INTERACT FORUM

Please login or register.

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

Author Topic: Math in Expression Language  (Read 4893 times)

hit_ny

  • Citizen of the Universe
  • *****
  • Posts: 3310
  • nothing more to say...
Math in Expression Language
« on: March 13, 2009, 02:44:18 pm »

2. NEW: Added function Math(...) to expression language for evaluating mathematical formulas

Any instructions on how to use this ?
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8952
Math in Expression Language
« Reply #1 on: March 13, 2009, 03:01:43 pm »

Any instructions on how to use this ?
I've only had a quick play, but, using an empty string field in the tag window, the following work as expected:

=math(2+3)

=math(length([filename])-length([filename (name)]))

-marko.

hit_ny

  • Citizen of the Universe
  • *****
  • Posts: 3310
  • nothing more to say...
Math in Expression Language
« Reply #2 on: March 13, 2009, 03:09:55 pm »

Hmm...how does one calculate an average album rating given track ratings with it then ?

Are we running up against the 'can't-compare-values-across-files' limitation here  ?

If only there was a way to group by [Field]...
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8952
Math in Expression Language
« Reply #3 on: March 13, 2009, 03:12:53 pm »

I think so, yes.

hit_ny

  • Citizen of the Universe
  • *****
  • Posts: 3310
  • nothing more to say...
Re: Math in Expression Language
« Reply #4 on: March 16, 2009, 01:38:19 pm »

Did not strike me earlier but you can use this across files, provided its done manually. Select files, F2, type expression.

Now all thats required to know is which math functions are supported ?
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8952
Re: Math in Expression Language
« Reply #5 on: March 16, 2009, 01:48:17 pm »

using the method you describe will batch the process, but the expression will still only be applied to each single file in turn.

hit_ny

  • Citizen of the Universe
  • *****
  • Posts: 3310
  • nothing more to say...
Re: Math in Expression Language
« Reply #6 on: March 16, 2009, 02:14:16 pm »

ahhh  :'(
Logged

ChrisRainman

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 306
  • nothing more to say...
Re: Math in Expression Language
« Reply #7 on: March 16, 2009, 05:18:54 pm »

The new math function allows me to think about a feature I dreamt of for quite a long time but never thought you really would implement this.

I want to create a kind of dynamic "playback priority" based on a formula I now can start thinking of. As a result I should be able to create perfect smartlists which consider when songs were played last, how they are rated and how often they have been played.

The fields to take into considerations are
- Number plays
- Rating
- Last Played
- (Date Imported)
- Preference (which I use to distinguish between public rate and personal rate).

Out of these fields I want to create a calculated figure that indicates a kind of probability for a song to be played. So the top100 scores could be the songs to be played next. After playing, the field "playback priority" updates so that it takes some time to be played next. Of course, this should depend also on its rating.

So, I just tried out some formulas but found out that I cannot calculate with date fields. Why? How they are handled internally? They could not work like in Excel?
How can I calculate squares of values? The results with using the "^" symbol are strange! By the way: i created a formula and inserted the "²" (high two) which let MC crash.

Would be great if dates could be considered somehow in formulas.
Logged

ChrisRainman

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 306
  • nothing more to say...
Re: Math in Expression Language
« Reply #8 on: March 16, 2009, 05:29:45 pm »

One additional gap:

Divisions don't work properly:

[Rating] / 2 works fine
[Rating] / [Number Plays] always returns 0!
Logged

skeeterfood

  • Citizen of the Universe
  • *****
  • Posts: 779
  • We're all just food for the skeeters.
Re: Math in Expression Language
« Reply #9 on: March 16, 2009, 08:59:42 pm »

How can I calculate squares of values? The results with using the "^" symbol are strange! By the way: i created a formula and inserted the "²" (high two) which let MC crash.

I assumed squares would be like [Rating]**2 for Rating^2, but that always returns 0...  [Rating]*[Rating] works though.

-John
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8952
Re: Math in Expression Language
« Reply #10 on: March 17, 2009, 01:49:40 am »

The new math function allows me to think about a feature I dreamt of for quite a long time but never thought you really would implement this.

I want to create a kind of dynamic "playback priority" based on a formula I now can start thinking of. As a result I should be able to create perfect smartlists which consider when songs were played last, how they are rated and how often they have been played.

The fields to take into considerations are
- Number plays
- Rating
- Last Played
- (Date Imported)
- Preference (which I use to distinguish between public rate and personal rate).

