INTERACT FORUM

Please login or register.

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

Author Topic: New expression language functions  (Read 3240 times)

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42442
  • Shoes gone again!
New expression language functions
« on: September 28, 2011, 09:55:16 am »

I'm working on a list of expression language improvements, and am petitioning for new functions that would be useful.

A few on my list:

Compare(...)
Compares numbers.
Example: Compare([Bitrate], >, 256)

IfElse(...)
Allows rewriting If(t1, r1, If(t2, r2, If(t3, r3))) as IfElse(t1, r1, t2, r2, t3, r3).
Example: IfElse(Compare([Bitrate], >, 256), High Bitrate, Compare([Bitrate], >, 128), Medium Bitrate, 1, Low Bitrate)

Orientation()
Outputs 'Landscape', 'Portrait', or 'Square' based on dimensions of an image.  More here: http://yabb.jriver.com/interact/index.php?topic=66557.0
Example: Orientation()

Please let me know if there are other any other functions that would make using expressions easier.  Marko, your votes count 10x since you wrote all the documentation!

Thanks.
Logged
Matt Ashland, JRiver Media Center

rjm

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 2699
Re: New expression language functions
« Reply #1 on: September 28, 2011, 10:53:39 am »

Some tools to help assess video quality. Sorting on these fields would provide some guidance on what video in a collection needs to be upgraded. I am not an expert here but I am thinking of things like:

Format()
Outputs Height divided by Width.

VideoQuality()
Outputs a video quality number normalized to the range 0..10 that is based on the product of Height x Width x Bitrate x codec efficiency.

Codec efficiency would be something like:
1 = vob, mpg
2 = Xvid, DivX
4 = h264
Logged

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: New expression language functions
« Reply #2 on: September 28, 2011, 01:13:56 pm »

What I'd really like is the ability to use any logical expression directly in the If() function. This expression would then be

If([Width]=[Height], Square, If([Width]<[Height], Portrait, Landscape).

That's more intuitive, easier to read, and has much broader application than this one application.

Is this not possible?
Logged

raym

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3583
Re: New expression language functions
« Reply #3 on: September 28, 2011, 09:00:38 pm »

Hi Matt, since you've asked, I'd really appreciate a change to TVInfo() which would allow me to show the EPG "Next:" program info (name, time and sub title) in Theater View's file info panel (Live TV view). Similar to what you get in the "Programs" OSD during live playback. Since it's already available there, I was thinking the TVInfo() function could be expanded to provide this?

I don't use the "Guide" but the "Live" TV view for Theater View is excellent for quickly deciding what to watch. It would be so much more useful though if at a glance you could also see what's showing next on each channel as you scroll through the list.

Thanks.

PS - I'm also pro anything that makes nested if statements easier to work with :-)
Logged
RKM Smart Home - www.rkmsmarthome.com.au
Z-Wave Home Automation

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9165
Re: New expression language functions
« Reply #4 on: September 29, 2011, 01:38:03 am »

Global match and substitution for the regex engine would be great. That link leads to a thorough explanation of the concept by MrC. With that, I could maintain a single nested keywords field, tracking all kinds of data, then make calculated fields that pull individual details out of there as required.

For example, my image library uses a single nested keywords field, with branches for People, Places, Events, Rating, Plants and Animals. for me, on the desktop it really is the simplest way to tag, and find things.

I personally think it also works exceptionally well in theater view, but the rest of the family don't agree, so I set about using the existing tools to attempt to extract the data from keywords, in order to set up specific views for them. I can't efficiently get People without global match and substitution. They way I get them at the moment works, by getting MC to check each file for up to 18 individual list items, causes an ugly pause, which means they think the button press hasn't worked, so they press a few more times, then MC finishes working out the people, and fires all the cached button presses, leaving them with no idea where they are, muttering to themselves and telling me it's sh*t and doesn't work right!!

That's just me. I know others have examples where they could use this too, but also accept that those that have gone on record are probably less than five, and MrC has alluded that this may be considerably more than just ticking a box to turn it on, so I appreciate that this is no small request, but it's still something I'd like to play with :)

Similar to RemoveCharacters(), I've often wished replace() could be used in a similar fashion, so, ReplaceCharacters([Name],//\?*:,_,0) would replace all occurrences of any of those characters with an underscore.

In a detailed category view, MC presents us with group specific information, such as number of tracks in an album, number of tracks by an artist, average ratings etc. etc.
I've often wished we could get at this information from the expression engine, but my head begins to hurt when I try to think how that could be done. I figured if it was feasible, we'd have it already!

Aside from that, I'm blissfully happy with the current status of expressions in MC. The stuff you can do with them, especially with things like listbuild() in theater view, never cease to make me smile. At $50 and 20Mb, MC really is a remarkable achievement.

-marko

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9165
Re: New expression language functions
« Reply #5 on: September 29, 2011, 01:40:06 am »

Quote
Marko, your votes count 10x since you wrote all the documentation!
Almost all... MrC kindly wrote up the Regex() entry :)

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: New expression language functions
« Reply #6 on: October 09, 2011, 11:05:43 am »

