INTERACT FORUM

Please login or register.

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

Author Topic: Here's how to get Album Ratings in your views  (Read 4721 times)

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Here's how to get Album Ratings in your views
« on: September 05, 2019, 10:57:55 pm »

For many years now people have been asking how to display Album Ratings, which is something MC doesn't natively support.  There's been a lot of discussion about it, and many different attempts and solutions have been tried, but most of these centered on either creating a separate "Album Rating" field, or using global variables.

These approaches have drawbacks.  A separate "Album Rating" field is something you have to manually edit, which should be an needless step when you've already rated your individual tracks.  Global variables, while powerful, are too complicated for some people to implement, and there can be issues with using them in certain circumstances because of how they are evaluated.

There's also another, limited way.  If you set the list style of the top pane of a standard view to Details, it will then summarize rating and duration if you add those columns.  This does give you automatically calculated album rating and duration, but only in text, and this does not work in theater view at all.

So for those who are interested, I'd like to offer the method I've been using, which does not have any of those problems.  It's simple, automatic, and works in Theater View or Standard View.  It's also more flexible.  I haven't seen anything like it documented on the forums before, so if you've struggled with this before then this may be a new approach for you.  Some of the black magic involved I got from Mr. C, and some of it is my own.

Before the pics, a quick note... Some of what you will see deals with "Compositions". A lot of classical music consists of multiple tracks that taken together form a single piece of music, a Composition.  For example, Mozart's 1st Piano Concerto consists of 3 movements, each in a separate track, and you would listen to these three tracks together as a single Composition.  JRiver doesn't natively have a concept of a Composition in this way, so I created one, as I'll explain later.

To show you the flexibility of this method for displaying album ratings, I'll show you a classic music view that provides not only Album Ratings, but also album duration, along with Ratings and Durations for Compositions within the albums.



As you can see, it shows the automatically calculated rating for each album, plus the automatically calculated duration for the album. Rating is an average based on the ratings of the included tracks, and duration is calculated as the total of the durations of all the included tracks.

If you drill into an album, it shows you the Compositions on the album, along with rating and duration:



Finally here in the track view, you can see the 3 tracks that make up the Composition of Beethoven's Piano Concerto No. 1.



As you can see, this method will not only calculate this information for Albums, but also for this arbitrary grouping of "Composition" that I've created.  It's flexible, and can do this for whatever group of files you point it at.

So what exactly is this Composition construct?
[Composition] is a user-defined field I created, a "calculated data" expression defined as:
listitem([name],0,:)

This works in conjunction with your naming scheme for classical music.   I name my classical tracks such that the name of the composition comes first, separated from the track-specific info by a colon. So if you have the three tracks for Mozart's 1st Piano Concerto named as follows:

Concerto No.1 in F major, K.37: I. Allegro
Concerto No.1 in F major, K.37: II. Andante
Concerto No.1 in F major, K.37: III. Allegro

They will all automatically share the [Composition] value "Concerto No.1 in F major, K.37"


So let's get to how the views themselves are constructed.  I used Theater View for this example, but it can just as easily be done in Standard View.  Here's the view structure:



Now, here's how the Album and Composition levels are built:





The secret to getting these summarized ratings and durations is the little-known, seldom-mentioned "GroupSummary" function that is part of the expression language.  GroupSummary will intelligently summarize certain types of data, for a defined group of files.  Each item, or set of items, that you "group by" in a view is a target for GroupSummary.

Here in detail are the expressions.  Generally, they display the item (an album or composition), then the summary of the Duration of the tracks therein, and then they display a star rating equal to the numerical value of the summarized rating.  A little format control also has to happen due to the way the GroupSummary function outputs.

Album Expression:
Code: [Select]
[Album, 1]/
<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>


Composition Expression:
Code: [Select]
[Composition, 1]      <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>

You could just as easily use these expressions in Standard View.  For standard view, don't put the expression in the "expression to display" area of the view customization, instead just insert it as the Thumbnail Text expression.  This will give you the summarized info you want, but preserve the graphical view if that's what you're after.  Although there does seem to be an issue/bug that when GroupSummary is used in a thumbnail text expression, it only returns a truncated value, which prevents the half-star ratings from being visible. (I think JRiver should fix that.)  Update: This bug has now been fixed in 25.0.106

