INTERACT FORUM

Please login or register.

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

Author Topic: revisiting album average rating-taking into account non rated tracks  (Read 1450 times)

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507

Hi all

I have searched (and found!) many good posts here on different ways (both simple and uber sophisticated) to calculate a user filed with the mean rating of an album.

yet I cant see anyway to do so while taking into account non rated tracks.

What I would love is to consider unrated tracks as `1` and take that into account when calculating average album ratings

anyone has done something like this before?

kind regards

Z
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #1 on: December 15, 2023, 06:53:51 pm »

Solution 1:

A single FieldQuery() almost gets you there, but unfortunately it ignores empty values. So the expression needs to be more complicated in order to generate the missing ratings:
Code: [Select]
save(ItemCount(/[Artist - Album /(Year/)/]), _count)/
save(FieldQuery(Artist - Album /(Year/), [Artist - Album (Year)], Rating, 1, 1), _ratings)/
save(1, _noRating)/
FormatNumber(Math((listmath([_ratings],2) + ([_count]-listcount([_ratings])) * [_noRating]) / [_count]),1)

This may be too slow if you have a large library. For most cases, it will work fine and much faster if you use 'Current View' Scope mode in FieldQuery() - just change this line:
Code: [Select]
save(FieldQuery(Artist - Album /(Year/), [Artist - Album (Year)], Rating, 1, 0), _ratings)/
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #2 on: December 15, 2023, 06:57:47 pm »

Solution 2 (simpler):

- create a calculated field called [RatingOr1] with expression: FirstNotEmpty([Rating,0],1)
- Use this expression for the album average:
Code: [Select]
FormatNumber(ListMath(FieldQuery(Artist - Album /(Year/), [Artist - Album (Year)], RatingOr1, 1, 1),3),1)

Again, try it with the Scope=0 to see if it works for you as it's faster:
Code: [Select]
FormatNumber(ListMath(FieldQuery(Artist - Album /(Year/), [Artist - Album (Year)], RatingOr1, 1, 0),3),1)
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #3 on: December 16, 2023, 12:37:13 pm »

wow thx so mych @zybex!!

I tried both methods and both with the `Scope=0` and with both as you said MC comes to a crawl :) (using latest OSX and MBP with m1pro chip)

I wonder is the slow crawl persistent or does MC calculates the mean rating as a one off thing and then stores this in file tags?

thx so much again

Z
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #4 on: December 16, 2023, 03:03:37 pm »