+1 of course for global match and substitution for the regex MC expression.

Another thing I found difficult with the current expression language was to find the lowest or highest value from a list or several fields. How about:

Min(...)
Max(...)


where ... can be a list type field or a list of values separated by , (or better yet ; )?
(I needed this to compare the different date fields associated with a music track; Date of release, Date of original release, Date of recording.)

I am sure Marko will let me know if this already is possible to do in an easy way.

An easy way to convert a string type field with a valid date according to the locale to a date type field would also be very useful. Now I enter date data in string type custom fields because I want to be able to use the full dates in other software. If I could import that data to a calculated date type custom field I could use the MC functions to handle the dates. How about:

FormatDate(..., convert)
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: New expression language functions
« Reply #7 on: November 23, 2011, 09:46:04 pm »

I've updated the Expressions wiki with Compare(), IfElse(), and Orientation().

@Vagskal, you can use Math() to get min() and max() functions (numeric).  See the Math() function docs in the Expressions Wiki.
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: New expression language functions
« Reply #8 on: November 24, 2011, 01:36:04 am »

@Vagskal, you can use Math() to get min() and max() functions (numeric).  See the Math() function docs in the Expressions Wiki.

Yes, I saw that. But I understand from the explanation that these functions only work with two values (x,y), not three or more (x,y,z...).

EDIT: Aha, perhaps I can nest the min() functions: math(min(z,min(x,y)))

EDIT 2: Nope. That did not work well with empty values.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: New expression language functions
« Reply #9 on: November 24, 2011, 11:24:55 am »

Yes, I saw that. But I understand from the explanation that these functions only work with two values (x,y), not three or more (x,y,z...).

EDIT: Aha, perhaps I can nest the min() functions: math(min(z,min(x,y)))

EDIT 2: Nope. That did not work well with empty values.

You can nest.   See this topic for a discussion about empty numeric values:

http://yabb.jriver.com/interact/index.php?topic=58110.0

For safety, use FormatNumber() around values that may expand to empty within Math().
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: New expression language functions
« Reply #10 on: November 24, 2011, 12:09:42 pm »

Thanks for the reply!

For safety, use FormatNumber() around values that may expand to empty within Math().

Just this did not work for me:
Code: [Select]
Math(Min(FormatNumber([Live Date]),Min(FormatNumber([Trackyear]),FormatNumber([Year]))))
As long as one of the three fields is empty 0 is returned.

I had to use a workaround to make it work:
Code: [Select]
Math(Min(FormatNumber([Live Date],0,9999),Min(FormatNumber([Trackyear],0,9999),FormatNumber([Year],0,9999))))
And now the expression is about as long as with If() statements...
Code: [Select]
If(IsEmpty([Live Date]),If(IsEmpty([Trackyear]),[Year],If(IsEqual([Trackyear],[Year],4),[Trackyear],[Year])),[Live Date])
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: New expression language functions
« Reply #11 on: November 24, 2011, 12:39:41 pm »

Yeah, understood.  Empty values become 0, and of course a zero is a minimum value for positive integers.  You could use your first format with a twist:

removeleft(Math(Min(-formatnumber([Live date]),
                       Min(-formatnumber([Trackyear]),
                             -formatnumber([Year])))),
               1)

:-)
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: New expression language functions
« Reply #12 on: November 24, 2011, 12:55:45 pm »