Even this year people were still asking the question of how to do this on the forums, and they weren't finding great answers, so I thought I'd put this up.

Hopefully it will help people, and you can adapt the technique to your needs.

-Will
Logged

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72548
  • Where did I put my teeth?
Re: Here's how to get Album Ratings in your views
« Reply #1 on: September 06, 2019, 07:14:06 am »

Thanks, wer.
Logged

rec head

  • Citizen of the Universe
  • *****
  • Posts: 1012
Re: Here's how to get Album Ratings in your views
« Reply #2 on: September 06, 2019, 08:09:57 am »

I wish I could try this but you would have to back up a couple steps for me. I don't even know how to get to the screens you show to start.

It seems like something that should be part of MC.
Logged

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 718
  • Hi
Re: Here's how to get Album Ratings in your views
« Reply #3 on: September 06, 2019, 10:42:43 am »

This is great stuff, I have a few questions though.

What does <font alpha="35"> do?  I've never seen the alpha element before.

Would you mind breaking down one of the expressions?  Explaining what each bit does a bit?  I am having a hard time wrapping my head around it, I tend to struggle with a bunch of nested expressions.  I have a feeling that this post will be linked to for years to come so I feel like this would be valuable information to have. It's great to be able to do something, it's even better to understand why it works.

Again, great stuff here, thank you.
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Here's how to get Album Ratings in your views
« Reply #4 on: September 06, 2019, 12:20:07 pm »

I wish I could try this but you would have to back up a couple steps for me. I don't even know how to get to the screens you show to start.

It seems like something that should be part of MC.

Rec Head, I assume by screens you mean the configuration dialogs, because the first three shots are just from browsing JRiver's Theater View mode.  Theater View is JRiver's 10-foot interface that can be used with a remote control for HTPCs.

If the configuration screens don't look familiar, I'm guessing you haven't done much view customization, as those are the screens you see every time you customize a view.  You can take a look at these two tutorials for a full description of all the screens you saw here:

Marko's excellent tutorial on customizing views
Glynor's article on customizing views for Theater View

Those tutorials give step by step info on how to customize views and how to get to and edit those screens.  This tutorial was just on how to accomplish a specific but widely desired task.  Enjoy!  -Will
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Here's how to get Album Ratings in your views
« Reply #5 on: September 06, 2019, 12:29:58 pm »

What does <font alpha="35"> do?  I've never seen the alpha element before.

Moe, alpha sets the transparency/blending percentage for the text.  In a lot of places in MC that display text, you can customize the way the text is displayed by using the HTML font tag.  I don't think the alpha attribute is honored in standard view, but it is in theater view.  So alpha="35" gives the text a good deal of transparency, and this has the effect of deemphasizing it or making it less prominent in the interface.  See here for more: https://wiki.jriver.com/index.php/Expression_Language#HTML_Font_Properties

Putting the font tag in there is optional.  I just liked the way it looked when the text was transparent, as it differentiated it from the actual name it was next to.

I'll post separately about details of the expression...
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2036
Re: Here's how to get Album Ratings in your views
« Reply #6 on: September 06, 2019, 03:18:24 pm »

Hopefully you don't mind wer but I'll try to explain the expression:
Following script is going to display two fields duration of grouped tracks and their averaged stars separated by character "•"

<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>

Let's cut that in pieces:
So first you make list of items to be shown which are separated by character •
ListBuild(1, / • ,

You give first list item to be shown (Duration) and remove text " total" from the end of the duration (6 characters). Otherwise it would display something like "40:06 total"
RemoveRight(GroupSummary(Duration),6),

Next item to be shown is ListItem type from which we will choose one item to be shown depending on average number stars of album
ListItem(;½;★;★½;★★;★★½;★★★;★★★½;★★★★;★★★★½;★★★★★,

So one of the above star items is going to be shown and this index (position) is chosen  with following code. First we check if there is avg text to be displayed and if yes we will remove that text " avg" (4 characters)
Math(If(IsEqual(GroupSummary(Rating), avg, 8 ), RemoveRight(GroupSummary(Rating),4),

Result of average stars is then multiplied by 2 to get "10 star" positon from above star list and that star field from that position is then displayed
GroupSummary(Rating)) * 2)))

