INTERACT FORUM

More => Old Versions => Media Center 17 => Topic started by: mark_h on May 09, 2012, 01:56:54 am

Title: HOWTO: Generate album ratings using variables (+ track count)
Post by: mark_h on May 09, 2012, 01:56:54 am
Global variables were added to MC a couple of builds back, which has opened up a new world of functionality within MC.

Here is my method for generating album ratings using variables.

Create a smartlist and copy this string into the import/export dialogue:

[Media Type]=[Audio] [=save(0,v_tracks[album artist (auto)][album])1]=1 [=save(math(1+load(v_tracks[album artist (auto)][album])),v_tracks[album artist (auto)][album])1]=1 [=save(0,v_albumratingsum[album artist (auto)][album])1]=1 [=if(compare([rating],=,0),save(-1,v_albumratingsum[album artist (auto)][album]),)1]=1 [=if(compare(load(v_albumratingsum[album artist (auto)][album]),>,-1),save(math([rating]+load(v_albumratingsum[album artist (auto)][album])),v_albumratingsum[album artist (auto)][album]),)1]=1 ~sort=[Album Artist (auto)],[Album],[Track #],[Media Type],[Disc #],[Name]

Add an expression column 'Album Rating'

if(compare(load(v_albumratingsum[album artist (auto)][album]),>,0),formatnumber(math( load(v_albumratingsum[album artist (auto)][album]) / load(v_tracks[album artist (auto)][album]) ),2),0)

Notes:

v_albumratingsum[album artist (auto)][album] is the variable that holds the album average, or -1 if tracks remain unvoted for.
v_tracks[album artist (auto)][album] contains the number of tracks in the album

The expression column could be moved into a user field, but by leaving the actual calculations in a smartlist you can refresh the ratings at any time, eg after you've made rating changes.  Views that want to display them or smartlists that want to use them can call the generating smartlist to ensure the ratings are correct and ready for use.

Enjoy!

Mark

Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: f.ammollo on May 29, 2012, 03:24:52 pm
Global variables were added to MC a couple of builds back, which has opened up a new world of functionality within MC.

Here is my method for generating album ratings using variables.

Hello,

I was really interesting in trying out what you suggested in this post, and I managed to make it work exactly how you explained it, but only for the part about the smart list and the new expression column.

What I don't really understand is what you exactly mean here:

Views that want to display them or smartlists that want to use them can call the generating smartlist to ensure the ratings are correct and ready for use.

Could you please explain what you mean with a practical example?

What I would like to achieve would be, for example, to have a thumbnail list showing the albums sorted by the "album rating" expression column, but it seems to me that I cannot reference it from a view because it is not a library field. Am I correct?

Thank you very much in advance.

Best regards,
Fabrizio
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: mark_h on May 30, 2012, 01:53:15 am
What I would like to achieve would be, for example, to have a thumbnail list showing the albums sorted by the "album rating" expression column, but it seems to me that I cannot reference it from a view because it is not a library field. Am I correct?

You do not need to use library fields for this to work.

What I was trying to describe above is that you create one smartlist that creates the variables and that any views or smartlists  that want to use variables would call this smartlist as part of their rules to ensure that the variables are created.

So for instance, in my system I have a smartlist called:

Var: Album Ratings

that calculates the ratings as per my example above.

Then in a view that wished to use album ratings I would use this smartlist as part of the view rules, eg:

Playlists is any Var: Album Ratings
<rest of the rules>

This ensures that the ratings are created and can be used by the view.

In your view you could then create the expression column and reference the variables directly...

Hope that helps.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: justsomeguy on May 30, 2012, 02:16:23 am
Is there a downside to doing this entirely with a view?
I created a new view called Album Ratings, set the rules for the view to your first expression. I then created a new library field called Rating Albums set it to calculated data and used your second expression for that. I can then use that field in the new view or as a pane category. It seems to work fine.

I did make a small modification to your expression so that tracks in an album with no rating get calculated as 3 stars instead of forcing the album rating to zero. I have a lot of my tracks rated but a huge amount of full albums have some several tracks with no rating. I know this won't give me a perfect representation of the albums rating but it works for me and as I rate more it will work itself out.

Thanks for sharing this.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: mark_h on May 30, 2012, 02:19:57 am
The only thing to be careful of with library fields is that the album rating data isn't refreshed... so if you change track ratings they won't update the album ratings.  To do this you should always call the smartlist as it forces the recalculations...
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: justsomeguy on May 30, 2012, 02:28:18 am
I thought that at first too but it seems to be updating. In my view if I change a rating it pauses for a second or two then the album rating updates. View seems to be updating on its own.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: mark_h on May 30, 2012, 02:31:33 am
The rules for the view force the recalculation...

If you move the rules into a smartlist you have to ensure the smartlist is called to get the refresh.

Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on October 29, 2012, 10:39:54 am
Hey Mark_h

tried to pm you about this but I don't know if it went through as I don't have anything in my outbox

I was wondering if you could tell me if this is possible?

I have many home videos where the descriptions "Tags" are stored in the name field. There are only a handful of descriptive tags. I also have a tags field that I was going to populate with the descriptive tags but is proving to be very time consuming.

My idea was to use variables to pull descriptions from the tags field from the few files that are tagged with them, then compare each of the description variables to the name tag of all home videos for equality and if there is a matches it would output the description tags to a pane.

If this would work I could then set the description in the tag field for one file but the pane would see all files that have that description in the name, thus saving me a lot of time tagging each file and also making it easier to add new descriptive tags. I wouldn't be worried about it slowing down my system because I would use it as a tool for adding tags to files and also adding new descriptions, so it would only be used when needed.

If I have to use the album artist and album field to do this it would be no problem, all videos could be part of the same album artist and album. From looking at your example being able to calculate the album rating using variables across all files in an album makes me believe that my idea is possible as long as they belong to the same album. I don't know that much about the global variables so I am unsure whether or not this is a wild goose chase.

Hope you get what I'm trying to convey and hope it is possible


Thanks
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on October 29, 2012, 12:08:16 pm
I was wondering if you could tell me if this is possible?

I have many home videos where the descriptions "Tags" are stored in the name field. There are only a handful of descriptive tags. I also have a tags field that I was going to populate with the descriptive tags but is proving to be very time consuming.

My idea was to use variables to pull descriptions from the tags field from the few files that are tagged with them, then compare each of the description variables to the name tag of all home videos for equality and if there is a matches it would output the description tags to a pane.

If this would work I could then set the description in the tag field for one file but the pane would see all files that have that description in the name, thus saving me a lot of time tagging each file and also making it easier to add new descriptive tags. I wouldn't be worried about it slowing down my system because I would use it as a tool for adding tags to files and also adding new descriptions, so it would only be used when needed.

Hi brian0001,

You don't need variables to pull components from a the values in any field, and use those to populate a pane.

It sounds like what you want to do is pull a bunch of values from Names, populate a pane, and then be able to select an item in that pane 1, and have another pane 2 populate its contents based upon what is selected in pane 1.  Eg. you select Foo in pane 1, and pane 2 populates all items where Name contains Foo.

An expression column can compare a field against a value and output the resulting matches (e.g. [Name] contains "Foo").  And it can even obtain that value from a global variable (e.g. [Name] contains evaluation of Load(var)).   BUT, there is no way to set the global variable to some value Bar which is the selection you made in pane 1.  In otherwords, there is no "event" that occurs at selection time in a pane to trigger the storing of your selection into the global variable, nor is there a way to even know what that selection is (e.g. no GetSelectionValue() function).

If you can give concrete examples of Names and descriptive tags, and your desired work flow, maybe there is some solution that could be suggested.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on October 29, 2012, 03:26:07 pm
Hi MrC
From my understanding of variables we can now compare files against each another, as long as they have something in common i.e. the album artist or album tag. - Is this true? I may have read it wrong but I don't see any other way to generate album ratings using variables.

The easiest way I can explain is just talking in the sense of one descriptive tag.
say I have lots of different videos for festivals

i.e
Festival 1 (Fire Show).avi
Festival 2 (Fire Show).avi
Festival 3 (Fire Show).avi and so on

Say that festival 1 (fire show).avi has "Fire Show" tagged in my [Tags] field but none of the other videos have fire show in the [Tags] field.

What I essentially want to do is somehow pull "Fire Show" from the tags field and put it into a variable, then use that variable to check against the [Name] field for all of the files and if "Fire Show" is there, make all those files appear under "Fire Show" in the pane, and repeat the process for whichever different tags exist within the [Tags] field of any of the files.

If all the files need the same data in a tag such as album artist or album to make the comparisons possible, I'd be willing just give all the videos the same entry to make it possible.

The logic behind me wanting this is, I could easily add a new tag in the [Tags] field for any one file. The tag would then appear in the pane and show all files that have that in their name even though the majority of these files don't have any entries in the [Tags] field.

I could make a search list to achieve this but this way entries in the pane would appear automatically based on the few files that have data in the [Tags] field. It would also be quick and easy to add a new tag.

Edit

I think the pane would essentially compare the variable to the name tag to achieve this

e.g.
If Isequal
             [var_tag] to [name] output [Name]
 
                       
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on October 29, 2012, 04:22:55 pm
I don't believe what you're asking can work.

Global vars didn't add the ability to compare files.  Rather, they added the ability to store a value and load that value.  With some cleverness, you can a) pre-load a set of arbitrary global variables when the view's contents are determined (i.e. the file list match rules), and b) use the values from these variables in an expression (pane, column, or when manually tagging) or view header.