Yeah, Fieldquery can be slow :( One way to go about it is use/show it only on Views having few albums, like only when displaying all albums for a given artist. Even so, if your collection is huge then it will be slow regardless.

I think MC caches the results for 1 minute only, so it's not persistent.

If you have a windows machine available, you can use ZStats to pre-calculate the ratings - you can configure it to just run an expression on all files, and re-run it daily/nightly to update the numbers:
https://yabb.jriver.com/interact/index.php/topic,131845.0.html
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #5 on: October 22, 2024, 03:36:20 pm »

Hi again

@zybex coming back to this. as this was so slow and i could not implement this, can one somehow calculate and save the values in a file field? would this make things work reliably?

best

Z
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #6 on: October 23, 2024, 02:40:13 am »

You can do that with ZStats, as mentioned above.

- create the calculated [RatingOr1] field as mentioned above
- create a normal field called eg. [AlbumRating] to hold the result
- enter this code into the [RunAfter] section of ZStats.ini:

Code: [Select]
setfield(AlbumRating, FormatNumber(ListMath(FieldQuery(Artist - Album /(Year/), [Artist - Album (Year)], RatingOr1, 1, 1),3),1))

Then run ZStats once to calculate the field once for all files. You can re-run it periodically to recalculate - maybe create a Scheduled Task to run it every night or once a week/month, depending on your needs.

Other settings for ZStats.ini (also set your MCWS user/pass there):
Code: [Select]
MCFilter=[Media Type]=[Audio]           # filter to limit processing to a given set of files
UpdateStats=0                           # 1 to update stats as defined in [Stats] sections, 0 to disable
UpdatePlaylists=0                       # 1 to enable playlist processing, 0 to disable
RunExpressions=1                        # 1 to execute [RunBefore] and [RunAfter] expression, 0 to disable
CreateFields=0
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #7 on: October 23, 2024, 07:00:43 am »

thx so much

sadly i dont have access to a windows machine thesedays (when i wrote the post i was using jriver 31 on a windows mahcine)

so i understand there is no internal way to do so? maybe ill spin a VM...

thx again

Z
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2046
Re: revisiting album average rating-taking into account non rated tracks
« Reply #8 on: October 23, 2024, 09:25:07 am »

You can also use global variables which are much snappier than fieldqueries. There is a really old discussion about that somewhere here in the forum
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #9 on: October 23, 2024, 09:44:00 am »

thx!

i did a search for "global variables album rating" but got this "Your search query didn't return any matches"

any chance you remember the thread topic?

thx so much

Z
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #10 on: October 23, 2024, 10:15:00 am »

I've just compiled ZStats for Linux and OSX. Can you please give it a try, even just to confirm if it runs?
https://github.com/zybexXL/MCStats/releases/tag/v1.2.0

This requires Net8 Runtime to be installed. Let me know if you need an ARM64 version.
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #11 on: October 23, 2024, 10:33:57 am »

wow Zybex thats amazing!!!

for sure will be happy to beta test and report back. yes im on a M1 max mbp, so i guess i need an ARM64 version?

best and thx so much

Z
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #12 on: October 23, 2024, 10:46:15 am »

OK, I've now added the ARM binaries.
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #13 on: October 23, 2024, 11:16:14 am »

thx so much!

so installed Net8, downloaded the binary (ZStats-osx-arm64) and tried to run it both via the GUI and the command line, but i dont think its running (or create the ini file)

ie:

zeltak@Itais-MBP:~/bin/ > ./ZStats-osx-arm64

does nothing

happy to further help debug! let me know what i should try

Z
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #14 on: October 23, 2024, 11:21:18 am »

try "dotnet ./ZStats-osx-arm64"
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2046
Re: revisiting album average rating-taking into account non rated tracks
« Reply #15 on: October 23, 2024, 11:28:39 am »

variables live-solutions here.... It might be overwhelming at start  ;D
https://yabb.jriver.com/interact/index.php/topic,72049.0.html
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #16 on: October 23, 2024, 11:29:35 am »

Also try running these 2 commands to sign the executable:

Code: [Select]
chmod +x ./ZStats-osx-arm64
codesign --force --deep -s - ./ZStats-osx-arm64

Not sure if "codesign" is available by default on MacOS.
Source: https://github.com/dotnet/runtime/issues/79267#issuecomment-1342976630
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #17 on: October 23, 2024, 11:47:46 am »

fantastic

i made it executable and signed it and it works!! this is so freaking cool, you just made my week with Zstats available on the mac :)

ok so im trying to follow your guide to get the album ratings as instructed using Zstats.

i configured the ini file and added my user/pass and the config

Code: [Select]
UpdateStats=0                           # 1 to update stats as defined in [Stats] sections, 0 to disable
UpdatePlaylists=1                       # 1 to enable playlist processing, 0 to disable
RunExpressions=1                        # 1 to execute [RunBefore] and [RunAfter] expression, 0 to disable
CreateFields=1                          # 1 to create missing output fields, 0 to disable (allow only update)

[RunAfter]
#setField(Stats Updated, formatdate(now(),%c))
setfield(AlbumRating, FormatNumber(ListMath(FieldQuery(Artist - Album /(Year/), [Artist - Album (Year)], RatingOr1, 1, 1),3),1))



also created 2 new fields in the MC library

