INTERACT FORUM

More => Old Versions => Media Center 15 (Development Ended) => Topic started by: morrison on June 08, 2010, 02:57:24 pm

Title: Math expression
Post by: morrison 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
Title: Re: Math expression
Post by: gappie 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
Title: Re: Math expression
Post by: morrison 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
Title: Re: Math expression
Post by: gappie 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
Title: Re: Math expression
Post by: Lasse_Lus 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 :(
Title: Re: Math expression
Post by: gappie 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.
Title: Re: Math expression
Post by: Matt 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?
Title: Re: Math expression
Post by: gappie 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
Title: Re: Math expression
Post by: gappie 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
Title: Re: Math expression
Post by: Lasse_Lus 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"  ;)
Title: Re: Math expression
Post by: Matt 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]))
Title: Re: Math expression
Post by: gappie 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
Title: Re: Math expression
Post by: gappie 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
Title: Re: Math expression
Post by: gappie 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
Title: Re: Math expression
Post by: morrison 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
Title: Re: Math expression
Post by: Lasse_Lus 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  :)
Title: Re: Math expression
Post by: vagskal 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.)
Title: Re: Math expression
Post by: MrC 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.