INTERACT FORUM

Please login or register.

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

Author Topic: Expression to make an "or" pane  (Read 1597 times)

laerm

  • Galactic Citizen
  • ****
  • Posts: 424
Expression to make an "or" pane
« on: December 12, 2010, 09:06:41 pm »

So I kinda slogged through the wiki pages on expressions and...wow. I didn't get it. Admittedly, I'm not super-savvy with this kind of work, but I did get a B in my SQL class so it's not totally foreign.  ;D

I am trying to make a pane that is is an OR of two fields (a pane that displays producer or remixer). I've tried some random stuff off the top of my head, some educated guesses, and some ideas based on what I read in the wiki, and I pretty much can't get anything to work. If anyone can answer what is probably an extremely simple problem, I'd appreciate it.

PS: I'm thankful the wiki pages are there, but I think they are missing some basic examples. It seems like they jump into the meat too quickly. I know, they're a wiki and anyone can edit -- I would if I knew what to put in!

Thanks!
Micah
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Re: Expression to make an "or" pane
« Reply #1 on: December 13, 2010, 01:53:55 am »

Format of OR is:

([producer]="your expression" or [remixer]="your expression")

Using the wizard you have to click to the left and right of the expression to invoke the OR, AND functionality.  The above text can by typed in manually in the Import / Export screen on the wizard.



Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8972
Re: Expression to make an "or" pane
« Reply #2 on: December 13, 2010, 02:08:50 am »

mark_h,
this is true, but I believe that laerm desires a pane that is populated with all examples of both [producer] and [remixer]. I tried wrapping expressions inside parenthesis with an "or" but it did not work for me here, as the expression engine worked the expressions, but also output the parenthesis and the "or" literally, so my test using [date] and [genre] returned a pane populated with things such as (or [genre]).

laerm,
How about an expression based pane using "ListBuild()":

