INTERACT FORUM

Please login or register.

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

Author Topic: Sorting Artists by Number Plays  (Read 3860 times)

Don W

  • World Citizen
  • ***
  • Posts: 185
Sorting Artists by Number Plays
« on: August 12, 2013, 07:38:22 pm »

Hello All,

I have an Artist/Album view and have modified Artist so it is sorted by "Plays". I'm not getting the results I would expect and wonder if someone can explain how number of plays for an artist are calculated for the purpose of sorting.

Here's an example of what I'm seeing:

Artist A has 1 album with 10 songs and each song has been played 5 times.
Artist B has 4 albums. Album 1 has 12 songs all played at least 6 times, Album 2 has 14 songs all played at least twice, Album 3 has 13 songs each played 4 times and album 4 has 16 songs all played at least 5 times.
Artist C has 2 albums. Album 1 has 12 songs each played 5 times. Album 2 has 10 songs each played twice.

I would expect these artists to be ordered B -> C -> A but they are in fact ordered A -> B -> C in my display.

Why?

Thanks in advance.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Sorting Artists by Number Plays
« Reply #1 on: August 12, 2013, 08:06:18 pm »

Think: Averages.
Logged
The opinions I express represent my own folly.

Don W

  • World Citizen
  • ***
  • Posts: 185
Re: Sorting Artists by Number Plays
« Reply #2 on: August 12, 2013, 09:04:04 pm »

I see. Would it be possible to make a calculated field where the calculated value is the sum of the plays of all tracks where artist = artist, or album = album?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Sorting Artists by Number Plays
« Reply #3 on: August 12, 2013, 09:14:52 pm »

Yes, but you have to use a special technique.  Review this first:

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

Don W

  • World Citizen
  • ***
  • Posts: 185
Re: Sorting Artists by Number Plays
« Reply #4 on: August 13, 2013, 01:23:23 am »

Thank you. I spent some time studying that post but don't see exactly how to make that approach work for what I want to do. Mainly, it seems that it requires a Panes view to work. What I am ultimately trying to do is sort artist by the sum total plays of all tracks - in Theater View... My thought was to create a new custom field "Artist Plays" which calculates that value and then use that field to sort by in theater view. Will it work?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Sorting Artists by Number Plays
« Reply #5 on: August 13, 2013, 10:11:41 am »

The technique is not specific to panes, just easier to work through the examples there.  All views use a Set rules for file display to calculate the list of files to present.

Here are the steps.

1. Go to Options > Library & Folders > Manage Library Fields... and add a new field.  Call it NumPlaysCalc, set the type to Calculated, and add the expression:

  load(v_numplays_[album artist (auto)])

You will use this later.

2. Go to any Standard View to create a new sort preset.  Go to the Tab's Sort By, and select Custom, and Add, and select your new field under Z-A, and then when you see that field click Preset and save with a name something like NumPlaysCalc (z-a).  You willl use this later.

3. Go go Options > Theater View and click on Audio under Items to Show.  Click Set rules for file display and click the Import / Export button.  Replace what is there with the copy/pasted search query:

[Media Type]=[Audio] [=1save(0,v_numplays_[album artist (auto)])]=1 [=1ifelse(!isempty([Number Plays]),save(math([Number Plays] + load(v_numplays_[album artist (auto)])), v_numplays_[album artist (auto)]))]=1

and OK out of the two dialogs (remain in Options > Theater View).

4. Select Artist under Audio.  Click on Album Artist (auto) to the right and Edit.  Change the Settings > Sort to use your sort preset NumPlaysCalc (z-a) that you created above.  This will now sort artist by your calculated user field, which gets calculated when the files are being filtered as the view is built.  Now, and this part is optional, but will help you see that the view is working.  Change the type to Expression and paste in the following:

   Load(v_numplays_[album artist (auto)]) - [Album Artist (auto)]

and OK your way out.  This changes the category from the stock Album Artist (auto) field to use the same, but to prefix it with the number of plays for the artist.  Thus, you can see how many plays there are for the artist, and that the sort is working as you expect.  When you no longer need this, you can change this detail item back to the library field Album Artist (auto).  OK your way out.

The technique can be extended to Albums, or any field.
Logged
The opinions I express represent my own folly.

Don W

  • World Citizen
  • ***
  • Posts: 185
