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 837 times)

zeltak

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 494

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: 2619
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: 2619
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
  • Galactic Citizen
  • ****
  • Posts: 494
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: 2619
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
  • Galactic Citizen
  • ****
  • Posts: 494
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: 2619
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
  • Galactic Citizen
  • ****
  • Posts: 494
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: 2033
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
  • Galactic Citizen
  • ****
  • Posts: 494
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: 2619
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
  • Galactic Citizen
  • ****
  • Posts: 494
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: 2619
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
  • Galactic Citizen
  • ****
  • Posts: 494
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: 2619
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: 2033
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: 2619
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
  • Galactic Citizen
  • ****
  • Posts: 494
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: 2619
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: 2619
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
  • Galactic Citizen
  • ****
  • Posts: 494
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: 2619
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
  • Galactic Citizen
  • ****
  • Posts: 494
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: 2619
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: 2619
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
Pages: [1]   Go Up