I think some time ago. I described how MC populates a view's panes and file list.  I think you might still of the mindset that when you click in a pane, MC can perform a bunch of expression evaluations based on that click.   It doesn't.

Instead, MC:

 - runs the rules from the Rule for file display to determine the subset of files to preset in a view
 - evaluates each pane or category to determine the list of possible values to present as the pane or category list.
 - presents the list of files

Now, each time you select something in a pane column, or a category, all MC is doing is narrowing the existing results by performing a SELECT operation on its database using the value you clicked on as an additional narrowing filter (eg. Name=foo).  So what might have been a:

   SELECT [media type] = Audio

becomes

   SELECT [media type] = Audio AND [Name] = Foo

It by no means performs arbitrary actions on each item selection.  And by no means does MC have the ability when you make selections to thereby modify a tag's value.

To accomplish what you're after, you can show a list of Names and Tags, and use in combination with the Search box, selections to discover where there is a mismatch.

If the number of your descriptions is small, you can build an expression to test that each description is present in Tags, and if not, indicate so.  But once the number grows even moderately large, there is currently no practical solution.

Also, keep in mind - there is no iteration capability.  Meaning, there's no general way to iterate over an arbitrary list of values, and do something with those values (e.g. compare against a field, summation, etc.)

Hope this helps.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on October 29, 2012, 04:43:55 pm
Thanks MrC does help.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on November 09, 2012, 01:30:51 pm
Quote
if(compare(load(v_albumratingsum[album artist (auto)][album]),>,0),formatnumber(math( load(v_albumratingsum[album artist (auto)][album]) / load(v_tracks[album artist (auto)][album]) ),2),0)

Is there anyway to use Mid and possibly Math to make the output of the expression above behave similarly to the one below?
Mid(★★★★★, 0, [!A.Rating])If(IsEqual(Right([!A.Rating], 2), .5), ☆, )

Right now using your expression in a pane, I get a variety of numbers such as 3.33 & 4.67, so the number after the decimal point would only output the half star if it was equal or greater than .5

thanks
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on November 09, 2012, 05:56:09 pm
[ Edit: see next post ]

Use this instead is the column:

save(if(compare(load(v_albumratingsum[album artist (auto)][album]),>,0),formatnumber(math( load(v_albumratingsum[album artist (auto)][album]) / load(v_tracks[album artist (auto)][album]) ),2),0), v_rating)/
Mid(★★★★★, 0, load(v_rating))/
If(Compare(Right(load(v_rating), 2), >=, .5), ☆, )
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on November 09, 2012, 07:10:06 pm
Hi MrC

tried the expression, it seems to give all ratings a half star,
Might be less a headache if I just opt for a five star system instead of using half stars..

It might be that some get the auto generated album rating and have two places after the decimal point whereas others only have 1 place. It might not be that though because some entries output 5, and still get the half star.

Just a thought would it be better if I created another custom album rating field, and created a view that would compare the auto generated result to the custom field and if they were not equal show it in the file list. I could then manually update inconsistencies, rather than have this complex expression running all the time in my main view?

It dosen't seem to be much slower but I can only imagine it will get slower as more tracks get rated.

Cheers
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on November 09, 2012, 07:37:04 pm
Indeed, I'm sorry.

Here you go:

save(if(compare(load(v_albumratingsum[album artist (auto)][album]),>,0),formatnumber(math( load(v_albumratingsum[album artist (auto)][album]) / load(v_tracks[album artist (auto)][album]) ),2),0), v_rating)/
Mid(★★★★★, 0, load(v_rating))/
If(math(below(load(v_rating) % 1, .5)), ,☆)
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on November 10, 2012, 08:58:20 am
Thanks

Works great :)
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: toomanybarts on December 02, 2012, 01:08:38 am
mark_h I love this ability to generate an average album rating THANK YOU.

I wont pretend to understand the expression or how it works, but I love it.

Is there a way to be able to query the smart list I have set up per your post (Smartlist = "Album Rating") so that I could set up a SEPERATE smartlist that only pulls in Albums that are rated 4 or greater?

[The idea is I would want to put only those albums that are 4 stars or over on my iPod)

I have tried what 'justsomeguy' suggested and it works for the pane view, but I do not know enough about logical expressions to set up the correct smart rule when building a new Smartlist.

Any help would be very much appreciated.

B
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on December 02, 2012, 01:48:23 am
Create the Avg Rating smartlist.

Create a new smartlist, perhaps named Avg Rating >= 4.  In the Rules, select Playlists is any Smartlists\Avg Rating.  Next, select the Import/Export button, and after the playlistid==<MC's internal playlist number>, append a <space> character followed by the code below:

Code: [Select]
[=Compare(if(compare(load(v_albumratingsum[album artist (auto)][album]),>,0),formatnumber(math( load(v_albumratingsum[album artist (auto)][album]) / load(v_tracks[album artist (auto)][album]) ),2),0), >=, 4)]=1
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: toomanybarts on December 02, 2012, 12:44:55 pm
MrC - WOW!  I dont know what else to say except THANK YOU THANK YOU!!

There is NO WAY I would have been able to work that out and it works like a charm!
(It would seem that this functionality should be built into a future version of MC in a simple field option...?)
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on December 02, 2012, 12:50:47 pm
You're welcome.

By the way, I should have pointed out that you can modify the comparison value in this part of the expression:

    >=, 4)