Re: Sorting Artists by Number Plays
« Reply #6 on: August 14, 2013, 04:47:12 pm »

Thank you. Works like a charm.
Logged

Don W

  • World Citizen
  • ***
  • Posts: 185
Re: Sorting Artists by Number Plays
« Reply #7 on: August 17, 2013, 01:42:33 pm »

Hi MrC,

I have a follow up question. The technique you describe works great for single value fields. But what about lists? For example, I am interested in grouping by [Artist] rather than the default [Album Artist (auto)]. Here is a simplified scenario. Suppose there are three albums, each album has 10 songs, each song has been played once and:

Album 1: Artist=Bob
Album 2: Artist=Bill
Album 3: Artist=Bob; Bill

When grouping by [Artist] the display correctly shows 2 albums under Bob and 2 albums under Bill. Album 3 is included in both lists. But the number of plays for each artist, when calculated with the method below, is 10, not the expected 20. It doesn't add the plays from tracks where Artist=Bob; Bill.

Is it possible to get the results I want?

The more general question, I think, is whether it is possible to define a special variable which is linked to a single value of a multi-value field? I tried defining the variable like this: v_numplays_[artist] - but it didn't work as I hoped it would.

Thanks in advance,
Don.

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Sorting Artists by Number Plays
« Reply #8 on: August 17, 2013, 01:59:34 pm »

If you want stats for the value present in Artist, use [Artist] instead of [Album Artist (auto)] in the expressions.  This will treat the entire value of [Artist] as a string, and thus differentiating "Bob", "Bill", and "Bill; Bob" as unique.
Logged
The opinions I express represent my own folly.

Don W

  • World Citizen
  • ***
  • Posts: 185
Re: Sorting Artists by Number Plays
« Reply #9 on: August 19, 2013, 03:30:38 pm »

That is exactly what is happening but it is not what I want... I want stats for "Bob" and stats for "Bill", but not for "Bill; Bob". In the display, under "Bill" both Album 1 and Album 3 show up. But the number of plays for Album 3 are not included in the total count of plays for "Bill". My question is how can I make it so they are?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Sorting Artists by Number Plays
« Reply #10 on: August 19, 2013, 03:36:46 pm »

Unfortunately, this can't generally be done.

There are no iteration constructs in the language, so the value "Bill; Bob" is a single entity.  While an expression can request one of the items, and do something with that item, it can't do something with N items.  You can simulate this, tediously, by assuming you have no more than N list items, and pre-constructing the expressions to deal with all N cases, specifically doing nothing when item M doesn't exist.

   If exists item 1 do something with item 1
   If exists item 2 do something with item 2
   ...
   If exists item N do something with item N
Logged
The opinions I express represent my own folly.

Don W

  • World Citizen
  • ***
  • Posts: 185
Re: Sorting Artists by Number Plays
« Reply #11 on: August 19, 2013, 05:17:10 pm »

I could do something like that. The question is how would I load a variable that is globally associated with Item X. For example, say Artist="A; B", then Item 2="B". I would need to load the variable that is globally associated with "A" and add the play count of the current song to it, then I would do the same with "B".
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Sorting Artists by Number Plays
« Reply #12 on: August 19, 2013, 05:31:44 pm »

Each artist is available as an item in the list.  They can be accessed as:

listitem([artist], 0)   <== artist #1
listitem([artist], 1)   <== artist #2
listitem([artist], 2)   <== artist #3
...

Then, to save some value into an artist-specific global variable:

save(some value, v_numplays_listitem([artist], 0))   <== artist #1
save(some value, v_numplays_listitem([artist], 1))   <== artist #2
save(some value, v_numplays_listitem([artist], 2))   <== artist #3
...

and to load / use them:

load(v_numplays_listitem([artist], 0))   <== artist #1
load(v_numplays_listitem([artist], 1))   <== artist #2
load(v_numplays_listitem([artist], 2))   <== artist #3
...
Logged
The opinions I express represent my own folly.

Don W

  • World Citizen
  • ***
  • Posts: 185
Re: Sorting Artists by Number Plays
« Reply #13 on: August 19, 2013, 11:22:15 pm »

