INTERACT FORUM

Please login or register.

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

Author Topic: Calculate Field as number string?  (Read 2331 times)

wig

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 750
Calculate Field as number string?
« on: February 03, 2014, 10:50:11 am »

I'm trying to use a calculated field as a number string, so that I can apply modifiers like < and => to it in Smartlist rules.

However, I'm not having any success.

I've looked at this info:

http://wiki.jriver.com/index.php/Expression_Language#Data_Types
http://wiki.jriver.com/index.php/Expression_Language#Calculated_Fields_and_Search

I've tried using adding &datatype=[number] to the end of my expression, but JRiver still doesn't treat as a number. Specifically, it only give me string options when trying to apply modifiers during Smartlist creation. Entering it by hand in the import/export window isn't working for me, either.

Is there a way to do this in JRiver?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Calculate Field as number string?
« Reply #1 on: February 03, 2014, 12:15:02 pm »

The Search comparison operators don't have full numeric support this way.  Instead, you'll have to use the expression language comparison functions such as Compare(), IsEqual() or IsEmpty(), and use their Boolean 0 or 1 output.  For example, this fails:

  [=left(2.2, 1)]=<3

but this works:

   [=compare(left(2.2,1), <, 3)]=1

In a custom search query (e.g. [= ... ]), the only supported operator is =, and the operand must be a simple integer.
Logged
The opinions I express represent my own folly.

wig

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 750
Re: Calculate Field as number string?
« Reply #2 on: February 03, 2014, 01:26:11 pm »

Thanks, Mr. C. That's what I was afraid of.

I'm trying to use the album ratings in a smarlist, limiting the selections to albums equal or above a certain rating.

Any ideas on the best way to skin that cat?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Calculate Field as number string?
« Reply #3 on: February 03, 2014, 01:30:36 pm »

Is you Album Rating field type Integer, Decimal, or String?

Edit: And is this field a calculated field, relying on Set rules for file display setting of global variables, or just a static field you add album rating values too?
Logged
The opinions I express represent my own folly.

wig

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 750
Re: Calculate Field as number string?
« Reply #4 on: February 03, 2014, 01:48:35 pm »

Is you Album Rating field type Integer, Decimal, or String?

Edit: And is this field a calculated field, relying on Set rules for file display setting of global variables, or just a static field you add album rating values too?

It's a calculated field with global variables, courtesy of mark_h a few years back:

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

My calculated field: formatnumber(math( load(v_albumratingsum[album artist (auto)][album]) / load(v_count[album artist (auto)][album]) ),2)

My smartlist:  [Media Type]=[Audio] [=save(0,v_count[album artist (auto)][album])1]=1 [=save(0,v_albumratingsum[album artist (auto)][album])1]=1 -[=save(math([Chad Index (album)]+load(v_albumratingsum[album artist (auto)][album])),v_albumratingsum[album artist (auto)][album])1]=0 -[=save(math(1+load(v_count[album artist (auto)][album])),v_count[album artist (auto)][album])1]=0 ~sort=[Rating],[Media Type],[Album Artist (auto)],[Album],[Disc #],[Track #],[Name]
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Calculate Field as number string?
« Reply #5 on: February 03, 2014, 01:56:24 pm »

Edit: my thinking was backwards here, and wrong.  See my following post.

You'll have to assign the calculated values to a static field to perform this type of comparison.

The reason, you can't use that technique to calculate the values, and then use those values to continue to filter.  The calculations in Set rules for file display run like this:

For each file:
    evaluate Rule 1
    evaluate Rule 2
    ...
    evaluate Rule N

So your Rule N would be the filtering rule based on Album Rating.  But Album Rating hasn't been calculated yet because all tracks for an album have not been seen.    You'd need rules to run like this:

   Evaluate Rule 1 for each file
   Evaluate Rule 2 for each file
   ...
   Evaluate Rule N for each file

I suggested to Matt not too long ago that what's necessary is an additional calculation stage prior to filtering, but it requires a big change, and as a baby step the GroupSummary() and GroupCount() commands were born.  As you can understand, this area will probably not have progress for some time.
Logged
The opinions I express represent my own folly.

wig

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 750
Re: Calculate Field as number string?
« Reply #6 on: February 03, 2014, 02:16:53 pm »

You'll have to assign the calculated values to a static field to perform this type of comparison.

The reason, you can't use that technique to calculate the values, and then use those values to continue to filter.  The calculations in Set rules for file display run like this:

For each file:
    evaluate Rule 1
    evaluate Rule 2
    ...
    evaluate Rule N

So your Rule N would be the filtering rule based on Album Rating.  But Album Rating hasn't been calculated yet because all tracks for an album have not been seen.    You'd need rules to run like this:

   Evaluate Rule 1 for each file
   Evaluate Rule 2 for each file
   ...
   Evaluate Rule N for each file

I suggested to Matt not too long ago that what's necessary is an additional calculation stage prior to filtering, but it requires a big change, and as a baby step the GroupSummary() and GroupCount() commands were born.  As you can understand, this area will probably not have progress for some time.

Got it.

I'll just use the Move/ Copy Fields tool and copy them to a static field for now.

Again, thanks Again, MrC  :P



Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Calculate Field as number string?
« Reply #7 on: February 03, 2014, 02:38:25 pm »

Bah...

I gave you a load of horse pucky, completely contrary to what I already explained elsewhere.  Sorry about my brain skid, and I'll edit my post above.

Rules run the way I said you needed them to run, so all you need is another custom rule that performs the comparison.  For example, to get album ratings >= 4, add the following as the last custom rule using Import/Export in the smartlist editor:

   [=compare(formatnumber(math( load(v_albumratingsum[album artist (auto)][album]) / load(v_count[album artist (auto)][album]) ),2), >=, 4)]=1

Change the comparison operator (>=) and operand (4) to suit your needs.

Edit: I replaced the expression above with the calculated value instead of your albumratingssum value.
Logged
The opinions I express represent my own folly.

wig

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 750
Re: Calculate Field as number string?
« Reply #8 on: February 03, 2014, 04:14:03 pm »

Even better! Gonna try this out tonight!

(insert dancing banana smiley)
Logged

wig

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 750
Re: Calculate Field as number string?
« Reply #9 on: February 03, 2014, 09:13:46 pm »

Works great, MrC.

Sometimes you just want to hear tunes from your favorite albums.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Calculate Field as number string?
« Reply #10 on: February 03, 2014, 09:17:44 pm »

Excellent.  Thanks for the update.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up