Just change the comparison and/or value as desired.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: toomanybarts on December 02, 2012, 02:05:29 pm
MrC - Got it and makes sense.  1 other question, but this may be a little more tricky...as well as lots of albums, I also have just favourite tracks from certain albums...unfortunately, these single or sometimes (2 or 3 tracks from an album) are showing up as a 4-star album.

For example I have 1 track from an album that I have rated 4, that shows up in the >=4 Album Smartlist you helped me create.

Is there a way to add one more qualifier to the query so that it only pulls in an album if there are 3 or more tracks in that album?

No worries if this takes it to a whole new level of complication, but I thought I'd test your patience and goodwill!!  ;) 
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on December 02, 2012, 02:31:32 pm
Trivial my friend, trivial!  :-)

Tack this on to the end of the Avg Rating >= 4 smartlist rule, with a leading space.  The red again shows where to make changes to the comparison value:

 [=Compare(load(v_tracks[album artist (auto)][album]), >=, 3)]=1
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: toomanybarts on December 02, 2012, 04:29:33 pm
Nice!!
You are the man - thank-you for the quick responses and assistance!!

I need to brush up on this expression malarky - seems pretty powerful if you know what youre doing!!
Any suggestions for a good place to start reading up and kick-starting the learning process?
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on December 02, 2012, 04:42:20 pm
These expressions are not for the faint of heart, mostly because they rely on some insight as to how MC works.  Start simpler, as in marco's expression wiki page:

   http://wiki.jriver.com/index.php/Media_Center_expression_language (http://wiki.jriver.com/index.php/Media_Center_expression_language)

After that, there are many examples here on Interact - just search "expression".

Here's my work in progress regarding Search queries:

   http://wiki.jriver.com/index.php/MrC-temp (http://wiki.jriver.com/index.php/MrC-temp)
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: toomanybarts on December 02, 2012, 09:02:45 pm
GULP!
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on December 18, 2012, 12:06:10 pm
Just wondering, say I wanted to count the total tracks of a particular artist, but some albums have two artists via the semi-colon delimiter. And each of the two artist have their own solo albums Is there any way to adjust the expression the separate the artists before performing the calculation?? Right now it would just count them as one artist..

Thanks
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on December 18, 2012, 01:16:11 pm
I mean using something like
Replace([Album Artist], ;, •)•, •, / ;), to calculate the tracks individually for each artist in a delimited list?

Would that work?
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on December 18, 2012, 02:03:00 pm
There is currently no way to do this generally.  But, if you are sure that you'll have no more than a few Artists, this can be handled without too much trouble.

The problem is that for tracks that have 2, 3, ... or more Artists, there's no way to tell the MC expression language to iterate over, and so something with, all the values.  So you can do the first, and even the second, in fact up to as many as you want.  But each additional artist requires hard coding a case to deal with these, and test for emptiness.  The basic idea is, and I'll use pseudo-code:

  if Artist[1] is not emtpy
     increment tracks for artist[1]
  if Artist[2] is not emtpy
     increment tracks for artist[2]
  ...
  if Artist[n] is not emtpy
     increment tracks for artist[n]
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: gappie on December 18, 2012, 02:17:19 pm
Just wondering, say I wanted to count the total tracks of a particular artist, but some albums have two artists via the semi-colon delimiter. And each of the two artist have their own solo albums Is there any way to adjust the expression the separate the artists before performing the calculation?? Right now it would just count them as one artist..

Thanks
it is possible to just do that in a view.. make a view with the artists, ond put [track #] under the thumb. the attachment shows a list with artists and their amount of tracks and sorted with the one who has the most first.

:)
gab
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on December 18, 2012, 02:29:43 pm
Thanks Gappie, I'll try that out.. Although it isn't really track numbers of Album Artists I'm really after that was just the simplest way to think of this idea for me.. Although I may still use it in that sense at some time.

It's really for photos , many photos belong to multiple categories, I was, thinking using what MrC said so I could build a pane that has [Categories] (Number of Items), it's only really for a quick reference of where the bulk of content is, and possibly making another pane that is sorted accordingly by the number of items..

Right now if I build a pane this way and an item belongs to two categories.

i.e. Holidays (255) (But 10 also have birthday tag)

The pane would output

Holidays (245)
Holidays (10)
Birthdays (10)


Thanks MrC

I understand what you mean but I am a bit lot of how to proceed. Say the maximum is 4, or maybe 5 for good measure, how would I go about implementing your pseudo code, using the Replace function??

[=save(0,v_tracks[Album Artist][Album Artist])1]=1 [=save(math(1+load(v_tracks[Album Artist][Album Artist])),v_tracks[Album Artist][Album Artist])1]=1
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on December 18, 2012, 05:15:18 pm
Here's a quick, dirty and inefficient expression for counting up to 4 (semicolon separated) Keywords.  You can use this in the Rules for file display.

Code: [Select]
[Filename (path)]=[M:\Testing" [=save(0,v_count_listitem([keywords],0,;))1]=1 [=save(0,v_count_listitem([keywords],1,;))1]=1 [=save(0,v_count_listitem([keywords],2,;))1]=1 [=save(0,v_count_listitem([keywords],3,;))1]=1 [=ifelse(!isempty(listitem([keywords],0,;)),save(math(1+load(v_count_listitem([keywords],0,;))),v_count_listitem([keywords],0,;)))1]=1 [=ifelse(!isempty(listitem([keywords],1,;)),save(math(1+load(v_count_listitem([keywords],1,;))),v_count_listitem([keywords],1,;)))1]=1 [=ifelse(!isempty(listitem([keywords],2,;)),save(math(1+load(v_count_listitem([keywords],2,;))),v_count_listitem([keywords],2,;)))1]=1 [=ifelse(!isempty(listitem([keywords],3,;)),save(math(1+load(v_count_listitem([keywords],3,;))),v_count_listitem([keywords],3,;)))1]=1

Now, you can add a panes column to show the counts of each keyword using the expression:

Code: [Select]
ifelse(!isempty(listitem([keywords], 0, ;)),
    listitem([keywords], 0, ;) {load(v_count_listitem([keywords], 0, ;))});
ifelse(!isempty(listitem([keywords], 1, ;)),
    listitem([keywords], 1, ;) {load(v_count_listitem([keywords], 1, ;))});
ifelse(!isempty(listitem([keywords], 2, ;)),
    listitem([keywords], 2, ;) {load(v_count_listitem([keywords], 2, ;))});
ifelse(!isempty(listitem([keywords], 3, ;)),
    listitem([keywords], 3, ;) {load(v_count_listitem([keywords], 3, ;))})/
&datatype=[list]

You can change Keywords throughout to the field of your choice, so long as it is a list type.  If the delimiter is not a semicolon, the expression needs to be updated to reflect that.

I said it would be ugly, so here are flowers to ease the pain.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on December 18, 2012, 05:39:12 pm
Thanks MrC..
Works perfectly  ;D , I doubt there will ever be more than four..

Quick!! That would have taken me ages, even if I ever figured it out

Cheers
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on December 18, 2012, 08:38:16 pm
I had a few more minutes on this one.  Ignoring the regular expression, the panes expression might be easier on the eyes and better understood as:

ifelse(regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/),
   delimit([R1], / {load(v_count_[R1])});
   delimit([R2], / {load(v_count_[R2])});
   delimit([R3], / {load(v_count_[R3])});
   delimit([R4], / {load(v_count_[R4])});
)&datatype=[list]

The RE is long, but is essentially repeated groups:

   (?:([^;]+);\s?)

and each one essentially boils down to:

   1 or more non-semicolon characters, followed by a semicolon and a possible space.

