INTERACT FORUM

Please login or register.

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

Author Topic: Math expression  (Read 9735 times)

morrison

  • Galactic Citizen
  • ****
  • Posts: 335
Math expression
« on: June 08, 2010, 02:57:24 pm »

Please help

I create custom calculated field with this expression - Math([Number Plays] + [Skip Count]) and receive strange result. If one of the numbers is zero, the sum is zero.  I think this is wrong result. What could be wrong?

Thanks
Logged

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4560
Re: Math expression
« Reply #1 on: June 08, 2010, 02:59:51 pm »

my first reaction is to try
Math([Number Plays,0] + [Skip Count,0])
the ,0 gives the true values.

 :)
gab
Logged

morrison

  • Galactic Citizen
  • ****
  • Posts: 335
Re: Math expression
« Reply #2 on: June 08, 2010, 03:22:45 pm »

But 5 + 0 also 0, and 0 + 3 also 0. And with you expression too. Its wrong   ::)

Thanks
Logged

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4560
Re: Math expression
« Reply #3 on: June 08, 2010, 03:38:32 pm »

But 5 + 0 also 0, and 0 + 3 also 0. And with you expression too. Its wrong   ::)

Thanks
yes...  :( i was testing what i said in the mean time.. things do change.  :-\

i actually thought this gives the nicest result.
Quote
if(isempty([Number Plays]),if(isempty([skip count]),0,[skip count]),if(isempty([Skip Count]),[number plays],math([skip count]+[number plays])

but maybe i overlooked something or could be a bit simpler..

 :)
gab
Logged

Lasse_Lus

  • Citizen of the Universe
  • *****
  • Posts: 999
Re: Math expression
« Reply #4 on: June 08, 2010, 03:39:30 pm »

Math([Number Plays]+[Skip Count]-0)

should work..

you can't add the number zero to MC integer fields, it becomes null :(
Logged
MT5FR

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4560
Re: Math expression
« Reply #5 on: June 08, 2010, 03:42:36 pm »

Math([Number Plays]+[Skip Count]-0)

should work..

you can't add the number zero to MC integer fields, it becomes null :(

 ;D
looks like this is simpler.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 41788
  • Shoes gone again!
Re: Math expression
« Reply #6 on: June 08, 2010, 04:51:56 pm »

I can't reproduce this.

I added an expression column:
Math([Number Plays] + 0)

It works fine.  Any other clues?
Logged
Matt Ashland, JRiver Media Center

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4560
Re: Math expression
« Reply #7 on: June 08, 2010, 04:58:46 pm »

matt, try Math([Number Plays] + [skip count])
or with the ,0 you will see. i guess you did skip some songs..
i only had some skip counts that gave me 0 when using only [skip count,0] in a expression the rest was empty, and that is where it goes wrong.

 :)
gab
Logged

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4560
Re: Math expression
« Reply #8 on: June 08, 2010, 05:08:58 pm »

Math([Number Plays]+[Skip Count]-0)
it is really intriguing the difference this -0 makes.  8)

have to remember that

 :)
gab
Logged

Lasse_Lus

  • Citizen of the Universe
  • *****
  • Posts: 999
Re: Math expression
« Reply #9 on: June 08, 2010, 05:16:40 pm »

have to remember that


try to add a zero value to a integer field and you remember "15-null=null" "15-0=15"  ;)
Logged
MT5FR

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 41788
  • Shoes gone again!
Re: Math expression
« Reply #10 on: June 08, 2010, 05:36:05 pm »

matt, try Math([Number Plays] + [skip count])
or with the ,0 you will see. i guess you did skip some songs..
i only had some skip counts that gave me 0 when using only [skip count,0] in a expression the rest was empty, and that is where it goes wrong.

 :)
gab

Thanks.  I can reproduce it.  It's a little tricky.  

Numeric fields can return empty strings if they're blank or zero (we don't tightly differentiate zero / empty cases due to intentionally loose typing in the database engine).

The operator precedence gives evaluation like this:

Start with:
Math([Number Plays] + [Skip Count])

