INTERACT FORUM

Please login or register.

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

Author Topic: MC Expression language in a Library Field  (Read 2027 times)

Z0001

  • Citizen of the Universe
  • *****
  • Posts: 541
MC Expression language in a Library Field
« on: July 27, 2012, 08:02:35 am »

Hi

I am using this expression in a library field to tag video files as Watched, Watching or Not Watched:

If(Compare(Math([Bookmark]/1000/[Duration,0]),>,0.95),1,Watched,If(compare(Math([Bookmark]/1000/[Duration,0]),>,0.05),1,Watching,Not Watched))

it returns the value 0, even though I can clearly see the [Bookmark] values are partway through the files.

I used other threads to write this - not sure what the 0 does in [Duration,0] does it change the units from to seconds from minutes?

I found the Compare(...) and Isequal(...) seem similar in function - am i missing something?

Appreciate any help on how to get the filed to show Watched, Watching or Not Watched.
Z
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MC Expression language in a Library Field
« Reply #1 on: July 27, 2012, 11:43:44 am »

Try this (copy/paste into the expression editor).  We can refine as necessary.  Ask if you want the expression explained.

IfElse(
  Compare(Math([Bookmark] / 1000 / [Duration,0]), >, 0.95),
     Watched,
  Compare(Math([Bookmark] / 1000 / [Duration,0]), >, 0.05),
     Watching,
  1,
     Not Watched
)

Compare() was implemented recently and works on numeric values; IsEqual has been around for a while and works against strings and numbers.

See also:

  http://wiki.jriver.com/index.php/Media_Center_expression_language
Logged
The opinions I express represent my own folly.

Z0001

  • Citizen of the Universe
  • *****
  • Posts: 541
Re: MC Expression language in a Library Field
« Reply #2 on: July 27, 2012, 06:09:02 pm »

Thanks MrC- I can see the late night error I made!  Your expression seems to be working I'll have a review of several files. Not sure I get the logic of the syntax - can you explain please so I can learn for next time!

As I read it the Compare(...) returns 1 or 0 - does MC treat this 1 or 0 as "true" and "false" for the purposes of the If/IfElse logic?

What is the IfElse comparing that 1 or 0 to in order to know whether to return Watched or move to the next nested If test in the IfElse?  And then what is the 1 for before the ,Not Watched?  Is it simply a statement that says "true", so that the IfElse returns Nit Watched?


Many thanks!
Logged

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: MC Expression language in a Library Field
« Reply #3 on: July 27, 2012, 06:12:45 pm »

I am using this expression in a library field to tag video files as Watched, Watching or Not Watched...

Using nested If()'s, the expression should be...

If(Compare(Math([Bookmark] / 1000 / [Duration,0]),>,0.95), Watched, If(Compare(Math([Bookmark] / 1000 / [Duration,0]),>,0.05), Watching, Not Watched))

The extra '1' parameters in your If()'s are incorrect, and (I'm not sure why, but it seems) operators in Math() need to be separated by spaces. MrC, can you clarify?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MC Expression language in a Library Field
« Reply #4 on: July 27, 2012, 09:07:18 pm »

In the MC expression language, 0 is FALSE and non-0 (e.g. 1) is TRUE.

The syntax of IfElse() is

   condition1, outpu1,
   condition2, output2,
   ...
   conditionN, outputN

The final 1 as conditionN will always evaluate is TRUE (because 1 is non-0), so this gives you a final ELSE clause.

The Compare() in this expression turns out to be unnecessary, as Math() can do all the work:

IfElse(
  Math(above([Bookmark] / 1000 / [Duration,0], 0.95)),
     Watched,
  Math(above([Bookmark] / 1000 / [Duration,0], 0.05)),
     Watching,
  1,
     Not Watched
)

or to use on a single line:

   IfElse(Math(above([Bookmark] / 1000 / [Duration,0], 0.95)), Watched, Math(above([Bookmark] / 1000 / [Duration,0], 0.05)), Watching, 1, Not Watched)

or using rick.ca's suggested method:

   If(Math(above([Bookmark] / 1000 / [Duration,0], 0.95)), Watched, if(Math(above([Bookmark] / 1000 / [Duration,0], 0.05)), Watching, Not Watched))

rick.ca - the expression inside Math() is passed to a Windows library function which does the actual work.  Since that function allows commas, parens, and forward slashes, MC has to peek inside the expression to not trip over these MC-reserved tokens.  But it looks like when a field is on the right of a division character (/), MC misses this case:

   Math(100/[duration,0])

fails, but all of these work:

   Math(100 / [duration,0])
   Math(100//[duration,0])
   Math([duration,0]/100)
Logged
The opinions I express represent my own folly.

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: MC Expression language in a Library Field
« Reply #5 on: July 27, 2012, 10:17:56 pm »

Quote
rick.ca - the expression inside Math() is passed to Windows library function which does the actual work.

Thanks for the explanation. I'm not sure I can tolerate the inconsistency. I may have to use Math(100*pow([duration,0],-1)). ;)
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42441
  • Shoes gone again!
Re: MC Expression language in a Library Field
« Reply #6 on: July 27, 2012, 10:39:00 pm »

rick.ca - the expression inside Math() is passed to a Windows library function which does the actual work.  Since that function allows commas, parens, and forward slashes, MC has to peek inside the expression to not trip over these MC-reserved tokens.  But it looks like when a field is on the right of a division character (/), MC misses this case:

   Math(100/[duration,0])

fails, but all of these work:

   Math(100 / [duration,0])
   Math(100//[duration,0])
   Math([duration,0]/100)

It's actually our own math parser, but we do use special token handling when parsing the math function out of the expression.  It looks like you've found something we should try to handle better.  It's tricky that the escape character for expressions happens to be how you divide in a math expression :(
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: MC Expression language in a Library Field
« Reply #7 on: July 27, 2012, 10:45:27 pm »

Oh, my mistake.  When I updated the Math() portion of the Wiki, I'd used some MS Technet documentation to discover which functions were implemented, and how they worked.  So maybe there are some more goodies I've yet to discover.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up