INTERACT FORUM

Please login or register.

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

Author Topic: Expression Help  (Read 2587 times)

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Expression Help
« on: November 17, 2012, 01:15:03 pm »

MrC (or someone else), please help!

I thought I had perfected my thumbnail text and group by expression. But today I found an error. I might be blind, tired or it was too long ago that I created the original expression.

This is the part of the expression that is supposed to show if an album is on certain top lists.
Code: [Select]
ifelse(isempty([RSM internt]),if(isempty([Virgin internt]),if(!isempty([1001 Albums]),/ /(<font color="FF0000">♥<//font>/),),/ /(/<i/>Virgin/ [Virgin internt]/<//i/>if(!isempty([1001 Albums]),/ <font color="FF0000">♥<//font>/),/))),isempty([Virgin internt]),if(!isempty([1001 Albums]),/ /(/<i/>RSM/ [RSM internt]/<//i/>/ <font color="FF0000">♥<//font>/),/ /(/<i/>RSM/ [RSM internt]/<//i/>/)),!isempty([1001 Albums),/ /(/<i/>RSM/ [RSM internt] • Virgin/ [Virgin internt]/<//i/>/ <font color="FF0000">♥<//font>/),1,/ /(/<i/>RSM/ [RSM internt] • Virgin/ [Virgin internt]/<//i/>/)))
The issue I discovered today is that I have some albums where [1001 Albums] is empty and both [RSM Internt] and  [Virgin Internt] have values, but a heart (representing a value in [1001 Albums]) is nevertheless displayed.

Any help would be appreciated since I seem unable to figure it out by myself.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help
« Reply #1 on: November 17, 2012, 02:03:57 pm »

You're missing a closing bracket on the last 1001 Albums.
There's an extra closing paren at the end of this expression, but I presume that's because this is from a larger expression.

ifelse(isempty([RSM internt]),if(isempty([Virgin internt]),if(!isempty([1001 Albums]),/ /(<font color="FF0000">♥<//font>/),),/ /(/<i/>Virgin/ [Virgin internt]/<//i/>if(!isempty([1001 Albums]),/ <font color="FF0000">♥<//font>/),/))),isempty([Virgin internt]),if(!isempty([1001 Albums]),/ /(/<i/>RSM/ [RSM internt]/<//i/>/ <font color="FF0000">♥<//font>/),/ /(/<i/>RSM/ [RSM internt]/<//i/>/)),!isempty([1001 Albums),/ /(/<i/>RSM/ [RSM internt] • Virgin/ [Virgin internt]/<//i/>/ <font color="FF0000">♥<//font>/),1,/ /(/<i/>RSM/ [RSM internt] • Virgin/ [Virgin internt]/<//i/>/)))

Some cleanups:

  * you don't need to escape < or >
  * you don't need to escape <space> chars when they are internal to a string (escape is only necessary when the can be confused with whitespace surrounding function parameters, which is ignored).
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help
« Reply #2 on: November 17, 2012, 02:20:11 pm »

Here's how I spotted it.

First, I replaced all /( and /) with { and } to make using my paren-matching editor find paren groups for me.
Next, I replaced your FF0000 values, with unique values, so that the output in a file expression column shows which clause was causing trouble.  This gave pseudo-line numbers.

I also replaced a couple of empty else claused If() statements with their dangling closing comma with Ifelse().  Dangling commas make parsing the expression even more difficult to my eyes.

I had to replace the ♥ character, as my editor didn't like it - I chose the word STAR.  Same idea for the • character.

I did some formatting to help my old eyes parse the expression.  That made it easier to...

Factor out some common expressions that were in both clauses of an If() or IfElse().

ifelse(
    isempty([RSM internt]),
        if(isempty([Virgin internt]),
            ifelse(!isempty([1001 Albums]),                                        / {<font color="FF0000">STAR<//font>}),
            / {<i>Virgin [Virgin internt]<//i>ifelse(!isempty([1001 Albums]),  / <font color="FF0001">STAR<//font>)}
          ),
    isempty([Virgin internt]),
        / {<i>RSM [RSM internt]<//i>/
           ifelse(!isempty([1001 Albums]), <font color="FF0002">STAR<//font>)},
    1,
         / {<i>RSM [RSM internt] BULLET Virgin [Virgin internt]<//i>/
              ifelse(!isempty([1001 Albums]),<font color="FF0004">STAR<//font>)}
)


Edit: Fixed the missing <i> values, which were being eaten by the forum software.
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: Expression Help
« Reply #3 on: November 18, 2012, 01:31:10 pm »

Many thanks, MrC!

You solved it already by spotting the missing end paren!

I used your elegant expression (but had to add a couple
Code: [Select]
<i> and move a couple / ). This is the entire expression, with an initial part that explains the extra paren at the end:
Code: [Select]
Clean(If(IsEmpty([Date]),Okänt år,/<b/>Left([Date],4)/<//b/>if(IsEqual(length([Date]),4,5),Right([Date],6),)) ifelse(isempty([RSM internt]),if(isempty([Virgin internt]),ifelse(!isempty([1001 Albums]),/ /(<font color="FF0000">♥<//font>/)),/ /(<i>Virgin [Virgin internt]<//i>ifelse(!isempty([1001 Albums]),/ <font color="FF0000">♥<//font>)/)),isempty([Virgin internt]),/ /(<i>RSM [RSM internt]<//i>ifelse(!isempty([1001 Albums]),/ <font color="FF0000">♥<//font>)/),1,/ /(<i>RSM [RSM internt] • Virgin [Virgin internt]<//i>ifelse(!isempty([1001 Albums]),/ <font color="FF0000">♥<//font>)/)))
The only issue I can see is that there seems to be a trailing extra space if there are values in both [RSM Internt] and [Virgin Internt], see the Miles Davis album and the Ray Charles album in the screen shot. Where can that extra space be?

EDIT: I see now why I had to add the
Code: [Select]
<i>. It was the forum software interpreting them. I put the expression in code in stead.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help
« Reply #4 on: November 18, 2012, 03:11:15 pm »

I'm not seeing the double spaces, but can reproduce if I add spaces to the end of the actual value stored in [Virgin internt].  Check that.

I fixed the <i> problem above.  I noticed the text getting italicized, and thought "Hey, that looks good", so left it, not realizing it would be copy/pasted!  Sorry.
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help
« Reply #5 on: November 18, 2012, 03:14:51 pm »

Ah, yes I see it now.

Remove the double forward slashes from the closing html tags, such as <//i>, setting them to </i>.  Do likewise for the bold and font close tags.

Edit: I see when all the tags are cleaned up, MC gets confused and isn't properly handing the HTML here.  I'll look more at it later tonight.


See my reply #8 below.
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: Expression Help
« Reply #6 on: November 18, 2012, 11:34:06 pm »

I'll look more at it later tonight.

Thanks for checking! Right now it is only a minor cosmetic issue, but I could not find anything wrong with the code.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help
« Reply #7 on: November 19, 2012, 02:20:36 pm »

Sorry, I didn't get much time to look at this last night - I made soup instead.

On of the problems with using a series of nest If() statements to build up non-empty string values is that the nesting grows exponentially with the number of values being tested for emptiness.  A better approach is to use the functions that have this testing built in, such as Listbuild() and the new Delimit().  Listbuild() is good for conditionally inserting delimiters between non-empty components, and the new Delimit() is good for adding leading and trailing delimiters to a non-empty component.  In both of these, the testing is done internally.

So, here's a better, more extensible solution:

Code: [Select]
listbuild(1, / ,
  FormatDate([Date,0],
     <b>Year<//b>ifelse(Compare(length([Date]),>,4),//MM//dd), Okänt år),
  Delimit(
     listbuild(1, / ,
       listbuild(1, / •/ ,
            Delimit([RSM internt],   <//i>, <i>RSM/ ),
            Delimit([Virgin internt], <//i>, <i>Virgin/ )),
       ifelse(!isempty([1001 Albums]), <font color="FF0000">♥<//font>)),
  /), /()
)

which:

  - uses Listbuild() to conditionally add a <space> between the Date output and the remaining text
  - uses FormatDate() to output the date in the desired format, including the bolding, and empty-date value output (Okänt år)
  - uses Listbuild() to add a <space> between the RSM/Virgin and ♥ output, conditionally
  - uses Listbuild() to add <space>•<space> between the RSM and Virgin output, conditionally
  - uses Delimit() to surround both the RSM and Virgin output with the HTML tags and leading text, and encapsulating parenthesis
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help
« Reply #8 on: November 19, 2012, 03:54:05 pm »

Regarding the phantom space, this seems to be a kerning/tracking affect with the HTML text engine.  You can see this here:



and can test it by creating some Thumbnail Text using:

  <i>abc [_a] 123<//i>/)

where _a is a user string field, and you modify its value.  Try alternating values of •, ., *, K, o, and watch as the inter-letter spacing changes.

I think what was happening when the double forward slash was omitted, as I suggested incorrectly above, italic mode remained enabled through the end of the line, and affected the kerning/tracking spacing.

Selecting the non-proportional font, such as Courier New italic, eliminates the change in spacing, and hence seems to support this theory.
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: Expression Help
« Reply #9 on: November 20, 2012, 12:23:02 pm »

Thanks again, MrC! I hope that your soup turned out well.

It was not at all my intention to ask you to rewrite the expression - it was for me more than enough that you spotted the ending paren that I had missed and could not see until you pointed it out. But since you have been so kind to take the trouble of optimizing the expression for me, I wonder if you could extend your kindness to post your last expression surrounded by CODE forum markers. I am not sure where the start bold and italic html codes "eaten up" by the forum software should go, and I am afraid I do not have much time to test right now.

If I interpret the image posted by you correctly there seems to be something wrong with the spacing when using html code in thumbnail text; a •, instead of a x, inside html code should not insert an extra penultimate space on the same line. This might be something that Matt and his clever team can fix...

It is of course just a matter of taste, but using Courier New italic is for me not an acceptable workaround. That font simply does not go very well together with the overall look and feel of MC, in my opinion. I rather live with the minor spacing issue.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help
« Reply #10 on: November 20, 2012, 01:06:39 pm »

Cheers.

Code posted in CODE blocks now, sorry.

Just for clarification, there's no extra <space> character being output.  Rather, its a function of how the HTML text engine is adjusting the intra-/inter-character spacing for proportional fonts.  I wasn't suggesting use of a monospace font, but was showing that the issue is just a weakness in the HTML text engine (and I'm not sure if there's anything JRiver can do about this), and perhaps the hinting in the font itself (I'm not so up to speed on fonts anymore).
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: Expression Help
« Reply #11 on: November 21, 2012, 09:56:32 am »

Thanks!

I think your new expression even fixed the spacing issue! See the screen shot where your new expression is on the last line.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help
« Reply #12 on: November 21, 2012, 10:03:37 am »

Great!

[note: the following is to guide others who might want to build such phrases w/out being hamstrung by an if/else structure.]

Adding yet another rating source is trivial now - just pop in a single new clause, such as:

    Delimit([Vagskal internt], <//i>, <i>Vagskal/ ),

and it's done.
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: Expression Help
« Reply #13 on: November 25, 2012, 12:11:46 pm »

This is strange.

I have one custom expression field called [Toppalbum alla formaterat exp] with this expression you taught me:
Code: [Select]
Delimit(listbuild(1,/ ,listbuild(1,/ <b>•<//b>/ ,Delimit([RSM internt],<//i>,<i>RSM/ ),Delimit([Virgin internt],<//i>,<i>Virgin/ ),Delimit([Esq. 75 INTERNT],<//i>,<i>Esq./ ),Delimit([NME 100 INTERNT],<//i>,<i>NME/ ),Delimit([NARM 200 INTERNT],<//i>,<i>NARM/ ),Delimit([VH1 100 INTERNT],<//i>,<i>VH1/ )),ifelse(!isempty([1001 Albums]),<font color="FF0000">♥<//font>)),/),/()
If I do:
Code: [Select]
ListCount([Toppalbum alla formaterat exp],/ <b>•<//b>/ )1 is returned if [1001 Albums] is not empty but all the other referenced fields are empty.
1 is returned if [1001 Albums] is not empty and 1 (one) of the other referenced fields is not empty.
If [1001 Albums] is not empty and two or more referenced fields are not empty, I get the number of the referenced fields, i.e. if [1001 Albums] is not empty and two other referenced fields are not empty, I get (only) 2.

I want to get the number of non empty referenced fields, including [1001 Albums], but this expression does not work:
Code: [Select]
If(IsEmpty([1001 Albums]),ListCount([Toppalbum alla formaterat exp],/ <b>•<//b>/ ),Math(ListCount([Toppalbum alla formaterat exp],/ <b>•<//b>/ )+1))
Help!

PS. MrC, in your last post I think there is one closing paren too many in your partial expression.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help
« Reply #14 on: November 25, 2012, 01:57:51 pm »

I corrected the statement above - it was copy/pasted from the last entry in the listbuild, so included it's closing paren.  Sorry.

The [1000 Albums] element confounds the list counting.  What you could do is normalize the list before counting, so that listcount() does the right thing.  You current have lists that look like:

   1: (_heart_)
   2: (A)
   3: (A • B)
   4: (A • B _heart_)

where _heart_ represents how your formatted [1001 Albums] appears.

Listcount() defaults to 1 for any non-null string, so case 1 and 2 are fine.  Case 3 is also a simple listcount().  But case 4 requires normalization, repacing the <space>_heart_ with a bullet and some stuff, turning it into:

   4: (A • B • stuff)

The distinction between case 1 and 4 is the space preceding the _heart_ string.  Once replaced, listcount() can be run correctly on all cases 1 - 4.

For example:

Code: [Select]
listcount(
   replace([Toppalbum alla formaterat exp], / <font color="FF0000">♥, / <b>•<//b>/ ),
   / <b>•<//b>/ )
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: Expression Help
« Reply #15 on: November 26, 2012, 02:32:02 am »

Thanks! That worked!

The only issue is that 0 is output when [Toppalbum alla formaterat exp] is empty, i.e. thumbnail text with the suggested expression actually contains "0". I thought that to MC 0 was just null/empty. No biggie. I just test if the field is empty before applying the ListCount().
Logged
Pages: [1]   Go Up