Yes, that would be an alternative workaround. Clever.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9165
Re: New expression language functions
« Reply #13 on: November 25, 2011, 03:32:51 am »

I've updated the Expressions wiki with Compare(), IfElse(), and Orientation().
Thanks for the updates.
It's going to be at least another week before I can get anywhere near this job, if you're still in the mood, here's the list of changes I had that needed doing...

Quote
4. NEW: Added an expression function FixSpacing(...) to convert camel case to normal spacing.  OneWord becomes One Word

13. Changed: Expressions support &DataType=[Integer] to specify that the output should be treated as an integer.

1. Changed: IsMissing(...) expression will handle special-case filenames like Blu-ray, DVD, etc. when used without a parameter like IsMissing().
When used like IsMissing(some value), the exact value specified be tested.

6. Changed: Removed MediaSubType(...) expression.  Instead, use the standard [Media Sub Type] field which is filled by Carnac.

3. NEW: Added expression function IfElse(...) for performing a sequence of tests.  Allows rewriting If(t1, r1, If(t2, r2, If(t3, r3))) as IfElse(t1, r1, t2, r2, t3, r3).

5. NEW: Added expression function TVInfo(Channel) to display the channel name for a television program.

Compare()

11. Changed: The expression function FileName(...) suppoprts an optional parameter for whether to include the extension (to get no extension: FileName(,0))

1. Faster: Expression language is faster when dealing with fields (as a result, it's no longer supported to nest functions inside the Field(...) function).

9. Changed: Expressions that work on filenames better handle portable install filenames like "(Install Drive):\1.mp3".

8. NEW: Expression language supports ! operator in a conditional (ie. If(!IsEqual([Artist], Abba), a, b))
I didn't have orientation() in the list, so good catch there, and I don't think mediasubtype() ever got written up, so no-one is going to miss that!!

-marko

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: New expression language functions
« Reply #14 on: November 25, 2011, 07:44:26 pm »

1. NEW: Added an expression function FixSpacing(...) to convert camel case to normal spacing.  OneWord becomes One Word

Done.

2. Changed: Expressions support &DataType=[Integer] to specify that the output should be treated as an integer.

Done.

3. Changed: IsMissing(...) expression will handle special-case filenames like Blu-ray, DVD, etc. when used without a parameter like IsMissing().
When used like IsMissing(some value), the exact value specified be tested.


Done.

4. Changed: Removed MediaSubType(...) expression.  Instead, use the standard [Media Sub Type] field which is filled by Carnac.

Nothing to do.

5. NEW: Added expression function IfElse(...) for performing a sequence of tests.  Allows rewriting If(t1, r1, If(t2, r2, If(t3, r3))) as IfElse(t1, r1, t2, r2, t3, r3).

Already Done.

6. NEW: Added expression function TVInfo(Channel) to display the channel name for a television program.

Done.

7. Compare()

Already Done.

8. Changed: The expression function FileName(...) suppoprts an optional parameter for whether to include the extension (to get no extension: FileName(,0))

Done. 
 - Moved Filename() into Other functions area
 - Corrected a couple copy/paste typos (filepath() used instead of filename())
 - Moved Counter() into "Functions that perform specific tasks" (was in Functions for filename and field manipulation).

1. Faster: Expression language is faster when dealing with fields (as a result, it's no longer supported to nest functions inside the Field(...) function).

Done.

9. Changed: Expressions that work on filenames better handle portable install filenames like "(Install Drive):\1.mp3".

10. NEW: Expression language supports ! operator in a conditional (ie. If(!IsEqual([Artist], Abba), a, b))

To be added after beta build containing change is promoted to MC17 board.

Questions
1. FixSpacing() - what are the available modes / meanings?
2. For item (9) above, where should this be documented?
Logged
The opinions I express represent my own folly.

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72541
  • Where did I put my teeth?
Re: New expression language functions
« Reply #15 on: November 25, 2011, 07:53:21 pm »

Thanks again!

The wiki should be OK again.
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1855
Re: New expression language functions
« Reply #16 on: November 26, 2011, 03:05:16 am »

One thing I'd like is Global Variables for use in expressions, as I previously requested here:

http://yabb.jriver.com/interact/index.php?topic=62019.0

Logged
Pages: [1]   Go Up