INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: statistics - examples of how to display  (Read 14714 times)

rjm

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 2699
statistics - examples of how to display
« on: January 31, 2013, 12:47:49 pm »

MrC generously offered to show us how we might display some library statistics.

I am interested in a simple example that we could then extrapolate and customize.

1) select a subset of files using an expression like "Media Sub Type is Music"
2) For the subset calculate # files, # albums, total duration, total size on disk
3) Display those results in a formatted row with headings
4) select a different subset of files and repeat 2-3

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #1 on: January 31, 2013, 03:14:11 pm »

Ok, here it is briefly.

This is a panes view that shows two media types: Audio and Video.  It shows the stats you wanted, each in its own pane.



Here is a selection of Media Type=Audio and one album selected.  The stats are updated as you can see:



The code to do this is not difficult, just difficult to read.  It requires two components: the rules for file display for the view, and pane entities themselves.

Rules for file display contains two segments: the first initializes the global variables we want to use; the second performs the increments.  This works because MC runs each listed rule on the entire current set of files.  So when doing this stuff, always think Stage 1: Initialize, Stage 2: Perform work.

Here are the rules split apart for easy reading, and also in the code block for easy copy/paste:

Code: [Select]
[=save(0,v_ntracks)save(0,v_nalbums)save(0,v_ntracks[album][album artist (auto)])save(0,v_tduration)save(0,v_tsize)1]=1 [=save(math(1+[v_ntracks]),v_ntracks)ifelse(isequal(load(v_ntracks[album][album artist (auto)]),0),save(math(1+[v_nalbums]),v_nalbums))save(math(1+load(v_ntracks[album][album artist (auto)])),v_ntracks[album][album artist (auto)])save(math([duration,0] + [v_tduration]),v_tduration)save(math([file size,0] + [v_tsize]),v_tsize)1]=1

Stage 1.  This just initializes each variable we'll use to 0.  Note that the v_ntracks[...][...] variable is a unique variable per album/album artist (auto) pairing.  This gives us tracks per album, and might need further refinement to uniquely define an album.

[=
   save(0,v_ntracks)
   save(0,v_nalbums)
   save(0,v_ntracks[album][album artist (auto)])
   save(0,v_tduration)
   save(0,v_tsize)
1]=1

Stage 2: This next stage does the incrementing.  It adds 1 to the number of tracks, adds 1 to the number of albums but only for the first track seen for the album, adds 1 to the number of tracks-per-album (which can be used elsewhere, but is not currently being used otherwise), and increments the total file duration and total file size by the file's duration and size respectively.

[=
  save(math(1+[v_ntracks]),v_ntracks)
  ifelse(isequal(load(v_ntracks[album][album artist (auto)]),0),
     save(math(1+[v_nalbums]),v_nalbums)
  )
  save(math(1+load(v_ntracks[album][album artist (auto)])), v_ntracks[album][album artist (auto)])
  save(math([duration,0] + [v_tduration]),v_tduration)
  save(math([file size,0] + [v_tsize]),v_tsize)
1]=1

Now, the size pane columns are configured as:

   [Media Type]
   [Album]
   [v_ntracks]
   [v_nalbums]
   FormatDuration([v_tduration]) : math([v_tduration] / 3600) hours
   FormatFileSize([v_tsize]) : [v_tsize] bytes

Note that there is a new feature being employed here.  Global variables can now be referenced as if they were fields once they have been defined with a Save() function.  So [v_ntracks] is just shorthand for load(v_ntracks).  If you don't have MC 18.0.126, replace these pseudo-field entities with the equivalent load() functions, both in the panes expressions and in the Rules for file display.
Logged
The opinions I express represent my own folly.

zxsix

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1753
Re: statistics - examples of how to display
« Reply #2 on: January 31, 2013, 03:21:23 pm »

1) Count of files in each audio genre.

2) What, if anything, is currently playing in each zone, especially remote LS clients.

3) I have several smartlists that I use for troubleshooting (ex.: one tells me if any files are missing a genre tag).   I'd like to display the count of files that are in each of these playlists.  If count=0, display "None".