This is how lists are structured (stuff; stuff; stuff).  I've highlighted in green, blue, and red each portion.  Its easy now to add more keyword captures: copy and paste the red fragment, and add another delimit() line.  Each delimit() line tests for a non-empty value and adds the numeric count in brackets.  No more IFs().

Modify it slightly, putting the count first, gives us sorting by count:

ifelse(regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/),
   delimit([R1], , load(v_count_[R1]):/ );
   delimit([R2], , load(v_count_[R2]):/ );
   delimit([R3], , load(v_count_[R3]):/ );
   delimit([R4], , load(v_count_[R4]):/ );
)&datatype=[list]

(see attached image)

Of course, the search portion in Set rules for file display has to be fixed up...
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on December 18, 2012, 10:00:53 pm
A couple more minutes  :o Nice  ;D

I'd be lying if I said I understood how that works, but it works

Quote
Of course, the search portion in Set rules for file display has to be fixed up...

I think I understand what you mean, it is working right now with the current rules, but if I added several more delimits to the pane expression, it wouldn't work because the rules for file display also limits how many you can have?? Will the rules for file display be better suited using regex as well?


Thanks
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on December 18, 2012, 10:16:38 pm
Exactly, the Rules for file display would need additional clauses to setup the global variables for keywords 5, 6, etc.  Those rules initialize the totals (one variable per keyword), and the pane rules outputs the values.

Also, yes, Regex() could be used to capture more keywords in the Search rule.  Unfortunately, you can only get up to 9 captures, so that means only 9 keywords.  If more is needed, then the first method for both sets of rules must be used.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on December 18, 2012, 11:22:33 pm
I'm sure 9 captures is more than anyone would ever need.

Is it worth the time/more efficient to use regex for the rules for file display in this manner or should I just augment the first way to include as many captures as I need (Not going over nine because I like the Regex for the pane)

Makes me wonder what else is possible using global variables possibly with regex...
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on December 18, 2012, 11:28:17 pm
I'll take a look tomorrow at this.  I don't think it will be any faster -- just easier to read.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on December 18, 2012, 11:31:51 pm
Cool, no problem

Thanks again
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on December 19, 2012, 12:31:19 am
Sorry, using Regex() won't work simply in the Search rules.

The reason has to do with how MC runs the clauses in the search rule list, and how each clause loses the return values from Regex().

It is OK to use the Pane column expression posted.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on December 19, 2012, 06:04:25 am
Thanks, no matter it is working well as is :)
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on December 19, 2012, 11:53:47 am
Just for clarity, and I modified my comments above.  Regex() can be used, but it needs to be used twice; once for the initialization stage of the globals, and once again for the incrementing.  This works fine, and you can add up to 9 captures:

Code: [Select]
[=regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)save(0,v_count_[R1])save(0,v_count_[R2])save(0,v_count_[R3])save(0,v_count_[R4])1]=1 [=regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)ifelse(!isempty([R1]),save(math(1+load(v_count_[R1])),v_count_[R1]))ifelse(!isempty([R2]),save(math(1+load(v_count_[R2])),v_count_[R2]))ifelse(!isempty([R3]),save(math(1+load(v_count_[R3])),v_count_[R3]))ifelse(!isempty([R4]),save(math(1+load(v_count_[R4])),v_count_[R4]))1]=1

Formatted for readability:

[=
   regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)
   save(0,v_count_[R1])
   save(0,v_count_[R2])
   save(0,v_count_[R3])
   save(0,v_count_[R4])
1]=1

MC first evaluates the expression against all files, capturing the first 4 keywords, and initializes those 4 keyword-specific global variables to 0.

The next portion, run against the returned file set:

[=
   regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)
   ifelse(!isempty([R1]),save(math(1+load(v_count_[R1])),v_count_[R1]))
   ifelse(!isempty([R2]),save(math(1+load(v_count_[R2])),v_count_[R2]))
   ifelse(!isempty([R3]),save(math(1+load(v_count_[R3])),v_count_[R3]))
   ifelse(!isempty([R4]),save(math(1+load(v_count_[R4])),v_count_[R4]))
1]=1

performs the same 4 keyword capture (necessary because the [Rn] values in the first custom search clause are destroyed), and for each keyword found (non-empty), increments the 4 keyword-specific variable.

Hopefully these comments help others working with globals, especially in the Query (Set rules for file display) stage of a view.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on December 19, 2012, 03:45:22 pm
Thanks MrC I'll try that out shortly
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on December 20, 2012, 04:00:37 pm
Links to other threads about mischief (fun?) to be had with Global Variables:

