Author Topic: Divide function for virtual tag - differing results help  (Read 594 times)

metrodub

  • Jr. Member
  • **
  • Posts: 31
I created a virtual tag to show the last time a track was played.  Using $NumberOfDays gets me, logically, the number of days the track was last played.  I wanted to show years for any tracks that were last played more than 365 days prior.  In the screenshot below, you can see that for some instances, the formula works, but for others it is still showing days vs years.  Any thoughts as to why?


boroda

  • Sr. Member
  • ****
  • Posts: 4653

metrodub

  • Jr. Member
  • **
  • Posts: 31
Sorry about that - see below.

Code
$If(<Last Played>="Unknown"," This is the First Time","  "{color: 124,198,247}$If($NumberOfDays($Now(),<Last Played>)>365," "$Round($Div($NumberOfDays($Now(),<Last Played>), 365),1)" "{color: default}"Years Ago on "<Last Played>,{color: 124,198,247}$NumberOfDays($Now(),<Last Played>)" "{color: default}" Days Ago on "<Last Played>))

hiccup

  • Sr. Member
  • ****
  • Posts: 7907
It looks like the problem is that the number of days (between now and last played) is treated as a string, and not as a number.
So e.g. 500 days will work, because 365 comes before 500, but it fails for 1100 days, since 1100 comes before 365.
So 1100 is considered to be 'less' than 365.

Perhaps there is an easy solution for that, but I couldn't find it.
(thinking about it, one solution could be to pad all day fields to 5 digits, so 365 becomes 00365 and 1100 becomes 01100. I'm not going to work that out though.)

So I concocted something taking a slightly different approach, I think it should work.

Code
$If(<Last Played>="Unknown",{contrast: 70}"not played yet",$If($NumberOfDays($Now(),<Last Played>)>365,$If($Round($Div($NumberOfDays($Now(),<Last Played>),365),0)>1,$Round($Div($NumberOfDays($Now(),<Last Played>),365),0)" years ago  "{contrast: 70}$Date(<Last Played>,MMM d yyyy  HH:mm),$Round($Div($NumberOfDays($Now(),<Last Played>),365),0)" year ago  "{contrast: 70}$Date(<Last Played>,MMM d yyyy  HH:mm)),$If($NumberOfDays($Now(),<Last Played>)>1,$Char(200b)$NumberOfDays($Now(),<Last Played>)" days ago  "{contrast: 70}$Date(<Last Played>,MMM d yyyy  HH:mm),$If($NumberOfDays($Now(),<Last Played>)=1,$Char(200b)$Char(200b)"yesterday  "{contrast: 70}$Date(<Last Played>,HH:mm),$Char(200b)$Char(200b)"today  "{contrast: 70}$Date(<Last Played>,HH:mm)))))
It's a lot longer, but that is mainly because the version you used would allow output such as '1 days', '1 years', '0 days.
I added some functionality so that it will say '1 day', '1 year' and 'today' instead.

P.S.
I took the liberty to change "This is the first time" to "not played yet", so you should change that if you prefer the first one.
Last Edit: January 09, 2023, 04:28:58 PM by hiccup

boroda

  • Sr. Member
  • ****
  • Posts: 4653
i've added 4 new functions to tag tools plugin to compare numbers (integer or fractional): $gt(num1, num2) - num1 is Greater Than num2, $lt(num1,num2) - num1 is Less Than num2, $ge(num1,num2) - num1 is Grater than or Equal to num2, $le(num1, num2) - num1 is Less than or Equal to num2

i'll upload new plugin version today later.

---

hiccup, your solution is very elegant anyway.
Last Edit: January 08, 2023, 09:02:30 PM by boroda

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34369
i have changed the string comparison to use a sort criteria that treats comparisons of digits as numeric values. I have updated the patch version

@boroda, please continue with your change

metrodub

  • Jr. Member
  • **
  • Posts: 31
Thanks everyone for the thorough explanation and new formula. 

Wasn't thinking about the possible string connection, as there were instances of 10+ years working, but it makes sense from a logic standpoint if viewed as a string.




hiccup

  • Sr. Member
  • ****
  • Posts: 7907
F.w.i.w, I have updated the version in my previous post.

- when sorting the 'last played' column it now orders the dates in a sensible manner
- improved formatting of the output  (even more elegant? ;-)
- it requires AT&RT plugin version 5.5.8407 or higher


boroda

  • Sr. Member
  • ****
  • Posts: 4653
new plugin version adds 6 functions to compare integer or fractional numbers:

$eq(num1,num2): compares 2 integer or fractional numbers. Determines if num1 is EQual to num2, e.g. $eq(1.0,1) returns "T"

$ne(num1,num2): determines if num1 is Not Equal to num2

$gt(num1,num2): determines if num1 is Greater Than num2

$lt(num1,num2): determines if num1 is Less Than to num2

$ge(num1,num2): determines if num1 is Greater than or Equal to to num2

$le(num1,num2): determines if num1 is Less than or Equal to num2


--------------

https://getmusicbee.com/addons/plugins/49/additional-tagging-amp-reporting-tools/

hiccup

  • Sr. Member
  • ****
  • Posts: 7907
Great.
(and I will be adding them to the cheatsheet)

P.S.
Is it intentional you are announcing this in this thread instead of in the AT&RT thread?
I don't think I need to use these new functions for this specific case? (well, not anymore, now that the latest MB patch fixed the originating issue)
Or do you think it could be an improvement on it?

edit
Hmm, maybe it would be useful in case I get bored a bit and bring myself to adding the concept of 'weeks' and 'months' to the formula too. (instead of only having  'days' and 'years')
Last Edit: January 09, 2023, 05:28:21 PM by hiccup

boroda

  • Sr. Member
  • ****
  • Posts: 4653
it's all up to you. i promised, i publish  :D

of course, i've added more detailed descriptions of new features of the latest plugin version on plugin topic. there just was some delay.

hiccup

  • Sr. Member
  • ****
  • Posts: 7907
i promised, i publish  :D
If I am correct you promised 4, and you delivered 6.
Some would call that overachieving  ;-)

boroda

  • Sr. Member
  • ****
  • Posts: 4653
it's because i've thought that mb won't parse correctly number comparison like $If(1.0=1,yes,no)