INTERACT FORUM

Please login or register.

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

Author Topic: Need help with a User Created Library Field  (Read 7001 times)

Saucepan

  • Junior Woodchuck
  • **
  • Posts: 73
Need help with a User Created Library Field
« on: October 03, 2015, 12:21:30 pm »

Hi all,

I'm trying to create a Library Field that will do some math for me.

The field will be called Points. The math that needs to be done is simple: [Number Plays] + ([Rating] * [Duration]).

What function or expression do I use, and how do I make the field return that number?



Thank you for reading.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Need help with a User Created Library Field
« Reply #1 on: October 03, 2015, 12:42:58 pm »

I'm assuming you want the duration to be expressed in decimal minutes right?  So 3:30 would be 3.5 (three and a half minutes).  As a full example, a song that has 7 plays, a rating of 4, and a duration of 3:30 would be:

Points = 7 + (4 * 3.5) = 21

If that's correct, here's an expression to do it:

Code: [Select]
math([Number Plays] + ( [Rating] * [Duration,0]/60 ))
I would try it as an expression column first.  Get it working the way you want, then copy the expression and put it into your calculated field.

Good luck.

Brian.
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Need help with a User Created Library Field
« Reply #2 on: October 03, 2015, 12:45:23 pm »

math([number plays]+[rating]*[duration]-0)

if any of those fields are empty, the math will fail although the -0 at the end seems to sort a lot of those weird problems

if you get an issue, try

math(formatnumber([number plays])+formatnumber([rating])*formatnumber([duration]))

edit:  of course blgentry beat me to it, he's got a good point about the duration!  but don't forget the formatnumber and/or the -0 otherwise an empty field will ruin the expression
Logged

Saucepan

  • Junior Woodchuck
  • **
  • Posts: 73
Re: Need help with a User Created Library Field
« Reply #3 on: October 03, 2015, 02:11:43 pm »

Perfect.

I had figured out that it was the Math function while waiting for replies, but I couldn't get [duration] working properly until you guys chimed in. I appreciate this very much.

Logged

Saucepan

  • Junior Woodchuck
  • **
  • Posts: 73
Re: Need help with a User Created Library Field
« Reply #4 on: October 03, 2015, 02:20:47 pm »

I have a new problem...

Now that Points works right, it won't display the way I want it to.

In a Library View, if there's more than one value, Media Center displays Points as '[Varies]'.

How do I get MC to tally the points up and display the total?

Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Need help with a User Created Library Field
« Reply #5 on: October 03, 2015, 02:33:53 pm »

Ugh.  That's a really different problem.

What are you adding?  For example, do you mean adding all the track "points" over an album?

This requires variables, I can probably help but need really specific details on what you are trying to add up (and what is the "total")
Logged

Saucepan

  • Junior Woodchuck
  • **
  • Posts: 73
Re: Need help with a User Created Library Field
« Reply #6 on: October 03, 2015, 02:40:08 pm »

Points over an Album, yes.

I'd like it to display similar to how MC displays the total Number of Plays (i.e. '73 total plays').

I appreciate the help, and will definitely use it...but if it's a headache please don't bother!
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Need help with a User Created Library Field
« Reply #7 on: October 03, 2015, 02:48:01 pm »

ha ha sorry don't mean it like that.

do you want the sum of all the track points, or the average points per track per album?
Logged

Saucepan

  • Junior Woodchuck
  • **
  • Posts: 73
Re: Need help with a User Created Library Field
« Reply #8 on: October 03, 2015, 02:52:38 pm »

The sum.
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Need help with a User Created Library Field
« Reply #9 on: October 03, 2015, 02:59:19 pm »

...
Logged

Saucepan

  • Junior Woodchuck
  • **
  • Posts: 73
Re: Need help with a User Created Library Field
« Reply #10 on: October 03, 2015, 03:07:28 pm »

Followed your steps:

The Expression column just displays:

0

Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Need help with a User Created Library Field
« Reply #11 on: October 03, 2015, 03:27:47 pm »

smartlist import/export