Summary:
So if duration would be "50:34 total" the expression would trim it to 50:34 and put • as separator. For next it will choose one of the 10 star items so If average star value would be "3 avg" the " avg" will be removed and remaining value 3 will be multiplied by 2 so result is 6 and the position in ListItem is then position six which is  ★★★
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Here's how to get Album Ratings in your views
« Reply #7 on: September 06, 2019, 03:54:14 pm »

Thanks, lepa.  I was just sitting down to write something out, but you saved me the trouble!  ;D  -Will


Two additional things worth mentioning:

The GroupSummary function sometimes adds text to its answers (things like " average" or " total") and sometimes it does not, depending on the object it is summarizing, so you have to sanitize that when it occurs, or mathematical operations won't work.  The expression doesn't know the nature of the object, so you have to handle all contingencies. When I first wrote the function, I wasn't sure of all the things that might pop up.

A cleaner way to write it would be to just strip the " avg" text if it is there but leave the value alone if it's not, which the RemoveCharacters function does (so it could replace the conditional):
RemoveCharacters(GroupSummary(Rating), avg)

So the entire Album expression could be shortened to this:
Code: [Select]
[Album, 1]/
<font alpha="35">ListBuild(1, / • ,RemoveRight(GroupSummary(Duration),6), listitem(;½;★;★½;★★;★★½;★★★;★★★½;★★★★;★★★★½;★★★★★, math(RemoveCharacters(GroupSummary(Rating), avg) * 2)))<//font>

The reason for the multiplication by 2 is that GroupSummary will return a decimalized value, like 3.4, for an average.  Multiplying that by 2 and counting through the objects in the ListBuild is an easy way to arrive at the half-star values.  You could also do this by taking the int() and frac() portions of the GroupSummary value, but I tried that and it actually makes a longer expression overall because of the need to sanitize the GroupSummary output.

Again, as I said in the earlier post, when used in Thumbnail text, GroupSummary only returns a truncated value, but I think that's probably a bug.  Either that or someone thought it would be a good idea so it didn't need to be sanitized, but it inappropriately truncates the mantissa as well so you lose precision.
Logged

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 718
  • Hi
Re: Here's how to get Album Ratings in your views
« Reply #8 on: September 06, 2019, 05:14:44 pm »

Thank you both, that helps a lot.

By the way, I have a font with half stars, if anyone would rather have a half star than ½.  After writing that, I just realized we could do it with images now even easier.

Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Here's how to get Album Ratings in your views
« Reply #9 on: September 06, 2019, 05:29:22 pm »

Glad that helped...

I tried with actual half stars like you have, and also with outlined/empty stars.

To my eyes, the 1/2 character was just easier to read.  I found it too easy to mistake the others for a full star.  But it's all personal preference.

Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2036
Re: Here's how to get Album Ratings in your views
« Reply #10 on: September 07, 2019, 12:07:49 am »

Yeah, Will's ListItem usage is very clever and before images it was cleanest way to do it. Now with images support it can also be done like this which perhaps is more easier to read for some.
Code: [Select]
<img src="tooltip:rating-stars-Math(Round(RemoveCharacters(GroupSummary(Rating), avg)*2))">
for this you will need to have "rating-stars-" prefixed images (postfix 0 to 10) in your tooltip folder

Thanks Will for sharing this!
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Here's how to get Album Ratings in your views
« Reply #11 on: September 07, 2019, 12:51:26 am »

Yeah I've had this scheme in theater view for a while, and haven't felt any need to update it.  I haven't really messed around with the new inline image support yet, but there are a couple of problems with it for this implementation though, aren't there?  I don't think it supports transparency (unless you hard-code it into your PNG), which I wanted. And also that would limit it to the most recent MC releases though, and that isn't cool for all the people with older versions.  A text string is simple and universal, and supports transparency.

But the exact graphics for displaying the rating isn't what's important about what I was trying to describe; you can do any of half a dozen different things for that according to taste and they'd all work fine.

The important thing is an easy, reliable, and flexible way to actually compute the information (rating number, or whatever).  That's what people have been asking for for years... You should see some of the very clever but horrific looking things people have come up with using global variables to make it work.  There's never been anything straightforward.  This I think is simple enough regular people can actually adapt and modify it for their own use.

