INTERACT FORUM

Please login or register.

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

Author Topic: Problems sorting an expression field  (Read 2242 times)

Qythyx

  • Galactic Citizen
  • ****
  • Posts: 390
Problems sorting an expression field
« on: May 21, 2009, 04:35:47 am »

I have a complex expression field set in my library that I'm trying to sort on. I have a playlist that is specifically set to sort of this field and I also often add this playlist to Playing Now, and in both cases sorting is not working 100% correctly.

My expression is:
Math((100 + If(IsEqual(Field(Last Played,0),), 100, Math(Now() - Field(Last Played,0)))) / 100 / (10 + If(IsEqual([Number Plays],),0,[Number Plays])) * (If(IsEqual(Field(Rating, 0), ), 6, Field(Rating, 0)) * 15))

This expression equates (for my library) to numbers between just above 0 to around 5. The sorting kind of works, but not entirely. For example, I'll see number like 5.4xxxx sorted out of sequence with 5.3xxxx. In general sorting is correct, in that I don't see 4.xxx mixed in with the 5.xxx, but at the hight precisions they're mixed.

So, am I doing something wrong or is this a bug? Would it help if I made my numbers larger, e.g., multiplied the result by 1000, or something like that?
Logged

Qythyx

  • Galactic Citizen
  • ****
  • Posts: 390
Re: Problems sorting an expression field
« Reply #1 on: May 21, 2009, 10:14:27 pm »

Can anyone else repro this problem? It's actually a bit worse than I said, that is, the numbers are mixed up more than I thought.

Is there anything special that should be done when sorting on an expression field that equates to a number?
Logged

Qythyx

  • Galactic Citizen
  • ****
  • Posts: 390
Re: Problems sorting an expression field
« Reply #2 on: May 22, 2009, 01:14:38 am »

I tried multipyling my result by 1,000,000 to make the comparisons of intergers instead of high precision decimals and that seemed to work. So, this looks like a bug.

BTW, I didn't mention that this is on 169. Haven't tried 170 yet.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42323
  • Shoes gone again!
Re: Problems sorting an expression field
« Reply #3 on: May 22, 2009, 10:45:11 am »

End the expression with &DataType=[Number] to let Media Center know it should use numeric sorting.  You may need to delete and readd the column, due to a minor bug when changing only the data type.

Otherwise, it uses string sorting (which does have intelligent handling of integers, but not decimals).

Updated expression:
Code: [Select]
FormatNumber(Math((100 + If(IsEqual(Field(Last Played,0),), 100, Math(Now() - Field(Last Played,0)))) / 100 / (10 + If(IsEqual([Number Plays],),0,[Number Plays])) * (If(IsEqual(Field(Rating, 0), ), 6, Field(Rating, 0)) * 15)), 2)&DataType=[Number]
Logged
Matt Ashland, JRiver Media Center

Qythyx

  • Galactic Citizen
  • ****
  • Posts: 390
Re: Problems sorting an expression field
« Reply #4 on: May 22, 2009, 10:49:36 pm »

Ahh, that explains it. Thanks.
Logged

c1c9k72

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 332
  • So many worlds, so much to do, so little done...
Re: Problems sorting an expression field
« Reply #5 on: August 01, 2009, 08:01:28 am »

I'm having a similar problem with a calculated field.  I deleted the field, rebuilt it with the &DataType=[Number] included and it's still not sorting correctly.  It's doing all the internal mathematics correctly, and sorts properly if I manually click the field in the view, but if I refresh the smartlist, it reverts to the close-but-not-quite-right version of the sort.

Has anyone found a solution to this issue?
Logged
Pages: [1]   Go Up