* Generating Statistics (http://yabb.jriver.com/interact/index.php?topic=77826.0)
* Generating album track count (http://yabb.jriver.com/interact/index.php?topic=76581.msg518902#msg518902)
* Generating album ratings (http://yabb.jriver.com/interact/index.php?topic=72049.0)
* Highlighting playing album (http://yabb.jriver.com/interact/index.php?topic=74116.0)
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 02, 2013, 07:13:34 pm
I know this is an old thread, but I've been trying to do something like this using the half-star method of this thread:

http://yabb.jriver.com/interact/index.php?topic=76240.0

I'd like to be able to get an album rating based on the decimal song rating that weights by track length. So:

album rating = average of track ratings, where track rating are...

track rating x (track length/album length)

How would I do this?

Also, what are the chances there is a remote control for MC that would allow me to input the decimal track ratings and see the weighted album ratings as they are entered. I'm currently using J.Remote, which obviously would not allow this.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 07, 2013, 11:54:43 am
No one?
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on June 19, 2013, 08:23:39 pm
Late reply, sorry.

In this thread:

    http://yabb.jriver.com/interact/index.php?topic=77826.0

I show how to calculate values across tracks.  If you can review, it might help you to see how to calculate these values.  Your math formula is straightforward - all that is needed is a view that calculates each component and combines them to form the result.  If none of this makes sense, I'll provide more help.

As to your last question, I can't think of anything that will meet the criteria.  The tricks we're using for the above require a view be refreshed.  While you can store the results of such views into custom user variables, the view must be reached at least once first.  So there's no way to change a tag value and have that view automatically refreshed via JRemote.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 23, 2013, 08:20:14 am
Thanks, but I could use some more specific, step-by-step guidance.

Thanks in advance.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 23, 2013, 08:28:12 am
As to your last question, I can't think of anything that will meet the criteria.  The tricks we're using for the above require a view be refreshed.  While you can store the results of such views into custom user variables, the view must be reached at least once first.  So there's no way to change a tag value and have that view automatically refreshed via JRemote.

Ok, that makes sense, but wha about to just store the data. J.Remote allows input of ratings in one-star increments. Is they're any way to accommodate the decimals through the remote, even if these are not immediately refreshed?
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on June 23, 2013, 12:53:16 pm
Thanks, but I could use some more specific, step-by-step guidance.

Thanks in advance.

Ok, it might take me a few days to get to it, as I'm a little busy with some work.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on June 23, 2013, 01:02:18 pm
Ok, that makes sense, but wha[t] about to just store the data. J.Remote allows input of ratings in one-star increments. Is they're any way to accommodate the decimals through the remote, even if these are not immediately refreshed?

I haven't used JRemote to input data, and only looked briefly at its interface to do so.  It doesn't appear to show valueless tags, and don't know how to get it to show these.  If it can, then you should be able to enter a decimal value into your own user field.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 23, 2013, 04:55:53 pm
Ok, it might take me a few days to get to it, as I'm a little busy with some work.
No problem. Thank you for your help!
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on June 24, 2013, 02:47:58 pm
I'd like to be able to get an album rating based on the decimal song rating that weights by track length. So:

album rating = average of track ratings, where track rating are...

track rating x (track length/album length)

How would I do this?

Ok, here you go.  You may have to tweak after you played with it.  I didn't bother to ensure a ceiling of 10 for the calculated values.

Attached are some screenshots that show how to set up the key areas.  The columns contain the requested values (see Avg Biased Ratings.png).

Now, setup your fields and views:

1) Create two user fields (see AAA field.png).  Create the AAA field as shown by the yellow highlights.  Next, create a new user field as named by the pink highlight (which I've shown in the same screenshot - just create the new field, giving it the pink highlighted name and that's it for that field).  The AAA field is created as a shortcut to avoid repetition of and errors while entering the longer Album / Album Artist (auto) field pairs.

2) Setup the Rules for file display under Customize for the view.  You can copy/paste the value below in the Import / Export button.  Be sure not to leave leading or trailing spaces with your paste:

Code: [Select]
[=save(0,v_ntracks_[AAA])1]=1 [=save(0,v_duration_[AAA])1]=1 [=save(0,v_trating_[AAA])1]=1 [=save(math(1 + load(v_ntracks_[AAA])), v_ntracks_[AAA])1]=1 [=save(math([duration,0] + load(v_duration_[AAA])),v_duration_[AAA])1]=1 [=save(math(10 * [_Rating (track)] * ([duration,0] / load(v_duration_[AAA]))),v_trating_[AAA]_[name])1]=1 [=save(math(load(v_trating_[AAA]_[name]) + load(v_trating_[AAA])),v_trating_[AAA])1]=1 ~sort=[Disc #],[Track #]

3) Create the columns.  The columns are either fields or expression columns (I'll ignore the obvious ones like [track #]):

 - Total Tracks:  load(v_ntracks_[AAA])
 - _Rating (track): this is the field you created - just add the column.
 - Track Rating (biased): formatnumber(load(v_trating_[AAA]_[name]),1)
 - Avg Album Rating (biased): formatnumber(math(load(v_trating_[AAA]) / load(v_ntracks_[AAA])),1)
 - Album Duration: load(v_duration_[AAA])

 - tlen / alen is my quick test of track length / album length: math([duration,0] / load(v_duration_[AAA]))

Explaining the rules above.  The following rules initialize to 0 the global variables v_ntracks, v_duration, and v_trating (each are also suffixed with _[AAA], as these variables need to be unique to each Album / Album Artist (auto) pair):

   [=save(0,v_ntracks_[AAA])1]=1
   [=save(0,v_duration_[AAA])1]=1
   [=save(0,v_trating_[AAA])1]=1

This increments the number of tracks:

   [=save(math(1 + load(v_ntracks_[AAA])), v_ntracks_[AAA])1]=1

This sums and saves the track duration into album duration:

   [=save(math([duration,0] + load(v_duration_[AAA])),v_duration_[AAA])1]=1

This calculates and saves your biased track rating:

   [=save(math(10 * [_Rating (track)] * ([duration,0] / load(v_duration_[AAA]))),v_trating_[AAA]_[name])1]=1

This adds the biased track rating to the current total track ratings:

   [=save(math(load(v_trating_[AAA]_[name]) + load(v_trating_[AAA])),v_trating_[AAA])1]=1

Just to sort the results:

   ~sort=[Disc #],[Track #]

Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 25, 2013, 09:24:39 pm
Thanks for this. I must have done something wrong, because my Avg Album (biased) and Track Rating (biased) columns remain 0 no matter what rating I put in. Also the Total Tracks, while accurate for some albums, is inaccurate for others. And the Album Duration column is all whacky, too, with different figures for the same album, and figures that are totally off.

Note: I use "Album Artist" for "Last Name, First Name" sorting. Maybe that's messing it up.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on June 25, 2013, 09:29:23 pm
Ok, so you'll have to verify what you have done.  I'm guessing you've not setup a field correctly (maybe the AAA field), or there are some formatting issues from copy/paste.  Screenshots of each area would be good (field definitions, Set rules for file display, and column expressions for those that appear wrong.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on June 25, 2013, 09:31:25 pm
Album Artist probably won't work, since this will be empty for most albums.  It is critical that all albums be uniquely identified, or the tallies will be wrong.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 25, 2013, 09:38:16 pm
Total tracks are the total tracks of all albums by a single artist. That much I've figured out. Duration still doesn't make sense.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 25, 2013, 09:40:47 pm
Yes, I had the AAA set up wrong. Let me report back in a minute...
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 25, 2013, 09:45:44 pm
Alright, steady and accurate Total Tracks. And steady (but kinda high looking, is this in seconds?) Album Duration. But entering ratings into Rating (Tracks) does not affect the other columns, which remain 0.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on June 25, 2013, 09:48:44 pm
Good on tracks.  Duration is in seconds.  You'll need to refresh the view to update the global vars.  Just switch views and come back to be sure.  If that still doesn't work, check your rules for file display for accurate copy/paste from mine above.

Did you create the track rating field named exactly as I did (including leading underscore).  If not, be sure to change it everywhere.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 25, 2013, 09:53:35 pm
It was the

_

that was screwing it up. I had "Rating (Tracks)" not "_Rating (Tracks)"

Seems to work now, though I may have some further questions about tweaking it.

Thanks!
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on June 25, 2013, 10:00:49 pm
Good job!
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 25, 2013, 10:12:00 pm
Thanks, but not quite there yet. I'm not getting accurate figures for the Avg Album Rating (biased). The number is too low. I have an Excell doc with the formula worked out and inputting the ratings for an album gives me a totally different album average.

In the Excell sheet the album rating is the sum of the individual track ratings, which are calculated as follows:

track rating x (track length/album length)

Why am I getting a discrepancy?

Also, what are the chances I could get the non-rated tracks to not count in the equation?
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on June 25, 2013, 10:15:50 pm
Zip the spreadsheet and attach it so I can look.  Enter the values you are getting as a separate, labelled column, or include a screenshot. We only need to look at one album.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 25, 2013, 10:24:54 pm
Ok, will get to this tomorrow. Thanks for the help!
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 27, 2013, 01:48:53 pm
The forum isn't allowing me to send another personal message, so I'm just going to post here.

The time column in my file is set for hours:minutes:seconds. Does that have anything to do with it?  I don't see how changing this to second would make a difference, but I'll try.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on June 27, 2013, 01:50:16 pm
Let's take this offline.

The column C data is stored in Excel-style Date/Time format, and that is having conversion problems.  A simple number won't have the problem - that's why I'm saying to use Seconds for the column data.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 27, 2013, 02:24:29 pm
I sent you an email. I converted column C to numbers and used seconds and I get the exact same result, which to my mind corresponds more accurately to what I imagine a weighted average would look like (compared to the unweighted average, easy enough to calculate). The average I'm getting in JRiver seems off to me, which suggests either a) I've done something wrong or b) the formula isn't quite right.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Denti on June 27, 2013, 09:08:52 pm
MrC helped me out big time!! tHANK YOU!

The solution was to tweak the rules slightly as follows (note, this also ignores non-rated tracks, which I wanted):

[=save(0,v_ntracks_[AAA])1]=1 [=save(0,v_duration_[AAA])1]=1 [=save(0,v_trating_[AAA])1]=1 [=ifelse(!isempty([_Rating (track)]),save(math(1 + load(v_ntracks_[AAA])), v_ntracks_[AAA]))1]=1 [=ifelse(!isempty([_Rating (track)]),save(math([duration,0] + load(v_duration_[AAA])),v_duration_[AAA]))1]=1 [=ifelse(!isempty([_Rating (track)]),save(math([_Rating (track)] * ([duration,0] / load(v_duration_[AAA]))), v_trating_[AAA]_[name]))1]=1 [=ifelse(!isempty([_Rating (track)]),save(math(load(v_trating_[AAA]_[name]) + load(v_trating_[AAA])),v_trating_[AAA]))1]=1 ~sort=[Disc #],[Track #]


Then the Avg Album Rating field was changed with this expression:   formatnumber(load(v_trating_[AAA]),1)

That provides the sum of the track ratings that are weighted by length. Pretty sweet!

Thanks to the whole JRiver team. This is a great product!
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on June 27, 2013, 09:15:42 pm
A Cliff Notes summary:

  - Average Album Rating is now being calculated as a sum of the biased track ratings
  - Unrated tracks are ignored
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on July 13, 2013, 12:54:12 pm
Just for clarity, and I modified my comments above.  Regex() can be used, but it needs to be used twice; once for the initialization stage of the globals, and once again for the incrementing.  This works fine, and you can add up to 9 captures:

Code: [Select]
[=regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)save(0,v_count_[R1])save(0,v_count_[R2])save(0,v_count_[R3])save(0,v_count_[R4])1]=1 [=regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)ifelse(!isempty([R1]),save(math(1+load(v_count_[R1])),v_count_[R1]))ifelse(!isempty([R2]),save(math(1+load(v_count_[R2])),v_count_[R2]))ifelse(!isempty([R3]),save(math(1+load(v_count_[R3])),v_count_[R3]))ifelse(!isempty([R4]),save(math(1+load(v_count_[R4])),v_count_[R4]))1]=1

Formatted for readability:

[=
   regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)
   save(0,v_count_[R1])
   save(0,v_count_[R2])
   save(0,v_count_[R3])
   save(0,v_count_[R4])
1]=1

MC first evaluates the expression against all files, capturing the first 4 keywords, and initializes those 4 keyword-specific global variables to 0.

The next portion, run against the returned file set:

[=
   regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)
   ifelse(!isempty([R1]),save(math(1+load(v_count_[R1])),v_count_[R1]))
   ifelse(!isempty([R2]),save(math(1+load(v_count_[R2])),v_count_[R2]))
   ifelse(!isempty([R3]),save(math(1+load(v_count_[R3])),v_count_[R3]))
   ifelse(!isempty([R4]),save(math(1+load(v_count_[R4])),v_count_[R4]))
1]=1