The RatingOr1

https://share.cleanshot.com/2PHfrD89

and the AlbumRating field

https://share.cleanshot.com/rM4sR5ld

now i re-ran Zstats which seemed to run but nothing was written to the tags?

Code: [Select]
zeltak@Itais-MBP:~/bin/ > ./ZStats-osx-arm64
ZStats v1.2.0 for JRiver MediaCenter, by Zybex

Reading config file: zstats.ini
Connecting to http://127.0.0.1:52199/MCWS/v1/
Connected to JRiver Media Center 32.0.58 on Itai’s Macbook Pro
Reading file list
  33511 files read
Checking fields
  history field [Play History] does not exist

Finished in 00:00:00

im sure i missed a step :)

thx so much again

Z



Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #18 on: October 23, 2024, 11:51:20 am »

It's complaining that [Play History] field does not exist because you didn't disable the UpdatePlaylists setting.
Change it on the .ini file, as you only want to execute the expression:

Code: [Select]
UpdateStats=0                           # 1 to update stats as defined in [Stats] sections, 0 to disable
UpdatePlaylists=0                       # 1 to enable playlist processing, 0 to disable
RunExpressions=1                        # 1 to execute [RunBefore] and [RunAfter] expression, 0 to disable
CreateFields=0                          # 1 to create missing output fields, 0 to disable (allow only update)
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #19 on: October 23, 2024, 11:59:29 am »

Maybe you can make it run 10x faster ... since all files on the same Album will have the same AlbumRating, you can try this to process each album just once:

- change the [AlbumRating] to a relational field with "store one value for each Album"
- change the MCFilter setting in ZStats.ini to only process Track #1 of each album:
   MCFilter=[Track #]=1
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #20 on: October 23, 2024, 12:19:15 pm »

thx again!

changed the [AlbumRating] to a relational filed and edited the MCFilter=[Track #]=1

i re-ran Zstat, it ran for 3 seconds and it seems to indicate it only processed 4 files?

Code: [Select]

zeltak@Itais-MBP:~/bin/ > ./ZStats-osx-arm64
ZStats v1.2.0 for JRiver MediaCenter, by Zybex

Reading config file: zstats.ini
Connecting to http://127.0.0.1:52199/MCWS/v1/
Connected to JRiver Media Center 32.0.58 on Itai’s Macbook Pro
Reading file list
  4 files read
Executing [RunAfter] expression
  4 files processed, 0 errors

Finished in 00:00:00
zeltak@Itais-MBP:~/bin/ >


any thoughts?

thx so much again

Z

Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #21 on: October 23, 2024, 12:32:42 pm »

If you type "[Track #]=1" into MC's filter/search box, does it show more than 4 files?

Maybe it's the wrong filter for your use case. Just try with the previous filter to process all 33500 files. You should be able to see the changes in MC as it runs and interrupt at any time.
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #22 on: October 23, 2024, 01:36:25 pm »

Hi

pasting [Track #]=1 into the search box shows indeed all files (not just 4, but 2883 files) in the library

removing the filter indeed makes it go through all files :)

Code: [Select]
zeltak@Itais-MBP:~/bin/ > ./ZStats-osx-arm64
ZStats v1.2.0 for JRiver MediaCenter, by Zybex

Reading config file: zstats.ini
Connecting to http://127.0.0.1:52199/MCWS/v1/
Connected to JRiver Media Center 32.0.58 on Itai’s Macbook Pro
Reading file list
  33511 files read
Executing [RunAfter] expression
  file 1162 of 33511



yet i the actual calculated rating are all weird. how does zstat calculate these? ie an album with 13 tracks where only 2 tracks are rated (4 and 3 starts) gets a 2.7 rating :D

im general can the script assign rating 1 to non rated tracks? does that make any sense ? :)

thx for all your help, zstats is awesome and cant wait to continue exploring it :)

