INTERACT FORUM

Please login or register.

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

Author Topic: HOWTO: Generate album ratings using variables (+ track count)  (Read 47889 times)

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854

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

Logged

f.ammollo

  • Junior Woodchuck
  • **
  • Posts: 65
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #1 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
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #2 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.
Logged

justsomeguy

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 525
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #3 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.
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #4 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...
Logged

justsomeguy

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 525
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #5 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.
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #6 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.

Logged

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #7 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
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #8 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.
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #9 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]
 
                       
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #10 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.
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #11 on: October 29, 2012, 04:43:55 pm »

Thanks MrC does help.
Logged

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #12 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
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #13 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), ☆, )
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #14 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
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #15 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)), ,☆)
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #16 on: November 10, 2012, 08:58:20 am »

Thanks

Works great :)
Logged

toomanybarts

  • Regular Member
  • World Citizen
  • ***
  • Posts: 153
  • I might be a porcupine.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #17 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
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #18 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
Logged
The opinions I express represent my own folly.

toomanybarts

  • Regular Member
  • World Citizen
  • ***
  • Posts: 153
  • I might be a porcupine.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #19 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...?)
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #20 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.
Logged
The opinions I express represent my own folly.

toomanybarts

  • Regular Member
  • World Citizen
  • ***
  • Posts: 153
  • I might be a porcupine.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #21 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!!  ;) 
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #22 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
Logged
The opinions I express represent my own folly.

toomanybarts

  • Regular Member
  • World Citizen
  • ***
  • Posts: 153
  • I might be a porcupine.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #23 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?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #24 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

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
Logged
The opinions I express represent my own folly.

toomanybarts

  • Regular Member
  • World Citizen
  • ***
  • Posts: 153
  • I might be a porcupine.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #25 on: December 02, 2012, 09:02:45 pm »

GULP!
Logged

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #26 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
Logged

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #27 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?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #28 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]
Logged
The opinions I express represent my own folly.

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4580
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #29 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
Logged

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #30 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
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #31 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.
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #32 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
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #33 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...
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #34 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
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #35 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.
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #36 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...
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #37 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.
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #38 on: December 18, 2012, 11:31:51 pm »

Cool, no problem

Thanks again
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #39 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.
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #40 on: December 19, 2012, 06:04:25 am »

Thanks, no matter it is working well as is :)
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #41 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.
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #42 on: December 19, 2012, 03:45:22 pm »

Thanks MrC I'll try that out shortly
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #43 on: December 20, 2012, 04:00:37 pm »

Links to other threads about mischief (fun?) to be had with Global Variables:

* Generating Statistics
* Generating album track count
* Generating album ratings
* Highlighting playing album
Logged
The opinions I express represent my own folly.

Denti

  • Citizen of the Universe
  • *****
  • Posts: 593
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #44 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.
Logged

Denti

  • Citizen of the Universe
  • *****
  • Posts: 593
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #45 on: June 07, 2013, 11:54:43 am »

No one?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #46 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.
Logged
The opinions I express represent my own folly.

Denti

  • Citizen of the Universe
  • *****
  • Posts: 593
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #47 on: June 23, 2013, 08:20:14 am »

Thanks, but I could use some more specific, step-by-step guidance.

Thanks in advance.
Logged

Denti

  • Citizen of the Universe
  • *****
  • Posts: 593
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #48 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?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #49 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.
Logged
The opinions I express represent my own folly.
Pages: [1] 2   Go Up