performs the same 4 keyword capture (necessary because the [Rn] values in the first custom search clause are destroyed), and for each keyword found (non-empty), increments the 4 keyword-specific variable.

Hopefully these comments help others working with globals, especially in the Query (Set rules for file display) stage of a view.

Hey MrC, was just wondering, would there be a simple way change this to calculate album ratings in the same fashion (well keyword album ratings). Again it isn't for music files, so a file might belong to 2 different keywords.. I've tried numerous times over the past few months leaving it and then returning for another try.. My regex has got much better in the meantime although still pales in comparison to your regexcellent wizardry.. I was trying to learn from the original album rating expression and somehow incorporate it in this one, I got close but it resulted in a mammoth expression that just didn't quite work..

Thanks
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on July 13, 2013, 04:20:05 pm
... calculate album ratings ... (well keyword album ratings).

Can you be more specific and clarify this?

regexcellent - good word.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on July 13, 2013, 07:58:51 pm
Ok I'll try to be clear as possible

I have my field Categories, where one item may belong to several, delimited using ;

Previously the code below was made to calculate the total number of items of all categories but an item may belong to several categories and will still be included in the main count for each category it contains. I'd like to do the same but calculate a categories rating.. The original album rating variables will not suffice, I think because an item that is tagged Holiday;BBQ will not be included in the overall calculation for category rating for all other files that are simply tagged, Holiday. As Holiday;BBQ will seem like a totally different category, if you catch my drift?

Was also wondering, I have been learning how to use regex every now and again, mostly from the link specified in the wiki http://msdn.microsoft.com/en-us/library/bb982727.aspx (http://msdn.microsoft.com/en-us/library/bb982727.aspx). Do you know of any other places that provide good resourced to learn about this type of regex? That resource is good, a lot of it is easy to understand, but some other stuff is a little difficult to take in and anywhere that provides detailed explanations would be good.. I was also looking into the program Regexbuddy but I'm unsure if it will help making and regex expressions any easier within mc..

Well hope I've clarified enough

Thanks

Quote
[=
   regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)
   save(0,v_count_[R1])
   save(0,v_count_[R2])
   save(0,v_count_[R3])
   save(0,v_count_[R4])
1]=1

[=
   regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)
   ifelse(!isempty([R1]),save(math(1+load(v_count_[R1])),v_count_[R1]))
   ifelse(!isempty([R2]),save(math(1+load(v_count_[R2])),v_count_[R2]))
   ifelse(!isempty([R3]),save(math(1+load(v_count_[R3])),v_count_[R3]))
   ifelse(!isempty([R4]),save(math(1+load(v_count_[R4])),v_count_[R4]))
1]=1
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on July 14, 2013, 12:32:03 am
The code you're referring to counted the number of times a Keyword was used.

It sounds now like you now want to count something from Categories.  And you mention something about wanting to calculate some type of categories rating.

What is the formula for calculating this rating?  You have a Category value, of say:

   Holiday; Bob

How does Holiday get rated?  And Bob?

Previously, we just counted.  This time, you want to apply some concept of goodness or badness.  So where do those metrics come from?
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on July 14, 2013, 12:55:46 am
It's easier for me to think of the categories (or keywords) field just like an album field except in this instance, a file can belong to two or more albums..

Well the way I was thinking, the exact same way the original album rating expression worked kind of..

Using regex like before to count the v_tracks for each category only in the original is was something along the lines of [=save(0,v_tracks[album artist (auto)][album])1], now is would be along the lines of [=save(0,v_tracks[Keywords])1]

Then using the same technique if at all possible, using regex captures to add up the track ratings for each individual category using an augmented version of the original album rating formula. And store the value

The original

[=if(compare([rating],=,0),save(-1,v_albumratingsum[album artist (auto)][album]),)1]=1 [=if(compare(load(v_albumratingsum[album artist (auto)][album]),>,-1),save(math([rating]+load(v_albumratingsum[album artist (auto)][album])),v_albumratingsum[album artist (auto)][album]),)1]=1

Would become something like this but used in the same way with regex where we counted the number of times a keyword was used.

[=if(compare([rating],=,0),save(-1,v_keywordsratingsum[Keyword]),)1]=1 [=if(compare(load(v_keywordsratingsum[keywords][album]),>,-1),save(math([rating]+load(v_keywordsratingsum[keywords])),v_keywordsratingsum[keywords]),)1]=1

possible?
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on July 14, 2013, 01:29:53 am
So simply put, it sounds like you want a calculation of track ratings by keyword.

  For each keyword in Keywords
      average of all track ratings marked with this keyword
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on July 14, 2013, 01:32:16 am
Yep that's it..
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on July 14, 2013, 02:12:23 am
I'll think more about it tomorrow.  I'm the meantime, you're going to want to take the "The original" code, and replace the global variable:

   v_albumratingsum[album artist (auto)][album]