Z
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #23 on: October 23, 2024, 01:47:09 pm »

Weird that the filter only returns 4 files for ZStats, but 2883 in MC

Regarding the AlbumRating calculation, maybe you should do some tests with one album in MC to fine tune the expression before using it in ZStats.
Filter a View so that a single Album is showing and add an Expression Column with the current expression:
FormatNumber(ListMath(FieldQuery(Artist - Album /(Year/), [Artist - Album (Year)], RatingOr1, 1, 1),3),1)

See what you get when you change the Ratings on the tracks. You can also add the [RatingOr1] field to the view.
ZStats is just applying that expression... it should assign rating=1 to unrated files, so on that 13-track album it should result in:
(4+3+1+1+1+1+1+1+1+1+1+1+1)/13 = 1.4

2.7 is what you get with (4+3+1)/3 ... perhaps your tagging isn't fully correct and MC is only assigning 3 tracks to that album?

The expression assumes that an Album is composed of files that share the same value for [Artist - Album (Year)]. May add that field as well to the view just to confirm.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #24 on: October 23, 2024, 02:33:33 pm »

Found the issue with [Track #] ... the # symbol was causing the rest of the line to be ignored as ZStats uses it to denote comments  ::)
Published v1.2.1 with a fix, you can now escape the # symbol like this:

  MCFilter=[Track /#]=1      # this is still a comment

Updated binaries: https://github.com/zybexXL/MCStats/releases

Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #25 on: January 23, 2025, 06:12:42 am »

hi again @zybex

hope all is well :)

i changed my rating strategy today and now i dont have non rated tracks. so a non rated song by default is `2` now in my collection

i currently run Zstats weekly to save inside tags my albumrating and have the code you gave me:

Code: [Select]
setfield(AlbumRating, FormatNumber(ListMath(FieldQuery(Artist - Album /(Year/), [Artist - Album (Year)], RatingOr1, 1, 1),3),1))

when i run this now i get all `0` in my AlbumRating variable. any chance you can guide me on how to get Zstat to just calculate the mean of all rated track per album? oi assume the RatingOr1 variable we created is the culprit now?

thx so much

Z
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #26 on: January 23, 2025, 07:35:38 am »

The expression should still work, assuming the [RatingOr1] field still exists. Can you add it to a View and check if it returns '2' for the new entries?
If all tracks now always have a rating, you can just use "Rating" instead of "RatingOr1" on that expression.
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #27 on: January 23, 2025, 08:13:32 am »

thx so much again @zybex

yeah that seems or work well yet for ~ 20% of the albums they still come up as `0`, i double-checked and they all seem to have proper rating..how does one go and debug this? (is there a log for zstats to see whats going on?)

also, it seems its rounding up to 0.5 the album ratings, can we define more accurate ratings ie 3.7?

thx so much

Z
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #28 on: January 23, 2025, 08:23:29 am »

It shouldn't be rounding.
Can you add these 3 expression columns (plus AlbumRating) to a Details view and share a screenshot for a couple of albums that are wrongly calculated?

column 1: [rating,0]
column 2: FieldQuery(Artist - Album /(Year/), [Artist - Album (Year)], Rating, 1, 1)
column 3: FormatNumber(ListMath(FieldQuery(Artist - Album /(Year/), [Artist - Album (Year)], Rating, 1, 1),3),1)
column 4: AlbumRating
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #29 on: January 23, 2025, 08:36:20 am »

thx

it seems like option 2: column 2: FieldQuery(Artist - Album /(Year/), [Artist - Album (Year)], Rating, 1, 1)
freezes MC..
other colums work well
should i filter before hand or do something else to prevent the freeze?
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #30 on: January 23, 2025, 08:37:37 am »

Yes, do that on a view or playlist that has only a few albums.
That's why you need to use ZStats for the whole collection :)
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #31 on: January 23, 2025, 08:52:35 am »

thx!

here is a screesnhot

Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #32 on: January 23, 2025, 09:13:03 am »

That's almost unreadable, please post an unresized image.
Also... please give names to the expressions so that we know what we're looking at. Please add the [Artist - Album (Year)] and [Track #], just to know where an album starts/ends.

The screenshot seems to indicate that those albums only have 2 or 3 tracks per album. Is that right?
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #33 on: January 23, 2025, 11:51:57 am »

so sorry @zybex about the image quality, here it is again in decent (hopefully) quality and with then column info with the new columns

most of the albums with `0` are actually complete it seems

thx again

Z





 
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #34 on: January 23, 2025, 01:06:36 pm »

OK, the problem is that FieldQuery() doesn't return a list with ALL rating values, but instead it returns only the UNIQUE ratings without repeated values. So for your Black Sabbath album, instead of averaging "3;3;3;2;2;2;2;3;2;2" it's just averaging "3;2" which is 2.5.

This is a known issue:
https://yabb.jriver.com/interact/index.php/topic,139850.msg969805.html#msg969805

The workaround is to use GroupSummaryQuery() instead - this one calculates the average but requires ALL tracks to have a valid rating value - good that you already took care of that :)
You can test by adding this expression column to that view:
GroupSummaryQuery(Artist - Album /(Year/), Rating, 1)

