INTERACT FORUM

Please login or register.

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

Author Topic: Need help with an Expression  (Read 2134 times)

GaryWW

  • World Citizen
  • ***
  • Posts: 151
Need help with an Expression
« on: September 01, 2014, 07:20:35 am »

I created a menu item that lists Media by Artist (see attachment for an example) using the following expression:

Code: [Select]
ifElse(!IsEmpty([HD Audio]),[HD Audio],
       !IsEmpty([Concert]),Concert,
       IsEqual([Media Type],Audio),CD,
       1,[Media Sub Type])

Nothing wrong with it but I would like to conditionally pluralize the title when the media contains more than 1 item (e.g. CDs instead of CD). How can that be done?
Logged

kensn

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1362
Re: Need help with an Expression
« Reply #1 on: September 12, 2014, 09:22:12 pm »

I have a Custom Library Field that calculates the number of albums per artist. This field is called "#Album"

I then use is the expression to display the following:

Code: [Select]
[#Album, 1] if(compare([#Album, 1], >, 1), Albums, Album)
This will generate the plural if needed as in "6 Albums" or "1 Album"

Ken
Logged
If(IsEmpty([Coffee Cup]), Coffee, Drink)

GaryWW

  • World Citizen
  • ***
  • Posts: 151
Re: Need help with an Expression
« Reply #2 on: September 13, 2014, 08:07:29 am »

Thanks Ken.

How do you populate the "#Album" field?

Gary
Logged

kensn

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1362
Re: Need help with an Expression
« Reply #3 on: September 13, 2014, 08:43:40 am »

I was afraid you were going to ask that. ;D It is a bit in depth.

Custom Library Field:

Name: #Album
Display: #Album
Display Plural: #Albums
Flags: Audio
Calculated Data (Expression): load(v_numalbums_[Artist])

This will load a saved variable from a math expression at display time.

In theaterview I have a Secondary Roller called Audio, and a Library Item call Albums, and a few Library Items under albums(All Albums, His Res, HD Surround, Album Series, Boxsets, Multiple Artist...). Under "Set rules for file display"  for Albums I have the following:

Rule 1)Media Type - Is - Audio
Rule 2)Custom -
Code: [Select]
[=1save(0,v_numalbums_[artist])]=1 (this loads a zero for album count)
Rule 3)Custom -
Code: [Select]
[=1(compare([track #].[disc #], <=, 1.1),save(math(compare([track #].[disc #], <=, 1.1) + load(v_numalbums_[artist])), v_numalbums_[artist]))]=1 (This will load the number of albums based on disc number and track number. It allows each album of a multi disc set to be counted as well as single discs.)

In the Library Item All Albums nested under the secondary roller Albums In the Details part where you set what you want to display I have:

[Artist] (with the grouping checked with a Grouping size of 1)

Expression: (Expression to group by) [Artist] and (Expression to display:) (2 lines)
[Artist,1]
[#Album, 1] if(compare([#Album, 1], >, 1), Albums, Album)

and in "Set rules for file display" I Have: Album Type - is - Single Artist complete


This will give you

Pink Floyd
7 Albums

Please see this post more more background... http://yabb.jriver.com/interact/index.php?topic=85166.0

Ken
Logged
If(IsEmpty([Coffee Cup]), Coffee, Drink)

GaryWW

  • World Citizen
  • ***
  • Posts: 151
Re: Need help with an Expression
« Reply #4 on: September 14, 2014, 07:58:35 am »

Nice, thanks.  :)

The key concept seems to be in using expressions in custom rules and how to load values into a field. A bit in depth? Yes, I'd agree.

It may not be the exact solution for my problem but I think you have put me on the right trail.
Logged

kensn

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1362
Re: Need help with an Expression
« Reply #5 on: September 14, 2014, 11:27:40 am »

So if your above code is used for Expression to group by, put this code in Expression to display.

Code: [Select]
ifelse(!IsEmpty([HD Audio, 1]), if(Compare(groupcount(), >,1), HD Audios, HD Audio), !IsEmpty([Concert, 1]), if(Compare(groupcount(), >,1), Concerts, Concert),, IsEqual([Media Type), Audio, if(Compare(groupcount(), >,1), CDs, CD),1,[Media Sub Type, 1])
I did some testing and it seems to work... Or help you down that trail ;). I made some custom fields to match yours, but not all media types were in my view when testing.

Ken
Logged
If(IsEmpty([Coffee Cup]), Coffee, Drink)

GaryWW

  • World Citizen
  • ***
  • Posts: 151
Re: Need help with an Expression
« Reply #6 on: September 18, 2014, 10:13:22 am »

Must use both fields! Got it. Thanks Ken.  ;D
Logged

Arindelle

  • Citizen of the Universe
  • *****
  • Posts: 2772
Re: Need help with an Expression
« Reply #7 on: September 26, 2014, 03:54:10 am »

Nice one Ken!! BUT you blew it, the cat's out of the bag  ;D

euh until Mr. C gets back, now I know who to bug about some expression help using listcombine( ) and maybe some regex  8)

Logged
Pages: [1]   Go Up