Code: [Select]
[=save(0,var_number_of_tracks[album artist (auto)][album])1]=1 [=save(0,var_points_sum[album artist (auto)][album])1]=1 [=save(math(1+load(var_number_of_tracks[album artist (auto)][album])),var_number_of_tracks[album artist (auto)][album])1]=1 [=save(math([points]+load(var_points_sum[album artist (auto)][album])),var_points_sum[album artist (auto)][album])1]=1 [=save(math(load(var_points_sum[album artist (auto)][album]) / load(var_number_of_tracks[album artist (auto)][album])),var_album_points[album artist (auto)][album])1]=1 ~sort=[points]-d,[Media Type],[Album Artist (auto)],[Album],[Disc #],[Track #],[Name]
expression column

Code: [Select]
load(var_points_sum[album artist (auto)][album])
so far some basic testing seems to be working...

ok i've done some testing and hand calculations and it seems to work as long as all of the fields (number played, etc.) have real values in them..
Logged

Saucepan

  • Junior Woodchuck
  • **
  • Posts: 73
Re: Need help with a User Created Library Field
« Reply #12 on: October 03, 2015, 03:37:07 pm »

It's working for me as well. This is frickin' incredible.
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Need help with a User Created Library Field
« Reply #13 on: October 03, 2015, 04:00:04 pm »

Just for fun, the code also includes an average

So if you use

Code: [Select]
load(var_album_points[album artist (auto][album])
In the expression column it will give you the sum/# tracks for an album points average (well, it should ha ha variables are hard)

Just a note: the variables are global, so if you make a custom field that uses the load(...) codes, you can see them in normal views!  However when you import new tracks or increase play counts by listening, you must refresh the smartlist for the numbers to recalculate
Logged

Saucepan

  • Junior Woodchuck
  • **
  • Posts: 73
Re: Need help with a User Created Library Field
« Reply #14 on: October 03, 2015, 06:37:01 pm »

Many thanks again, this is super super good stuff (for me at least).

I tweaked the initial equation to fit my specific needs (Note: I took track duration out of the equation for now)

math((formatnumber([Rating]) * 20) + (formatnumber([number plays]) * 5))

Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Need help with a User Created Library Field
« Reply #15 on: October 03, 2015, 06:45:20 pm »

formatnumber([duration]/60))

That won't work.  formatnumber() doesn't do math, so the divide doesn't happen.  You want this instead:

formatnumber([Duration,0])/60

Brian.
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Need help with a User Created Library Field
« Reply #16 on: October 07, 2015, 10:18:44 pm »

so the OP asked for a revision, i think there's always value in making these things public in case someone else can learn from it

he wanted the totals to change by -75 if the rating was 2, and by -100 if the rating was 1

so, brief testing says that this works.  to the OP or anyone that tries it, let us know that it does what you want

Code: [Select]
ifelse(isequal([rating],2,2),math((formatnumber([rating])*20)-75+(formatnumber([number plays])*5)),isequal([rating],1,2),math((formatnumber([rating])*20)-100+(formatnumber([number plays])*5)),1,math((formatnumber([rating])*20)+(formatnumber([number plays])*5)))
Logged

Saucepan

  • Junior Woodchuck
  • **
  • Posts: 73
Re: Need help with a User Created Library Field
« Reply #17 on: October 08, 2015, 02:01:37 am »

First off, thank you to Ferday for basically making this happen. Absolutely amazing.

So...

Further tweaks to give weight to every rating and play-based-on-rating. It's getting pretty accurate now.

I simplified the code a bit.

Here's the breakdown:

5 star songs: get 100 points
Each play from a 5 star song: gets 10 extra points

4 star songs: get 80 points
Each play from a 4 star song: gets 7 extra points

3 star songs: get 30 points
Each play from a 3 star song: get 5 extra points

2 star songs: take away 75 points
Each play from a 2 star song: takes an extra 5 points away

1 star songs: take away 100 points
Each play from a 1 star song: takes an extra 10 points away

0 star songs: no points
Each play from a o star song: get 2 extra points

Here's the code, that will determine every tracks' Points:

Code: [Select]
ifelse(isequal([Rating],0,2),math(((formatnumber([number plays]) * 2))),isequal([Rating],4,2),math((80 + (formatnumber([number plays]) * 7))),isequal([Rating],5,2),math((100 + (formatnumber([number plays]) * 10))),isequal([Rating],3,2),math(30 + (formatnumber([number plays]) * 5)),isequal([Rating],2,2),math(-75 - (formatnumber([number plays]) * 5)),isequal([Rating],1,2),math(-100 - (formatnumber([number plays]) * 10)))
Additionally, you can create a Field called LP Points that will tally up the score of every track and display the Point total per LP!

Type this into the Expression Field while creating that: load(var_points_sum[album artist (auto)][album])

Why bother?
Because it takes album ratings a step further by being more specific with your ratings and plays. Using this will tell you what your best albums are, what's moving up and down in your library...and what you need to get rid of. All you need to do is rate your songs as you listen to them and then it will take shape.

KEEP THAT SMARTLIST OPEN IN AN EXTRA PANE. It needs to refresh to tally everything up. Very important.

Final Note:
I didn't realize how bad Black Sabbath's Vol. 4 was! And now I do. Holy hell.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9139
Re: Need help with a User Created Library Field
« Reply #18 on: October 14, 2015, 10:50:13 am »

Hi Marko thanks for replying.

---

What I'm trying to do, and I've been bugging ferday about this for a few days (poor guy!), is to try to create a variable that will take a field I've made, and assign an order to the values (1 for the highest value, 2 for the next highest and so on) that will change every time the list is refreshed.

It's basically a way to take my albums and say 'this one is #1, this one is #2, this one is #3 etc...Almost like a Seq for my records that changes every time I change a rating of a track.

The field is called LP Points. Thanks to ferday, who is amazing, I've got it working exactly how I want.

The last step of this whole thing is to list those values, top to bottom. I'm a huge fan of charts...

Any ideas you can add to this are extremely appreciated.

Global variables are not what you would call a forte of mine, so I am not really sure if that can be achieved that way or not. I tried a couple of ideas here, using MarkH's variable based [album rating] field, playing around with counter() and customdata(#) but ran into dead ends, brick walls and redundancy.


Pages: [1]   Go Up