Evaluate pieces inside function:
Math(4 + )

Evaluate function:
0 (because math parser is confused)

The math parser doesn't understand '4 +'

To make sure you're feeding valid math to the math parser, use this instead:
Math(FormatNumber([Number Plays]) + FormatNumber([Skip Count]))
Logged
Matt Ashland, JRiver Media Center

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4560
Re: Math expression
« Reply #11 on: June 08, 2010, 05:37:59 pm »


try to add a zero value to a integer field and you remember "15-null=null" "15-0=15"  ;)
yep..  :) i seem to remember that, in my days, adding ,0 would have gone past this problem. but then again im not sure what is worse my long or my short term memory.
and the most intereting part is
Math([Number Plays]+[Skip Count]-0)
15+null=null
15+null-0=15

 ;D
gab
Logged

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4560
Re: Math expression
« Reply #12 on: June 08, 2010, 05:44:19 pm »

Math(FormatNumber([Number Plays]) + FormatNumber([Skip Count]))

that makes sense matt. and a good solution. and i think its not only integers. had a problem with decimals where my plug putted a 0 in some places. had some problems with the average, just putted 0.00001 instead without a problem. the format number trick should work just as good.

 :)
gab
Logged

gappie

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 4560
Re: Math expression
« Reply #13 on: June 08, 2010, 06:37:04 pm »

Thanks.  I can reproduce it.  It's a little tricky.  

Numeric fields can return empty strings if they're blank or zero (we don't tightly differentiate zero / empty cases due to intentionally loose typing in the database engine).

The operator precedence gives evaluation like this:

Start with:
Math([Number Plays] + [Skip Count])

Evaluate pieces inside function:
Math(4 + )

Evaluate function:
0 (because math parser is confused)

The math parser doesn't understand '4 +'

To make sure you're feeding valid math to the math parser, use this instead:
Math(FormatNumber([Number Plays]) + FormatNumber([Skip Count]))

matt. would it not be better if the math parser would not get confused about empty and 0 values. im not expecting from mc to be some kind of excell or spss, but since 0 is a very valid value, and it seems funny to put formatnumber around everything, could it not be that the parser would assume the formatnumber part automatically?
and maybe that could also be the same when doing the averages under thumbs (maybe they do nowadays, but they didnt last time i checked a while ago).

 :)
gab
Logged

morrison

  • Galactic Citizen
  • ****
  • Posts: 335
Re: Math expression
« Reply #14 on: June 09, 2010, 04:34:51 am »

Thank your very much for three of the decision (where I could not find not one)

This funny freedom of interpretation base fields ) I think - there needed revision (unlock edit or allow to completely hide default fields to remove the constraints derived from apple, and these little bugs) fields configuration in the DB.

Thanks again for the solution
Logged

Lasse_Lus

  • Citizen of the Universe
  • *****
  • Posts: 999
Re: Math expression
« Reply #15 on: June 09, 2010, 05:34:15 am »

0 is a very valid value,

..indeed it is...i would really like to be able to add 0 to integer db fields..i guess the calculated fields is the workaround  :)
Logged
MT5FR

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: Math expression
« Reply #16 on: June 09, 2010, 05:50:40 am »

I too would prefer it if MC could distinguish 0 from null (empty). Searching for songs/albums with no replay gain is confusing since MC reports songs/albums with a replay gain value of 0 as having no replay gain applied. (I think, however, it has become a little less confusing since in earlier versions MC reported songs/album with the set offset replay gain value - 6 in my case - as having no replay gain applied, 6 = null, empty.)
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Math expression
« Reply #17 on: November 21, 2011, 12:36:03 pm »

Old topic, I just read.

Having to place FormatNumber() around all usages of integer fields seems excessive.

Would it not be possible to add a new raw mode to fields, such as 2, which means to convert the empty string to 0 automatically?  eg: [Number Plays,2]

Then, user instructions for usage inside Math() can be to always use the 2 mode for fields, thus avoiding the additional functions required to FormatNumber() for each field.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up