Out of these fields I want to create a calculated figure that indicates a kind of probability for a song to be played. So the top100 scores could be the songs to be played next. After playing, the field "playback priority" updates so that it takes some time to be played next. Of course, this should depend also on its rating.
Fascinating idea! If you manage arrive at a working formula, would you mind sharing? I get theory, then my eyes kind of glaze over ;)

-marko.

Edit: I don't know if it helps or not, but...
Dates in MC are calculated using that 'number of seconds since some day in 1970' thing, and then converted into user friendly strings for our general consumption. When I needed to use dates in an expression used to output my granddaughter's age in any photo, I created a custom library field I called numbers... Using the template formatdate([date,0],yyyyMMdd) the field [numbers] returns a numerical value for the date, the higher the value, the more recent. Would that help?

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1852
Re: Math in Expression Language
« Reply #11 on: March 17, 2009, 03:43:45 am »

I want to create a kind of dynamic "playback priority" based on a formula I now can start thinking of. As a result I should be able to create perfect smartlists which consider when songs were played last, how they are rated and how often they have been played.

The fields to take into considerations are
- Number plays
- Rating
- Last Played
- (Date Imported)
- Preference (which I use to distinguish between public rate and personal rate).


I already do this, it just takes about 25 smartlists to pull everything together  ;D  For example, here is my rule for pulling in candidate tracks with a rating of 7:

[My Rating]=7 [Last Played]=>112d [Album Play Only]=[] [Never Play]=[] ~sort=[Last Played],[Number Plays] ~limit=-1,1,[genrefilterprog] ~limit=-1,3,[artist] ~limit=-1,1,[name] ~n=7 ~limit=-1,1,[album] ~sort=[Last Played],[Number Plays]

I have one such smartlist for all ratings 1-10, with successively lower rating rules pulling in less tracks, then for tracks imported over the past six months, one per month with slight adjustments again newer tracks feature more heavily.

The result is a smartlist that pulls in lots of tracks I like but filtered by their [number plays] and [last played] plus a lot of new imported stuff to keep things fresh.

I'll be looking at the Math stuff to see how I can improve this, but it already works very well.

Cheers,

Mark





Logged

ChrisRainman

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 306
  • nothing more to say...
Re: Math in Expression Language
« Reply #12 on: March 17, 2009, 04:00:08 pm »

Fascinating idea! If you manage arrive at a working formula, would you mind sharing? I get theory, then my eyes kind of glaze over ;)

Of course, I let you know about my great formula ;) The approach with formatdate is valuable as I can build a similar behaviour like in Excel. I created a first draft formula that is not yet perfect but a start.

In my opinion one major missing feature is the ability to perform divisions with variables. For now, I use a square function that has also its disadvantages. But you will see below.

I already do this, it just takes about 25 smartlists to pull everything together  ;D  For example, here is my rule for pulling in candidate tracks with a rating of 7:

[My Rating]=7 [Last Played]=>112d [Album Play Only]=[] [Never Play]=[] ~sort=[Last Played],[Number Plays] ~limit=-1,1,[genrefilterprog] ~limit=-1,3,[artist] ~limit=-1,1,[name] ~n=7 ~limit=-1,1,[album] ~sort=[Last Played],[Number Plays]

I had similar smartlists in the past. They work good, but once you've played a song you won't here it for a long time.With the math function it's possible to allow songs to be played again as long as they are rated good enough. I mean middle class songs I don't worry once heard that they don't pop-up again for a while. But the real good ones shall appear faster again.

So my first "draft" formula is as follows:

Field name: Playback Score - the higher, the sooner it will be played.