Anyway I'm glad you liked it.
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2036
Re: Here's how to get Album Ratings in your views
« Reply #12 on: September 07, 2019, 12:55:20 am »

I agree with all the points.

Just noticed that in Math() I will have to use Replace() comma with period as MC's Math() favours period centric world  :(
Logged

Absinthe

  • Guest
Re: Here's how to get Album Ratings in your views
« Reply #13 on: September 10, 2019, 02:24:55 pm »

I finally got around to implementing this in my Theater View, but one question.  If the GroupSummary function is providing an average rating, shouldn't it be averaging the ratings for all tracks in an album and not just the tracks rated?  For example, if I have an album that has two fantastic tracks (both rated 4 stars) and 2 dogs (rated no stars) GroupSummary will report an average of 4 stars.  I would think that the average rating would be more like .5  (two tracks @ 4 stars each = 8 / Total possible number of stars (4*4=16)?  At least this tells me the average rating of the entire album and not just the average rating of the two rated tracks?
Logged

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 718
  • Hi
Re: Here's how to get Album Ratings in your views
« Reply #14 on: September 10, 2019, 02:38:06 pm »

Absinthe, I would rate the dog songs a one and not leave them unrated. 
Logged

Absinthe

  • Guest
Re: Here's how to get Album Ratings in your views
« Reply #15 on: September 10, 2019, 02:56:41 pm »

That's a workaround, and I'm thinking the current calculation of average was simpler to code but its not an actual average of Album Ratings by Album but more an average by those tracks that are rated. 


Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2036
Re: Here's how to get Album Ratings in your views
« Reply #16 on: September 10, 2019, 02:59:15 pm »

All true but I would still rate "dogs" as 1. Otherwise you can't separate "dogs" from "not yet rated".

It's always hard to choose from shades of good but my system is something like this 1=bad, 2=doesn't annoy, 3 pretty good, 4 very good, 5 outstanding
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Here's how to get Album Ratings in your views
« Reply #17 on: September 10, 2019, 07:16:20 pm »

Absinthe, Moe and Iepa are giving you good advice.

Rating a song 1-star isn't really a work-around, it's using the rating system as intended.  The thing is, "zero stars" is by definition equal to "not rated".  MC even includes a built-in smartlist that provides that exact function.

You could distinguish a "rated zero star" track from "never rated" track by checking if the Date First Rated field is not empty, as it does not reset if you clear the rating.  But that doesn't change how GroupSummary works.

The GroupSummary function averages the ratings of rated songs only, so it ignores unrated songs.  Whether you like it or not, that's how it works.  :)

I would think that the average rating would be more like .5  (two tracks @ 4 stars each = 8 / Total possible number of stars (4*4=16)?
Anyway that's not remotely how you calculate an average.  Average is Total/Count.  So for your example, the mathematical average in your example is (4+4+0+0)/4=2, not 0.5

What you described, almost, is calculating a percentage: (Actual Total)/(Maximum Possible Total).  For your example that would be 8/20=.4 or 40%.  (Remember it's a 5-star system, 5x4=20. Not 4x4=16.)

Aside from wishing the ratings were calculated a different way, how are you liking the addition to your theater view?
Logged

Absinthe

  • Guest
Re: Here's how to get Album Ratings in your views
« Reply #18 on: September 10, 2019, 09:17:48 pm »

Aside from wishing the ratings were calculated a different way, how are you liking the addition to your theater view?

I think that once you understand the idiosyncrasies, it works fine.  Some of the skins could use some improvement to allow better placement of details but that is another task for another day
Logged

Absinthe

  • Guest
Re: Here's how to get Album Ratings in your views
« Reply #19 on: September 10, 2019, 09:21:22 pm »

All true but I would still rate "dogs" as 1. Otherwise you can't separate "dogs" from "not yet rated".

It's always hard to choose from shades of good but my system is something like this 1=bad, 2=doesn't annoy, 3 pretty good, 4 very good, 5 outstanding

I don't really agree, but as wer says, "this is how it works" so I will deal with it. 
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Here's how to get Album Ratings in your views
« Reply #20 on: September 27, 2019, 01:01:31 pm »

The bug affecting GroupCount and GroupSummary in standard view has now been fixed in version 25.0.106, so I have updated that in the original post for future readers.
Logged
Pages: [1]   Go Up