And your ZStats expression becomes simply:
setfield(AlbumRating, GroupSummaryQuery(Artist - Album /(Year/), Rating, 1))
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #35 on: January 23, 2025, 05:09:32 pm »

wow!!! so ..freaking awesome :)

you are a rock star @zybex :)

a few smalish related questions (see results screenshot below)

1. I assume i can define the round up precision in zstat to be 0.1 and not 0.001 as is currently (ie round to 1 decimal?)
2. When you run zstat it seems to fo over all 40k tracks. is that normal or should it only go over modified tracks?
3. this may be out of the scope of this thread :) but i saw you can create a list and converst the score to stars for presneting, something like this
Code: [Select]
<font alpha="35">ListBuild(1, / • ,RemoveRight(GroupSummary(Duration),6), listitem(;½;★;★½;★★;★★½;★★★;★★★½;★★★★;★★★★½;★★★★★, math(If(IsEqual(GroupSummary(Rating), avg, 8), RemoveRight(GroupSummary(Rating),4), GroupSummary(Rating)) * 2)))<//font>


would this work with the albumrating generated from Zstat?

thx so much again!! its so much fun to play arounbd with Zstat

PS do you think the jriver folk will ever include these calculation nativly?

Z



Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2777
Re: revisiting album average rating-taking into account non rated tracks
« Reply #36 on: January 25, 2025, 02:35:13 pm »

1. assume i can define the round up precision in zstat to be 0.1 and not 0.001 as is currently (ie round to 1 decimal?)
FormatNumber(GroupSummaryQuery(Artist - Album /(Year/), Rating, 1), 1)

Quote
2. When you run zstat it seems to go over all 40k tracks. is that normal or should it only go over modified tracks?
It's normal, but you can also modify the expression so that it calculates only for recently modified tracks. This calculates only for files modified in the last 7 days:
if(compare(Math(int(now()-[Date Modified,0])),<,7),
  setfield(AlbumRating, FormatNumber(GroupSummaryQuery(Artist - Album /(Year/), Rating, 1), 1))
,)


Quote
3. this may be out of the scope of this thread :) but i saw you can create a list and converts the score to stars for presenting, (...)
would this work with the albumrating generated from Zstat?
You can just change the Edit Type of the AlbumRating field to 'five stars' in the field definition. Then it behaves like the regular Rating field.
Logged

zeltak

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 507
Re: revisiting album average rating-taking into account non rated tracks
« Reply #37 on: January 30, 2025, 07:34:21 pm »

perfect thx so much!! you rock as always :)
Logged
Pages: [1]   Go Up