How to format in the html page?
So let's say the count of files where media type=audio and genre=jazz is 4200
How do I tag that for display on the html start page?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #3 on: January 31, 2013, 03:34:59 pm »

1) Count of files in each audio genre.

This is easy with the format I've given above. You add the appropriate Stage 1 and Stage 2 pieces:

  - Stage 1: initialize a new global variable v_nfiles[genre]
  - Stage 2: increment v_nfiles[genre] by 1

2) What, if anything, is currently playing in each zone, especially remote LS clients.

Don't think this can be done.

3) I have several smartlists that I use for troubleshooting (ex.: one tells me if any files are missing a genre tag).   I'd like to display the count of files that are in each of these playlists.  If count=0, display "None".

The easiest way to something close to this might be to place them into a Helper playlist group, and include a column that is a Playlist group.  When you click on that column, if there are files, you'll see them listed.  Add a Playlist column to the file list, and you'll see which playlists they are listed in.

How to format in the html page?
So let's say the count of files where media type=audio and genre=jazz is 4200
How do I tag that for display on the html start page?

I have to leave something for somebody else!  :D
Logged
The opinions I express represent my own folly.

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: statistics - examples of how to display
« Reply #4 on: January 31, 2013, 04:02:25 pm »

I don't think people are saying this often enough: you are truly amazing MrC!
Logged

rjm

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 2699
Re: statistics - examples of how to display
« Reply #5 on: January 31, 2013, 05:38:06 pm »

Very impressive! Thanks kindly. I will enjoy playing with this new toy.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #6 on: January 31, 2013, 10:25:44 pm »

rjm had also asked for Imported this Month/Year stats (I assume this meant year/month to date), so let's add those.

Include the following Stage 1 file selection rule to initialize a couple of variables, the number of tracks imported to date for the month and year:

save(0,v_nimport_mo)save(0,v_nimport_yr)

Include the following Stage 2 file selection rule to increment those counters if a file's date imported value matches the year.month or year, respectively:

ifelse(Compare(formatdate([Date Imported,0],year.MM), =, formatdate(Now(),year.MM)),save(math(1+[v_nimport_mo]),v_nimport_mo))ifelse(Compare(formatdate([Date Imported,0],year), =, formatdate(Now(),year)),save(math(1+[v_nimport_yr]),v_nimport_yr))

And let's add a new column called Imported.  We'll put both MTD and YTD values in the same cell, so we'll save space and see how this works as an example.  Add a new expression column in the pane:

This month: [v_nimport_mo];
This year: [v_nimport_yr]&datatype=[list]

And voilą, I've imported 36 tracks this year or month to date.

Logged
The opinions I express represent my own folly.

rjm

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 2699
Re: statistics - examples of how to display
« Reply #7 on: January 31, 2013, 10:44:48 pm »

umm, sorry for stupid question, where do I put your code?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #8 on: January 31, 2013, 10:48:08 pm »

Set rules for file display:

[=save(0,v_ntracks)save(0,v_nalbums)save(0,v_ntracks[album][album artist (auto)])save(0,v_tduration)save(0,v_tsize)save(0,v_nimport_mo)save(0,v_nimport_yr)1]=1 [=save(math(1+[v_ntracks]),v_ntracks)ifelse(isequal(load(v_ntracks[album][album artist (auto)]),0),save(math(1+[v_nalbums]),v_nalbums))save(math(1+load(v_ntracks[album][album artist (auto)])),v_ntracks[album][album artist (auto)])save(math([duration,0] + [v_tduration]),v_tduration)save(math([file size,0] + [v_tsize]),v_tsize)ifelse(Compare(formatdate([Date Imported,0],year.MM), =, formatdate(Now(),year.MM)),save(math(1+[v_nimport_mo]),v_nimport_mo))ifelse(Compare(formatdate([Date Imported,0],year), =, formatdate(Now(),year)),save(math(1+[v_nimport_yr]),v_nimport_yr))1]=1

The other piece goes in a panes column.
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: statistics - examples of how to display
« Reply #9 on: February 01, 2013, 09:27:38 am »