with something like:

   v_kw_rating_sum_[R1]

You'll want to duplicate the code for each of the other [R2], [R3] and [R4] keyword values.

And you'll use the regex() from above, replacing Keywords with Categories:

   regex([categories];, ...
 
to set [R1], [R2], [R3], and [R4] beforehand.  These grab the keywords, and once grabbed can be used to build the name of the global variables.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on July 14, 2013, 02:18:20 am
Thanks MrC, I'll give it a bash
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on July 14, 2013, 09:31:34 pm
Ok here is my best shot.. Untested, done to the best of my ability, probably not on the ball at all, I basically tried to merge the original expressions for album ratings with the regex expression you made to count the items in categories.


[=
   regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)
   save(0,v_tracks_[R1])
   save(0,v_tracks_[R2])
   save(0,v_tracks_[R3])
   save(0,v_tracks_[R4])
1]=1

[=
   regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)
   ifelse(!isempty([R1]),save(math(1+load(v_tracks_[R1])),v_tracks_[R1]))
   ifelse(!isempty([R2]),save(math(1+load(v_tracks_[R2])),v_tracks_[R2]))
   ifelse(!isempty([R3]),save(math(1+load(v_tracks_[R3])),v_tracks_[R3]))
   ifelse(!isempty([R4]),save(math(1+load(v_tracks_[R4])),v_tracks_[R4]))
1]=1

[=
   regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)
   save(0,v_kw_rating_sum_[R1])
   save(0,v_kw_rating_sum_[R2])
   save(0,v_kw_rating_sum_[R3])
   save(0,v_kw_rating_sum_[R4])
1]=1


[=
   regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)
   save(if(compare([rating],=,0),save(-1,v_kw_rating_sum_[R1]),))
   save(if(compare([rating],=,0),save(-1,v_kw_rating_sum_[R2]),))
   save(if(compare([rating],=,0),save(-1,v_kw_rating_sum_[R3]),))
   save(if(compare([rating],=,0),save(-1,v_kw_rating_sum_[R4]),))
1]=1



I'm pretty sure this one below needs to use the ifelse statement in the same way as the one, second from the top..

[=
   regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/,-1)
   if(compare(load(v_kw_rating_sum_[R1]),>,-1),save(math([rating]+load(v_kw_rating_sum_[R1])),v_kw_rating_sum_[R1]),)
   if(compare(load(v_kw_rating_sum_[R2]),>,-1),save(math([rating]+load(v_kw_rating_sum_[R2])),v_kw_rating_sum_[R2]),)
   if(compare(load(v_kw_rating_sum_[R3]),>,-1),save(math([rating]+load(v_kw_rating_sum_[R3])),v_kw_rating_sum_[R3]),)
   if(compare(load(v_kw_rating_sum_[R4]),>,-1),save(math([rating]+load(v_kw_rating_sum_[R4])),v_kw_rating_sum_[R4]),)
1]=1

Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on July 16, 2013, 04:09:06 am
I clearly have a lot of learning to do, that didn't work at all :P

However if I loaded load(v_kw_rating_sum_[R1]) into a pane or column it did generate a number, 31025...
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on July 16, 2013, 01:10:22 pm
Let see if this works for you.  I've replaced the Regex() with ListItem() so that you can extend this (in case any item has more keywords than Regex() can support).

Add this to your Set rules for file display (not, if you are already using v_tracks_keyword there, you should replace v_tracks_ in all the code below with something unique, such as v_nratedtracks_):

Code: [Select]
[=1save(0, v_tracks_listitem([keywords], 0))save(0, v_tracks_listitem([keywords], 1))save(0, v_tracks_listitem([keywords], 2))save(0, v_tracks_listitem([keywords], 3))]=1 [=1save( 0,v_kwrsum_listitem([keywords],0))save( 0,v_kwrsum_listitem([keywords],1))save( 0,v_kwrsum_listitem([keywords],2))save( 0,v_kwrsum_listitem([keywords],3)))]=1 [=1ifelse(compare([rating],>,0), ifelse(!isempty(listitem([keywords], 0)), save(math(1+load(v_tracks_listitem([keywords], 0))),v_tracks_listitem([keywords], 0)))ifelse(!isempty(listitem([keywords], 1)), save(math(1+load(v_tracks_listitem([keywords], 1))),v_tracks_listitem([keywords], 1)))ifelse(!isempty(listitem([keywords], 2)), save(math(1+load(v_tracks_listitem([keywords], 2))),v_tracks_listitem([keywords], 2)))ifelse(!isempty(listitem([keywords], 3)), save(math(1+load(v_tracks_listitem([keywords], 3))),v_tracks_listitem([keywords], 3))))]=1 [=1save(math([rating]+load(v_kwrsum_listitem([keywords], 0))),v_kwrsum_listitem([keywords], 0))save(math([rating]+load(v_kwrsum_listitem([keywords], 1))),v_kwrsum_listitem([keywords], 1))save(math([rating]+load(v_kwrsum_listitem([keywords], 2))),v_kwrsum_listitem([keywords], 2))save(math([rating]+load(v_kwrsum_listitem([keywords], 3))),v_kwrsum_listitem([keywords], 3))]=1
The code above split apart for readability follows.  This initializes the number of tracks per keyword to 0:

[=1
   save(0, v_tracks_listitem([keywords], 0))
   save(0, v_tracks_listitem([keywords], 1))
   save(0, v_tracks_listitem([keywords], 2))
   save(0, v_tracks_listitem([keywords], 3))
]=1

and then initializes the keyword rating sum per keyword to 0:

[=1
   save(0,v_kwrsum_listitem([keywords],0))
   save(0,v_kwrsum_listitem([keywords],1))
   save(0,v_kwrsum_listitem([keywords],2))
   save(0,v_kwrsum_listitem([keywords],3)))
]=1

and if Rating is non-zero, increments the per keyword track count:

[=1
   ifelse(compare([rating],>,0),
      ifelse(!isempty(listitem([keywords], 0)), save(math(1+load(v_tracks_listitem([keywords], 0))),v_tracks_listitem([keywords], 0)))
      ifelse(!isempty(listitem([keywords], 1)), save(math(1+load(v_tracks_listitem([keywords], 1))),v_tracks_listitem([keywords], 1)))
      ifelse(!isempty(listitem([keywords], 2)), save(math(1+load(v_tracks_listitem([keywords], 2))),v_tracks_listitem([keywords], 2)))
      ifelse(!isempty(listitem([keywords], 3)), save(math(1+load(v_tracks_listitem([keywords], 3))),v_tracks_listitem([keywords], 3))))
]=1

and finally, adds the Rating value to the keyword rating sum per keyword (our per-keyword accumulator):

[=1
   save(math([rating]+load(v_kwrsum_listitem([keywords], 0))),v_kwrsum_listitem([keywords], 0))
   save(math([rating]+load(v_kwrsum_listitem([keywords], 1))),v_kwrsum_listitem([keywords], 1))
   save(math([rating]+load(v_kwrsum_listitem([keywords], 2))),v_kwrsum_listitem([keywords], 2))
   save(math([rating]+load(v_kwrsum_listitem([keywords], 3))),v_kwrsum_listitem([keywords], 3))
]=1


Now, you create some expression columns.  This one will show the per-keyword total rating:

   load(v_kwrsum_listitem([keywords], 0)) : /
   load(v_kwrsum_listitem([keywords], 1)) : /
   load(v_kwrsum_listitem([keywords], 2)) : /
   load(v_kwrsum_listitem([keywords], 3))