Code: [Select]
listbuild(1,;,if(isempty([producer]),,[producer]),if(isempty([remixer]),,[remixer])&datatype=[list]
This should give you a pane populated with all existing producers and remixers with an "Unassigned" entry at the end for files that have neither. If you would like to have them grouped, you could add a prefix:

Code: [Select]
listbuild(1,;,if(isempty([producer]),,Producer - [producer]),if(isempty([remixer]),,Remixer - [remixer])&datatype=[list]
Or perhaps you might prefer them to be nested:

Code: [Select]
listbuild(1,;,if(isempty([producer]),,Producer\[producer]),if(isempty([remixer]),,Remixer\[remixer])&datatype=[list]
If these are completely not what you're looking for, just post back with more detail and we'll try to help.

That wiki page was hard work, and I agree that it will never be all things to all people. The best advice I can offer to anyone who finds themselves in your situation is to do exactly as you have done... post a question here. You should never need to wait too long for an answer, and it's probably the best way to get up running because you get a working example that you actually use, you see why it works, and it helps all the bits to fall into place in your head, with the end result hopefully being that in time, you develop a feel (for want of a better description) for the best way to achieve your goal and you'll be out of the starting blocks in no time at all.

Hope that helps,
regards,
marko.

laerm

  • Galactic Citizen
  • ****
  • Posts: 424
Re: Expression to make an "or" pane
« Reply #3 on: December 13, 2010, 09:09:39 am »

mark_h,
this is true, but I believe that laerm desires a pane that is populated with all examples of both [producer] and [remixer].

Ah, yes, exactly what I am trying to do. :)

Quote
How about an expression based pane using "ListBuild()":

Code: [Select]
listbuild(1,;,if(isempty([producer]),,[producer]),if(isempty([remixer]),,[remixer])&datatype=[list]

Aha! Perfect. :) I was unclear what listbuild was used for from the wiki. It seemed to me more appropriate for a calculated field...though maybe I do not understand the lingo well enough, and options seen in a pane are technically calculated fields...?

Quote
That wiki page was hard work, and I agree that it will never be all things to all people. The best advice I can offer to anyone who finds themselves in your situation is to do exactly as you have done... post a question here. You should never need to wait too long for an answer, and it's probably the best way to get up running because you get a working example that you actually use, you see why it works, and it helps all the bits to fall into place in your head, with the end result hopefully being that in time, you develop a feel (for want of a better description) for the best way to achieve your goal and you'll be out of the starting blocks in no time at all.

You are exactly right -- it is much better to see a working query that does what you want so you can pull it apart. It's how I taught myself javascript. :)

Now then, if I may ask a few questions related to the above query that works for me, so I can understand it a bit more...

Code: [Select]
listbuild([b]1[/b],;,if(isempty([producer]),,[producer]),if(isempty([remixer]),,[remixer])&datatype=[list]
The 1 is like a boolean bit set, meaning that it displays the query results, correct? A 0 would hide the query results?

Code: [Select]
listbuild(1,[b];[/b],if(isempty([producer]),,[producer]),if(isempty([remixer]),,[remixer])&datatype=[list]
No idea on the semicolon. I know it's the default delimiter, but what is it delimiting? The fields haven't been brought into the query yet...

Code: [Select]
listbuild(1,;,[b]if(isempty([producer]),,[producer])[/b],if(isempty([remixer]),,[remixer])&datatype=[list]
OK, this is the main section where I had trouble parsing the wiki. The isempty query seems to be the way a lot of queries get built. What confuses me about it is I think just a hang-up of mine on what it says. To me, it seems it is looking for empty fields. As in I read that part of the query and think it is saying "if [Producer] is empty, show [Producer]." Obviously that can't be what is happening, so I would love a little clarification there.

Thanks so very much for your help Marko, I know I have a lot of questions. :)

Micah

(edited to clean up the bbcode)
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8972
Re: Expression to make an "or" pane
« Reply #4 on: December 13, 2010, 11:33:42 am »

Evening Micah,

ListBuild mode switch.
Regarding the "1"... First a quote lifted from the wiki page:
Quote
ListBuild(Mode,Delimiter,Items,To,Include)

Mode: There are two different modes available:

    * 0: combine all values. NOTE: This mode should be avoided as there is no recorded practical use for it, and it's behaviour can be unpredictable.
    * 1: combine non-empty values

Delimiter: The character used here will be used as a delimiter between each of the specified list items. To be clear, the keywords field uses a semi-colon delimiter by default; if a list is built using keywords and genre, and the specified delimiter is a back slash, it will be used between the keywords and genre fields when joining them, the semi-colons in the keywords field would not be altered. For example, if [keywords] contained "these;are;keywords" and [genre] contained "Rock", and these two were joined using ListBuild with a "\" specified as the delimiter, the resulting data would be "These;are;keywords\Rock". The real beauty and power of this function can be released when expressions are nested into the ListBuild instructions. For example, "listbuild(1,\,replace([keywords],;,\),[genre]" would return the data "These\are\keywords\Rock"

Items To Include: This can be any number of specified text entries, expressions, or library fields, seperated by commas

When researching this expression I found that using a zero as a mode switch for "combine all values" produced some rather bizarre and unpredictable results and concluded that it had no known usage scenario and is best to be avoided. So, when using listbuild(), always set the mode to "1". What this should effectively do is, if you have both a producer and a remixer called "Bob", then "Bob" should only appear once in your pane.

The Delimiter.
The delimiter can be anything you need the resultant list to be delimited by, be it a single character, a semicolon in this case, or a whole word, or words.
Quote
No idea on the semicolon. I know it's the default delimiter, but what is it delimiting? The fields haven't been brought into the query yet...
After specifying your chosen delimiter, you then introduce each element that you wish to be included in your list separated by commas. The listbuild function at its simplest, will replace the commas with your specified delimiter and present the resultant data as your list.
Remember that there is no known limit to the number of elements you can include in your list, and that the elements could be any mix of plain text, library field or nested expression. (by "nested", I mean that the listbuild function is your main tool for building your list, but it is quite acceptable to use secondary expressions inside the listbuild function)

Nested "IsEmpty" queries.
if(isempty([producer]),,[producer])

When asking "If" questions, you provide the expression engine with instructions to perform if the result is positive, and further instructions to perform if the result is negative. The "if positive" instructions are always provided first. "isempty([producer])" is the core query, and this will return either a 1 or a 0. If we now wrap an "If" instruction around that, like so:
if(isempty([producer]),,[producer])
We can manipulate the expression output dependent upon the positive or negative result returned by "IsEmpty"
In this case, no instructions have been given for a positive result, and if [producer] is not empty, i.e., the result is negative, the instruction is to return the contents of the [producer] field.
If you changed the instructions like so:
if(isempty([producer]),Not Specified,[producer])
Then you would see a "Not Specified" value in your pane representing those files with no [producer] value assigned.

-marko

laerm

  • Galactic Citizen
  • ****
  • Posts: 424
Re: Expression to make an "or" pane
« Reply #5 on: December 14, 2010, 09:38:15 am »

Hi Marko, sorry about the slow reply...

The mode switch for listbuild is certainly odd, but at least it's a simple concept. The nested queries make sense, too. Your explanation helped a lot, thanks very much for your time.

My next task is to clean up the current way I use artist tags. Currently I have them as the main artist and, if necessary, "featuring [...]". I use this for guest vocalists or notable musicians guesting on the track, mostly (and then album artist is the artist that, well, is the album artist so the albums group and sort correctly in the panes). One of the main problems with that is that the tracks don't go to last.fm correctly because of my non-standard artist info. I am going to create a "featuring" library field and then put all of the "featuring" people in there, and then hide the artist column and replace it with a "performer" field/column that is calculated from the artist field plus the featuring artists. That way, artist field is still alive and well and will submit to last.fm properly.

Also I think I will change the panes... Currently I use album artist (auto), but I think I would like to replace that with another calculated pane, like my producer + remixer pane, but for artists and featured performers. Though how to keep compilations in that view (i.e. the "(multiple artists)" option)...?

Hm, I will work on all this later this week with my new knowledge and I will be back if I have more questions. Thanks again very much, Marko. :)

Micah
Logged
Pages: [1]   Go Up