=IF(ISEQUAL([Last Played],never played,1),
  20000,
  Math(([Rating]*5*[Preference]-[Number Plays]*[Number Plays]/5)*0.1*
  (FormatDate(Now(),yyyy)*360   +FormatDate(Now(),MM)*30   +FormatDate(Now(),dd)       
  -(FormatDate([Last Played,0],yyyy,1)*360   +FormatDate([Last Played,0],M,1)*30   +FormatDate([Last Played,0],dd,1)))

As it is not perfect yet, don't look to close. In Excel I already created an advanced formula. As it requires divisions I needed a work-around.

The If-statement is necessary because otherwise where [Last Played] is never played I receive zero for the whole math statement. Of course, the IF-condition 1 with a fixed value of 20.000 is not proper. I would like to set a Math-function here but this doesn't work. Having two math-functions in an IF-statement fails (first time MC crashed, second time it returned zero.

In the math function I would like to compute a weighted sumproduct of rating and preference and devide this by [number plays]. Dividing by field values fails also. (What you see in my formula is a work-around which presently produces useful results but that will become worse when the number of plays increases).

In the FormatDate section of the formula I created a numeric day-based value for NOW and the Last Played date. By subtraction I receive the number of days as a number (in contrast to the 'elapsed' parameter in FormatDate). So depending on the time elapsed the playback score increases.

I hope that divisions will be made possible. Finally, if it would be possible to calculate average values of fields - then the whole thing could be made perfect.
Logged

ChrisRainman

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 306
  • nothing more to say...
Re: Math in Expression Language
« Reply #13 on: March 22, 2009, 08:29:30 am »

Are there plans to improve the math function? Presently, the division by field names fails. This would be a great addition if this worked!
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8952
Re: Math in Expression Language
« Reply #14 on: March 22, 2009, 08:44:17 am »

Are there plans to improve the math function? Presently, the division by field names fails. This would be a great addition if this worked!
What are you trying to do?
Using numbers works...

=math(600/15) = 40
=math(10/2) = 5

Where is division letting you down exactly?

-marko.

edit:
I think I may have it....
Using my example from above:
=math(length([filename])//length([filename (name)]))

Note that you need to escape the division operator with a preceding forward slash for the expression evaluator to acknowledge its presence.

ChrisRainman

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 306
  • nothing more to say...
Re: Math in Expression Language
« Reply #15 on: March 22, 2009, 11:22:26 am »

Note that you need to escape the division operator with a preceding forward slash for the expression evaluator to acknowledge its presence.

Thanks, that's what I needed!

So, there remains one thing: MC should be capable to handle divisions by zero:

Try =math(10/[Number plays]

If you have any song that has never been played MC crashes.

Addition: Also, it is not possible to handle to MATH-functions in an IF-statement.
Logged

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4566
Re: Math in Expression Language
« Reply #16 on: March 22, 2009, 11:51:55 am »

i think the problem with [number plays] is that it is not 0 but empty... if(isempty([number plays]),10,math(10//[number plays])) just like math(10//0).

 :)
gab
Logged

ChrisRainman

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 306
  • nothing more to say...
Re: Math in Expression Language
« Reply #17 on: March 22, 2009, 11:58:20 am »

Agreed!

But MC should not crash in case I forget to use an IF-statement.
Logged

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4566
Re: Math in Expression Language
« Reply #18 on: March 22, 2009, 12:05:59 pm »

Agreed!

But MC should not crash in case I forget to use an IF-statement.
agreed    ;)
of course

 :)
Logged

ChrisRainman

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 306
  • nothing more to say...
MC crashes with MATH function
« Reply #19 on: May 05, 2009, 04:49:09 pm »

1. The math function still causes MC crashing in certain cases:
Example: math(10/[Number plays]
Even if this can be avoided by saying if(isempty([number plays]),10,math(10//[number plays]))) => itshould not cause a crash

2. How can I extract roots or exponentiate with the math function?
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 41956
  • Shoes gone again!
Re: MC crashes with MATH function
« Reply #20 on: May 05, 2009, 04:59:52 pm »

1. The math function still causes MC crashing in certain cases:
Example: math(10/[Number plays]
Even if this can be avoided by saying if(isempty([number plays]),10,math(10//[number plays]))) => itshould not cause a crash

This will be fixed in a coming build.

It didn't like things with incomplete syntax like:
4 /
Logged
Matt Ashland, JRiver Media Center

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 41956
  • Shoes gone again!
Re: MC crashes with MATH function
« Reply #21 on: May 05, 2009, 05:20:49 pm »

2. How can I extract roots or exponentiate with the math function?

Powers are the pow(...) function.

For example:
pow(2, 3)

Or:
pow(8, 1 / 3)

(edited by Matt -- I misspoke with my first answer to this)
Logged
Matt Ashland, JRiver Media Center

c1c9k72

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 332
  • So many worlds, so much to do, so little done...
Re: Math in Expression Language
« Reply #22 on: June 01, 2009, 05:39:55 pm »

Now I can upgrade!  I've seriously needed this for years!  Thanks for the addition of addition.
Logged
Pages: [1]   Go Up