This is amazing, great work, one question, is the date imported just meant to be for statistical purposes? On my end for imported this month under audio it says 1, but when I click on it, it doesn't filter to that subset, it still shows all files..
Logged

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: statistics - examples of how to display
« Reply #10 on: February 01, 2013, 09:49:14 am »

Something is not right. When I add the default collumn [Album], All Albums shows 2279 but your expression shows 3501 when I only have Audio selected. When I select All Media Types it shows 3686. For Image, it shows 196, for Video it shows 0. 3501+196 =/ 3686.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #11 on: February 01, 2013, 11:38:12 am »

This is amazing, great work, one question, is the date imported just meant to be for statistical purposes? On my end for imported this month under audio it says 1, but when I click on it, it doesn't filter to that subset, it still shows all files..

It is only statistical.  A value in a pane column represents all the files that yield that value.  Since every file produces the output listed there, the pane column becomes little more than a piece of information.  If we added other values or possible output, then it could be selective.
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #12 on: February 01, 2013, 12:22:47 pm »

Something is not right. When I add the default collumn [Album], All Albums shows 2279 but your expression shows 3501 when I only have Audio selected. When I select All Media Types it shows 3686. For Image, it shows 196, for Video it shows 0. 3501+196 =/ 3686.

This might be one of the cases where you need to tighten up the definition of an Album.  I used [album][album artist (auto)] as the basis for ensuring the accumulator counted only one track / music album.  But for other media types, this doesn't really make sense.

What I didn't show in the view rules above is that I restricted the view to only include items that included one of my reference ids (which means the media came from a CD rip, audio or video).  I excluded that distraction above, to simplify the concept.

If you want to include other media types, you'll probably want to a) change how the accumulators work, and b) change the Album column to be something that is meaningful for a given media type.  Or just ignore that field.

I find it is easiest to narrow these discrepancies by sorting the file list on the columns that are being used to discriminate and count.  Ask what happens if a utilized value is empty, or is identical across a media type.  Also, you can use Search to narrow results to a more manageable number, so you can spot discrepancies.
Logged
The opinions I express represent my own folly.

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: statistics - examples of how to display
« Reply #13 on: February 03, 2013, 01:23:45 pm »

Theoretically, it shouldn't be too hard for someone with html and javascript knowledge to create a statistics page.

It is possible to export the database to csv and parse it with javascript.

A very simple (and not working) example is showing below. This idea would require you to export your library every once in a while to a csv at a location where that javascript can read it.

Obviously that javascript needs a lot of work but it should be possible.

I'm no coder though I'm just the guy that comes up with all the ideas that give coders headaches ;D.

Code: [Select]
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="../../js/highcharts.js"></script>
    <script src="../../js/modules/exporting.js"></script>


    <script type="text/javascript">

    $(document).ready(function() {

    var time = [];
    var temp = [];

    $.get('forecast.csv', function(data) {
               var lines = data.split('\n');
               $.each(lines, function(lineNo, line) {
                var items = line.split(',');
                time.push(parseInt(items[0]));
                temp.push(parseInt(items[1]));
               });
        });

        var options = {
          chart: {
             renderTo: 'container',
              type: 'spline'
          },
          title: {
              text: 'Temperature Forecast'
          },
          xAxis: {
             title: {
                text: 'Hour'
             },
             categories: time
          },      
          yAxis: {
                 title: {
                    text: 'Temperature'
                 }
          },
          series: [{
                 data: temp
          }]
          };                      

    var chart = new Highcharts.Chart(options);

    });

    </script>
</head>

<body>

    <div id="container" style="width: 100%; height: 400px"></div>

</body>

And if you really feel adventureous you can incorporate something like this. Don't forget to click the bubbles ;D.

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #14 on: February 03, 2013, 01:58:40 pm »


A very simple (and not working) example is showing below. This idea would require you to export your library every once in a while to a csv at a location where that javascript can read it.


Why not just have the script query via MCWS the data it needs?  No need to export, and the data will always be fresh.

I might do one in perl of folks are interested in a proof of concept, but I won't bother doing it in Javascript (yuck).
Logged
The opinions I express represent my own folly.

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: statistics - examples of how to display
« Reply #15 on: February 03, 2013, 03:31:22 pm »