Ok, almost there, but not quite. I can define variables for listitem([artist],0), listitem([artist],1), etc. and I can display the values in an artist view by modifying the thumbnail text like this: [Name] (load(v_numartistplays_[Name]) plays)

Since [Name] in that context is the name of the group, it actually works...

But I need to sort by these values. I want to sort by the expression: load(v_numartistplays_[Name]) where [Name] is the name of the group. Is this possible?

 
Logged

pcstockton

  • Citizen of the Universe
  • *****
  • Posts: 1261
Re: Sorting Artists by Number Plays
« Reply #14 on: August 20, 2013, 12:15:50 am »

cant wait... into this.
Logged
HTPC (ASRock Mini PC 252B: i5 2520M Sandy Bridge/HD3000 - 2.5 GHz - 8GB RAM - 256GB Intel SSD - Win7 Home) > MF V-Link 192 > Wireworld Ultraviolet > Naim DAC > Naim NAC 102/NAPSC/HiCap (PSU) > Naim NAP 180 Amp > Naim NACA-5 Speaker Cables > Naim Ariva

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Sorting Artists by Number Plays
« Reply #15 on: August 20, 2013, 12:42:04 am »

We might be getting into an area that is iffy as far as this working.  You need to create a sort Preset like step #2 above.  Use the expression you mention above to define the calculated user field, and then set your Sort value in for the category to that field.
Logged
The opinions I express represent my own folly.

pcstockton

  • Citizen of the Universe
  • *****
  • Posts: 1261
Re: Sorting Artists by Number Plays
« Reply #16 on: August 20, 2013, 01:26:17 am »

oh wait.... i scrobble [almost] everything to LastFM.  I can see stats there i believe.
Logged
HTPC (ASRock Mini PC 252B: i5 2520M Sandy Bridge/HD3000 - 2.5 GHz - 8GB RAM - 256GB Intel SSD - Win7 Home) > MF V-Link 192 > Wireworld Ultraviolet > Naim DAC > Naim NAC 102/NAPSC/HiCap (PSU) > Naim NAP 180 Amp > Naim NACA-5 Speaker Cables > Naim Ariva

Don W

  • World Citizen
  • ***
  • Posts: 185
Re: Sorting Artists by Number Plays
« Reply #17 on: August 20, 2013, 11:31:21 am »

Doesn't work. I think in this context [Name] is resolved as the value of the "name" field of the file, not the name of the group. I guess that there isn't any way, then, to get the name of the current grouping?

This could be a feature request: support for calculating group statistics when the group-by field (or expression) is a list, and optionally sorting the groups by the calculated values.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Sorting Artists by Number Plays
« Reply #18 on: August 20, 2013, 12:00:44 pm »

If you use 'Artist' as the value to create the global variables, use the same value to retrieve them, not Name.  [Name] is an alias for the current category.
Logged
The opinions I express represent my own folly.

Don W

  • World Citizen
  • ***
  • Posts: 185
Re: Sorting Artists by Number Plays
« Reply #19 on: August 20, 2013, 12:52:30 pm »

I used listitem([artist],0), listitem([artist],1), etc. to create the variables, just as we have been discussing. Retrieving them by "artist" doesn't work when artist has multiple values, because it treats the entire string as a single entity.

What I discovered by trial and error is that, when you define a variable using listitem, then the actual variable that gets created contains the value of that listitem. For example, say artist="a; b", and I define this variable: v_numartistplays_listitem([artist],1). The actual variable that is created is named v_numartistplays_b.

Now, you say [Name] is an alias for the current category. That is exactly what I was hoping, because it works when that truly is the case, which I verified by being able to display the num artist plays for each group by modifying the thumbnail text.

Specifically, taking the above example, there are two categories (or group names), "a" and "b", so it is possible to access the global variable v_numartistplays_a and/or v_numartistplays_b with the expression v_numartistplays_[Name] where [Name] is the name of the category or grouping. I verified this by experiment.

Remember, what I am ultimately trying to do is calculate the total number of plays for each unique artist and sort the artists by those values, being sure to consistently treat the "artist" field as a list, not a single value. Meaning that if a track has artist="a; b" then both "a" and "b" should have their total number plays incremented by the track's Number Plays. This makes sense after all, since the track will show up under both "a" and "b" in the display.

So far, we haven't found a way to do this.
Logged
Pages: [1]   Go Up