INTERACT FORUM

Please login or register.

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

Author Topic: Expression Help  (Read 2367 times)

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Expression Help
« on: January 10, 2012, 06:35:29 pm »

I have a pane that has the following expression,

Replace(•Replace([#Description], ; , •), •, ;if(isempty([#Description]),!No Description Applied,[#Description])\)&datatype=[list]

[#Description] is a semi colon delimited list...

Some files have more than one description. So the reason for this it to make my description pane where every unique entry has a top level nest. If the file has more than one description it will appear under both...

for example

My pane would look like below where stuff that is underlined is the top level..

Description 1
• Description 1
• Description 2
Description 2
• Description 1
• Description 2

Is it possible to filter out descriptions on the lower nest where the description is the same as the top nest so I would get

Description 1
• Description 2
Description 2
• Description 1

Thanks

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help
« Reply #1 on: January 10, 2012, 08:26:04 pm »

Not generally.

The reason - your expression is simply tacking on the original list at the place where a list separator exists, along with a backslash to designate the sub-list.  In essence, this is just duplicating the list under each item.  But the expression doesn't know anything about each item in the list.

To accomplish what you want, you'd need a way to grab each item in the list.  You might think to use listitem(), but you'd have to know how many times to use listitem(), and you don't know that in advance and your code would be hardcoded and very clumsy.

What you really need is an iterator function, which performs a sub-expression on each item in a list.  And that doesn't exist.

By the way, you don't need to perform the double replacement.  This works the same:

If(isempty([#Description]),
  !No Description Applied,
  replace([#Description];, ;, \[#Description];))&datatype=[list]
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: Expression Help
« Reply #2 on: January 11, 2012, 02:23:41 am »

Thanks MrC,

Worth a try anyway.

Iterator?? Maybe in the future??

Quote
By the way, you don't need to perform the double replacement.  This works the same:

If(isempty([#Description]),
  !No Description Applied,
  replace([#Description];, ;, \[#Description];))&datatype=
    Thanks for the refinement, some of my views are heavily clad in expression panes, making some of them take their fair share of time to load.. Does heavy accumulation of inefficient expressions slow down mc?

    Tell me I use a similar expression for my Genre/Styles pane..

    Replace(•Replace([Styles], ; , •), •, ;[Genre]\)&datatype=
      Does the same apply here, even though I am using two fields?

      Thanks
    [/list]
    Logged

    MrC

    • Citizen of the Universe
    • *****
    • Posts: 10462
    • Your life is short. Give me your money.
    Re: Expression Help
    « Reply #3 on: January 11, 2012, 07:03:56 am »

    Thanks for the refinement, some of my views are heavily clad in expression panes, making some of them take their fair share of time to load.. Does heavy accumulation of inefficient expressions slow down mc?

    The more complex the expression, the heavier the load on MC when generating and updating a view, so simpler when possible will be snappier.

    Quote from: brian0001
    Tell me I use a similar expression for my Genre/Styles pane..

    Replace(•Replace([Styles], ; , •), •, ;[Genre]\)&datatype=[list]

    Does the same apply here, even though I am using two fields?

    Yup, same thing.  We discussed this here.  Here's how to think of it.  You have a string value in a list field, for example, the literal sequence of characters:

       a;b;c

    Setting the datatype to list simply causes MC to break this string at the semicolons, and use each item as an individual value:

       a
       b
       c

    To nest this same list under another value in a pane, such as Genre, it would be sufficient to simply append the field and a backslash
     
      [Genre]\

    to the front of each item.  But there is no direct way to do this, so instead, to get the desired outcome, we can replace the semicolons in the original list

       a;b;c

    with ;[Genre]\

       a;[Genre]\b;[Genre]\c

    But notice this missed the first item "a".  To solve this, we want to initially append a single ; to the front of the list:

       ;a;b;c

    Now, the transformation via Replace would result in

       ;[Genre]\a;[Genre]\b;[Genre]\c

    The final simplified expression is:

       Replace(;[Styles], ;, ;[Genre]\)&datatype=[list]

    where we appended the initial semicolon to the value of [Styles].
    Logged
    The opinions I express represent my own folly.

    locust

    • Citizen of the Universe
    • *****
    • Posts: 699
    Re: Expression Help
    « Reply #4 on: January 11, 2012, 09:08:21 am »

    Thanks MrC, I am quite slow when it come to expressions but at least I get there in the end :)

    What would you say is the most useful function for Regex?? It is probably the only expression I haven't dabbled in yet.. Looks quite confusing on the wiki never mind thinking of what I could put it to use for..

    Thanks
    Logged

    locust

    • Citizen of the Universe
    • *****
    • Posts: 699
    Re: Expression Help
    « Reply #5 on: January 11, 2012, 09:44:23 am »

    MrC could you do me one more favour please? I have one view pane that is all artists. Because I have a lot of electronic music, there are a lot of featured artists and remixers.

    This was one my first endeavours with expressions so I suspect it can be cleaned up a lot and am uneasy to mess with it because it originally took me so long to create..

    It uses the expression below for my pane
    [#Calculate]&datatype=[list]

    [#Calculate]
    =listbuild(1,;,[#List Album Artists & Artists],[#List Supporting & Remixers])&datatype=[list]

    [#List Album Artists & Artists]
    =listcombine([Album Artist],[Artist],\,;)&datatype=[list]

    [#List Supporting & Remixers]
    =listcombine([Supporting Artist],[Remixer],\,;)&datatype=[list]

    Thanks MrC

    POST EDITED
    Logged

    MrC

    • Citizen of the Universe
    • *****
    • Posts: 10462
    • Your life is short. Give me your money.
    Re: Expression Help
    « Reply #6 on: January 11, 2012, 12:00:32 pm »

    What would you say is the most useful function for Regex?? It is probably the only expression I haven't dabbled in yet.. Looks quite confusing on the wiki never mind thinking of what I could put it to use for..

    Use it whenever you need to grab values from somewhere, when those values vary, but follow some detectible pattern.  Some examples:

      - pulling components from a date in a filename
      - pulling series or episode numbers from a Name
      - rearranging or stripping portions of a string

    The key is recognizing that there are patterns that can be identified (and to add a fancy word, "deterministically").

    When you can perform the same operation easily with a simpler function such as Left(), use it.  But once you start getting into problems where you need, say, the leftmost N characters, where N varies based upon being followed by a digit, use Regex().

    Work through the wiki examples from the top when you're ready, using an expression column, or using some of the available regular expression helper apps that allow you to explore how they work.
    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 #7 on: January 11, 2012, 12:08:21 pm »

    MrC could you do me one more favour please? I have one view pane that is all artists. Because I have a lot of electronic music, there are a lot of featured artists and remixers.

    Can you update you post, placing your expressions in a [code] [/code] block.  The word [list] is getting interpreted by the forum software here, and it has botched the expressions.  You'll have to also remove the extra [/list] at the end of the post that the forum software added.

    If you care to know how I got [list] into the text above, use [nobbc]  [/nobbc] around special forum "BB Codes" such as [list] to disable their special meaning.
    Logged
    The opinions I express represent my own folly.

    locust

    • Citizen of the Universe
    • *****
    • Posts: 699
    Re: Expression Help
    « Reply #8 on: January 11, 2012, 11:59:19 pm »

    Done :)
    Logged

    MrC

    • Citizen of the Universe
    • *****
    • Posts: 10462
    • Your life is short. Give me your money.
    Re: Expression Help
    « Reply #9 on: January 12, 2012, 08:19:12 pm »

    I don't see anything that could be optimized here.  Since you're assigning these to fields, I believe they get calculated once, and their values reused later.  In other words, until something referenced value changes, I don't believe the values are re-computed with each use.
    Logged
    The opinions I express represent my own folly.

    locust

    • Citizen of the Universe
    • *****
    • Posts: 699
    Re: Expression Help
    « Reply #10 on: January 12, 2012, 08:33:29 pm »

    Thanks MrC, that's reflief.. At least it won't slow my library much
    Logged
    Pages: [1]   Go Up