Why not just have the script query via MCWS the data it needs?  No need to export, and the data will always be fresh.

Because I didn't know that was possible  :P.

I might do one in perl of folks are interested in a proof of concept, but I won't bother doing it in Javascript (yuck).

I don't have a preference for javascript, its just the example I could find and figured it might trigger some interest.

Do you know Python?
Logged

Rubberduck0

  • Junior Woodchuck
  • **
  • Posts: 75
Re: statistics - examples of how to display
« Reply #16 on: February 04, 2013, 04:13:05 am »

Maybe this is not the right thread, but somehow I think the answer to my question is very near this topic...

I would like to have a view, which shows me only artists, where I do have at least n tracks (either per artist in total or, alternatively, per album, i.e. I do have at least one album with more than n tracks from that artist). For those artists I would then display the categories artist (of course), and then album (preferrably all albums, even if there is only one track or no album information at all).

I tried to use the standard field "number of tracks", but this seems to do nothing useful (i.e. I didn't get any result, whatever I tried). Then I thought the example given here at the beginning could help me out, but nope, it doesn't (because the number of tracks/albums/etc. is only calculated based on the tracks shown; but I would need to have the number of tracks for all artists as a list and then filter that for greater than n; or so I think).

Can anyone help me out here, or redirect me to the right location where to ask. Thanks in advance.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #17 on: February 04, 2013, 11:39:59 am »

This is a smartlist question.  Can you move it to a new thread, and someone will comment there?

Thank in advance.

Maybe this is not the right thread, but somehow I think the answer to my question is very near this topic...

I would like to have a view, which shows me only artists, where I do have at least n tracks (either per artist in total or, alternatively, per album, i.e. I do have at least one album with more than n tracks from that artist). For those artists I would then display the categories artist (of course), and then album (preferrably all albums, even if there is only one track or no album information at all).

I tried to use the standard field "number of tracks", but this seems to do nothing useful (i.e. I didn't get any result, whatever I tried). Then I thought the example given here at the beginning could help me out, but nope, it doesn't (because the number of tracks/albums/etc. is only calculated based on the tracks shown; but I would need to have the number of tracks for all artists as a list and then filter that for greater than n; or so I think).

Can anyone help me out here, or redirect me to the right location where to ask. Thanks in advance.
Logged
The opinions I express represent my own folly.

kurushi

  • Citizen of the Universe
  • *****
  • Posts: 683
Re: statistics - examples of how to display
« Reply #18 on: February 04, 2013, 01:04:45 pm »

Very good but it 'll be better to have it in a premade view without to read a ton of wiki... or maybe a type of "sharing view" with one click and install like the skins.
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: statistics - examples of how to display
« Reply #19 on: February 19, 2013, 11:34:36 pm »

This is cool and should be bumped on general principle.  If you didn't read it, do it now.  If not, shame on you.

Also, there's nothing wrong with Perl.  Don't take any guff.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

Marra

  • Regular Member
  • World Citizen
  • ***
  • Posts: 160
Re: statistics - examples of how to display
« Reply #20 on: June 30, 2013, 05:51:29 pm »

One for MrC.  (hope he finds this old thread)
I have implemented your code above for number of albums per artist.
The calcs in my instance are not what I was after. Let me explain.
Basically, I need to count on 1 every time the [album artist(auto)] and [album] change.
That is ignore the track numbers/disc numbers. Every track then has atleast one album for that artist
(complete or not).  Thanks
BTW this thread needs bumping for those that are not aware of theses capabilities.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #21 on: June 30, 2013, 06:17:42 pm »

Hi Marra,

I'm not sure I understand.  Can you explain, or show some examples to help me understand?
Logged
The opinions I express represent my own folly.

Marra

  • Regular Member
  • World Citizen
  • ***
  • Posts: 160
Re: statistics - examples of how to display
« Reply #22 on: June 30, 2013, 08:14:42 pm »

MrC
Thanks for your reply.
Sorry, it looks like I got the code from another thread you replied to.
This is the what I'm using
[=save(0,v_nalbums[album artist (auto)])1]=1 [=ifelse(Compare([track #].[disc #], <=, 1.1),save(math(1+load(v_nalbums[album artist (auto)])),v_nalbums[album artist (auto)]))1]=1
How do I go about ignoring the ifelse component to reflect change in [album artist(auto)] and [album] only - irrespective of track numbers.
Is this clearer?
For instance at the moment if I only have 1 track from an album, say track #5, the calc leaves it empty.  However, I would like it included in totals as I have set albums as complete or incomplete elsewhere.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #23 on: June 30, 2013, 08:28:52 pm »

Let's take this over to the original thread:

   http://yabb.jriver.com/interact/index.php?topic=78295.msg532393#msg532393
Logged
The opinions I express represent my own folly.

DJ_Hazelwood

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 294
Re: statistics - examples of how to display
« Reply #24 on: July 03, 2013, 11:49:06 am »

Hi,

I also have a statistics question, I hope this is the right place for it:

In my library I use the tag 'custom' to mark tracks with 'EXCLUDE', that means I will move them to another library when all the tagging is done. For all other tracks the 'custom'-tag is unassigned.
Now I would like to see if I have artists that have tracks marked with 'EXCLUDE' and also tracks that are not marked.
So the statistic should count EXCLUDE-tracks and unassigned-tracks and show the result per Artist.

Is this possible with MC-functions?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #25 on: July 03, 2013, 12:15:33 pm »

The easiest way to do this is while you are in this statistics view, use the Search box and enter:

   [Custom]=[EXCLUDE]

or

    -[Custom]=[EXCLUDE]

to show or hide EXCLUDE items, respectively.  The stats will update.
Logged
The opinions I express represent my own folly.

DJ_Hazelwood

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 294
Re: statistics - examples of how to display
« Reply #26 on: July 03, 2013, 12:47:54 pm »

Ok, but then I can't see the EXCLUDE/not EXCLUDE counters per artist within the same view, right?
The idea is to see artists that have entries in both of the views (EXCLUDE and not EXCLUDE).

Something like this:

Artist    EXCLUDE count   NOT EXCLUDE count
Artist1                    10                           15
Artist2                     5                             3
....
....
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #27 on: July 03, 2013, 05:16:22 pm »

To keep the values readable and connected to the artist, you'll want to either combine them into a single pane column, or add the include/exclude values into the file list as separate columns (or both methods is fine).

Add this to your Set rules for file display:

[=save(0,v_nExcl_[Album Artist (auto)])1]=1 [=save(0,v_nIncl_[Album Artist (auto)])1]=1 [=if(isequal([Custom],EXCLUDE), save(math(1 + load(v_nExcl_[Album Artist (auto)])),v_nExcl_[Album Artist (auto)]), save(math(1 + load(v_nIncl_[Album Artist (auto)])),v_nIncl_[Album Artist (auto)]))1]=1

Add this to a panes column, and label it something like Excl / Incl : Artist:

E: padnumber(load(v_nExcl_[Album Artist (auto)]), 4) / I: padnumber(load(v_nIncl_[Album Artist (auto)]), 4): [Album Artist (auto)]

We have to pad the numbers to force alignment.  Of course, you can reformat it anyway you want.

Also, I used Album Artist (auto) - you may want to replace those with Artist, depending upon your needs.
Logged
The opinions I express represent my own folly.

DJ_Hazelwood

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 294
Re: statistics - examples of how to display
« Reply #28 on: July 04, 2013, 01:16:10 am »

Wow, works great! Thank you so much, you saved me a lot of time  :)

One last question:
is it possible to set a rule so that I can filter Album Artists where v_nExcl <> 0 AND v_nIncl <> 0  ??
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: statistics - examples of how to display
« Reply #29 on: July 08, 2013, 12:06:31 pm »

One last question:
is it possible to set a rule so that I can filter Album Artists where v_nExcl <> 0 AND v_nIncl <> 0  ??

I didn't forget about this, but have run into a limitation of the trick we're using.  I can get you two panes columns that show the values of v_nExcl and v_nIncl, so that you can select those not-0.  A single column using an expression to combine the values unfortunately fails to work due to the limitation.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up