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

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 #50 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.
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 #51 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!
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 #52 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 #]

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

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 #55 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.
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 #56 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.
Logged

Denti

  • Citizen of the Universe
  • *****
  • Posts: 593
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #57 on: June 25, 2013, 09:40:47 pm »

Yes, I had the AAA set up wrong. Let me report back in a minute...
Logged

Denti

  • Citizen of the Universe
  • *****
  • Posts: 593
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #58 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.
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 #59 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.
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 #60 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!
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 #61 on: June 25, 2013, 10:00:49 pm »

Good job!
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 #62 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?
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 #63 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.
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 #64 on: June 25, 2013, 10:24:54 pm »

Ok, will get to this tomorrow. Thanks for the help!
Logged

Denti

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

Denti

  • Citizen of the Universe
  • *****
  • Posts: 593
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #68 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!
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 #69 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
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 #70 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
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 #71 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.
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 #72 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. 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
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 #73 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?
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 #74 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?
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 #75 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
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 #76 on: July 14, 2013, 01:32:16 am »

Yep that's it..
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 #77 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.
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 #78 on: July 14, 2013, 02:18:20 am »

Thanks MrC, I'll give it a bash
Logged

locust

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

Logged

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #80 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...
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 #81 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.
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 #82 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.
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 #83 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.
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 #84 on: July 17, 2013, 06:49:05 am »

Oh I remember that, anyway thanks for the help :)

Logged

locust

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

the.call

  • Recent member
  • *
  • Posts: 10
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #86 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.
Logged
Live is eternal - at least until NOW !

Leben währt ewig - zumindest bis JETZT !

Tomplifier

  • Recent member
  • *
  • Posts: 8
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #87 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.
Logged

Tomplifier

  • Recent member
  • *
  • Posts: 8
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #88 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.
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Re: HOWTO: Generate album ratings using variables (+ track count)
« Reply #89 on: October 30, 2023, 01:59:22 am »

Global variables are still supported. 
Logged
Pages: 1 [2]   Go Up