and this one will show the per-keyword rating averages:

   listbuild(0, / :/ ,
      ifelse(!isempty(listitem([keywords],0)), math(load(v_kwrsum_listitem([keywords], 0)) // load(v_tracks_listitem([keywords], 0)))),
      ifelse(!isempty(listitem([keywords],1)), math(load(v_kwrsum_listitem([keywords], 1)) // load(v_tracks_listitem([keywords], 1)))),
      ifelse(!isempty(listitem([keywords],2)), math(load(v_kwrsum_listitem([keywords], 2)) // load(v_tracks_listitem([keywords], 2)))),
      ifelse(!isempty(listitem([keywords],3)), math(load(v_kwrsum_listitem([keywords], 3)) // load(v_tracks_listitem([keywords], 3))))
   )

With all the code above, you can just copy/paste a line from each fragment, and change the index to add more keywords.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on July 16, 2013, 08:46:13 pm
Thanks MrC, your a definite Genius at this stuff..

I had to change the delimiter to ; instead of : in the per-keyword rating averages expression.. Just wondering are you sure the mode should be set to 0? I saw on the wiki apparently there is no practical recorded use for it.. It's not quite working yet.. When the pane for rating is set at 5 and I pick a category, some show something like 12 out of 14 unrated and 2 rated 5.. I tried switching the mode to 1 for listbuild but no luck..

Appreciate the help.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: MrC on July 16, 2013, 09:02:11 pm
The usage of ListBuild() was just easier to nicely format the expression in the expression editor (allows using newlines after commas) and to easily output a formatted listing.

Using mode 0 is simply for forcing even empty items to show.  This way, you can visually see which keyword in the list got the hit by noticing its position.  If you use mode 1, then the empty items will be squashed away and you can't tell which keyword was hit.  You can remove the ListBuild() entirely, and just output the items directly if you want.

Changing from : to ; for a panes list is correct.  I had my expressions in the file list so I could see the results per file.  Be sure you got rid of that extra what space too (i.e. "/ :/ " should become just ";")

Using the expression in a pane won't work for selection.  Its hard to describe why - suffice it to say that it has to do with how we're tricking MC into generating the values in the first place.  I explain it a little after the similar comment here (http://yabb.jriver.com/interact/index.php?topic=77826.msg528609#msg528609).
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on July 17, 2013, 06:49:05 am
Oh I remember that, anyway thanks for the help :)

Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: locust on August 21, 2013, 04:06:59 am
I had a few more minutes on this one.  Ignoring the regular expression, the panes expression might be easier on the eyes and better understood as:

ifelse(regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/),
   delimit([R1], / {load(v_count_[R1])});
   delimit([R2], / {load(v_count_[R2])});
   delimit([R3], / {load(v_count_[R3])});
   delimit([R4], / {load(v_count_[R4])});
)&datatype=[list]

The RE is long, but is essentially repeated groups:

   (?:([^;]+);\s?)

and each one essentially boils down to:

   1 or more non-semicolon characters, followed by a semicolon and a possible space.

This is how lists are structured (stuff; stuff; stuff).  I've highlighted in green, blue, and red each portion.  Its easy now to add more keyword captures: copy and paste the red fragment, and add another delimit() line.  Each delimit() line tests for a non-empty value and adds the numeric count in brackets.  No more IFs().

Modify it slightly, putting the count first, gives us sorting by count:

  ifelse(regex([keywords];, /#(?:([^;]+);\s?)(?:([^;]+);\s?)?(?:([^;]+);\s?)?(?:([^;]+);\s?)?#/),
   delimit([R1], , load(v_count_[R1]):/ );
   delimit([R2], , load(v_count_[R2]):/ );
   delimit([R3], , load(v_count_[R3]):/ );
   delimit([R4], , load(v_count_[R4]):/ );
)&datatype=[list]

(see attached image)

Of course, the search portion in Set rules for file display has to be fixed up...

Trying to use the new groupcount expression to replace this. It works. I deleted to rules for file display & used the following.. It even seems to calculate the individual group count of each item in the keywords list just like the regex helped do..

expression to group by
[Keywords]&datatype=[LIST]

expression to display
[Keywords] /(groupcount()/)


But the only thing I can't find a workaround for, is making a pane that sorts by group count.. I've tried the following with no success..

expression to group by
groupcount():/ [Keywords]&datatype=[LIST]

expression to display
groupcount():/ [Keywords][/list][/list]
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: the.call on May 09, 2015, 08:40:35 pm

I did make a small modification to your expression so that tracks in an album with no rating get calculated as 3 stars instead of forcing the album rating to zero. I have a lot of my tracks rated but a huge amount of full albums have some several tracks with no rating. I know this won't give me a perfect representation of the albums rating but it works for me and as I rate more it will work itself out.

Thanks for sharing this.

Can You pls show Your Modification, 'cause I prefer this solution instead of get Album rating = 0 as long as not ALL tracks are rated.
Another way would be to set the average of the RATED Tracks to Album Rating, but I dont know how to implement this.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Tomplifier on May 26, 2020, 03:01:57 am
Hello,

I'm trying to get an alternative album rating as Denti was asking for. I like it more because some short Interlude-Tracks can pull the average rating down.

Unfortunately the global variables are not working for me. The library view gets empty as soon as I fill in the Save() expression into the import/export. Also it is empty if I fill in the whole expression by MrC. After re-entering import/export the text looks like this:

[Custom]=[/[/=save/(0,v_ntracks_/[AAA/]/)1/]/=1] [Custom]=[/[/=save/(0,v_duration_/[AAA/]/)1/]/=1] [Custom]=[/[/=save/(0,v_trating_/[AAA/]/)1/]/=1] [Custom]=[/[/=save/(math/(1 + load/(v_ntracks_/[AAA/]/)/), v_ntracks_/[AAA/]/)1/]/=1] [Custom]=[/[/=save/(math/(/[duration,0/] + load/(v_duration_/[AAA/]/)/),v_duration_/[AAA/]/)1/]/=1] [Custom]=[/[/=save/(math/(10 * /[_Rating /(track/)/] * /(/[duration,0/] // load/(v_duration_/[AAA/]/)/)/),v_trating_/[AAA/]_/[name/]/)1/]/=1] [Custom]=[/[/=save/(math/(load/(v_trating_/[AAA/]_/[name/]/) + load/(v_trating_/[AAA/]/)/),v_trating_/[AAA/]/)1/]/=1] ~sort=[Disc #]

Now I've tried another way:

In the album view I get an album duration in second format by entering: FormatNumber([Duration,2]0) <--AlbumDuration
Then I added an user-defined field: math([Rating] * FormatNumber([Duration,2],0)) <-- Rating*Duration
That gives me a weighted expression for each track.
Now to get an album average I only have to sum up Rating*Duration for all tracks of an album and divide it through AlbumDuration in Album view.

Is that possible? With GroupSummary() it doesn't work. It only shows [varies] for my user-defined field.

Hopefully someone can help.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: Tomplifier on October 29, 2023, 01:54:38 pm
Still not working with variables. Using Save-expression ends in empty views.

Are global variables still supported?


------

I guess I found the source of the problem. I am German and the variable expression language does not work, when language is set to German. I've changed it to Englisch and it works. Even if I switch back to German afterwards.
Title: Re: HOWTO: Generate album ratings using variables (+ track count)
Post by: mark_h on October 30, 2023, 01:59:22 am
Global variables are still supported.