Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Natural Language Timestamps (Read 26771 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Natural Language Timestamps

Reply #25
It works, problem is not with your code (or my modification of it) but with the way foo_custominfo adds system time information. It doesn't pad the entries with leading zero's (instead of 2 am being 02 it's just written as 2) which messes up the display of your code.

One final question, I have just updated the old code I had to the newest one you have posted in the first post, how would I change the code to remove the Never if the song hasn't been played?

Natural Language Timestamps

Reply #26
It works, problem is not with your code (or my modification of it) but with the way foo_custominfo adds system time information. It doesn't pad the entries with leading zero's (instead of 2 am being 02 it's just written as 2) which messes up the display of your code.

One final question, I have just updated the old code I had to the newest one you have posted in the first post, how would I change the code to remove the Never if the song hasn't been played?


Guess you search for Never in the code and remove the word, or do some stringcompare for the output, if its never say nothing and otherwise output the time. Sorry, i'm too lazy to do this atm and i'm also not very good at foobar scripting and coding at all

Natural Language Timestamps

Reply #27
I believe you cannot use this in trackinfo, only in columns_ui because trackinfo does not support "%_system_xxxx%... correct me if i'm worong...


It is possible to use this script in trackinfo panel, but you also need foo_cwb_hooks to implement date/time variables, and some tuning.

Natural Language Timestamps

Reply #28
I plan to rewrite the code to use foo_cwb_hooks, and will post it on the first page when I finish.

Natural Language Timestamps

Reply #29
Would be interesting to compare results.

Natural Language Timestamps

Reply #30
Really nice script! I'm impressed

Natural Language Timestamps

Reply #31


the never played tracks are grayed out and the today played ones are marked blue.

it's This replayed by $rgb(110,170,210)This
and Never replayed by $get(standard_color_low)Never

i dont know what's standard_color_low - it's a global value from navigator suite theme for columns_ui.

Natural Language Timestamps

Reply #32
@topdownjimmy:

I wanted to add your script to my SCP config, so I've made a quick mod to make it works with foo_cwb_hooks. Here is the mod in case someone else needs it. I hope it does not bother you..

Code: [Select]
removed


Edit: see code bellow instead.

Natural Language Timestamps

Reply #33
It seems to me you could severely abridge the dayssince calculation by using $cwb_datediff.  Here's the code I'm currently using for these timestamps:

Code: [Select]
/////////////////////////////////////////
// NATURAL LANGUAGE TIMESTAMPS
// by topdownjimmy
// v0.3.c - Dec 4, 2006
/////////////////////////////////////////

$puts(year,$left(%cwb_systemdate%,4))
$puts(month,$substr(%cwb_systemdate%,6,7))
$puts(day,$substr(%cwb_systemdate%,9,10))

$puts(dayssince,$cwb_datediff(%cwb_systemdate%,%last_played%))

// correct "dayssince" to consider early AM to be an extension of previous day
// $puts(dayssince,$sub($get(dayssince),$if($and($greater(7,%_system_hour%),$greater($substr(%last_played%,12,13),6)),1,0)))
$if($and($greater(%_system_hour%,6),$greater(7,$substr(%last_played%,12,13))),$puts(dayssince,$add($get(dayssince),1)),)

// calculate day of week
$puts(calcdayofweek,$add(1,$mod($add($substr(%last_played%,3,4),$div($substr(%last_played%,3,4),4),$select($substr(%last_played%,6,7),6,2,2,5,0,3,5,1,4,6,2,4),$substr(%last_played%,9,10)),7)))

// correct day of week to consider early AM to be an extension of previous day
$puts(calcdayofweek,$sub($get(calcdayofweek),$ifgreater(7,$substr(%last_played%,12,13),1,0)))
$if($strcmp($get(calcdayofweek),0),$puts(calcdayofweek,7),)

// calculate period of day (night, morning, etc.)
$puts(dayperiod,$select($add(1,$substr(%last_played%,12,13)),Night,Night,Night,Night,Night,Night,Night,Morning,Morning,Morning,Morning,Morning,Afternoon
,Afternoon,Afternoon,Afternoon,Afternoon,Evening,Evening,Evening,Evening,Night,Night,Night))

// calculate natural language timestamp
$if(%last_played%,$puts(nat_lang_stamp,$ifgreater($get(dayssince),0,$ifgreater($get(dayssince),1,$ifgreater($get(dayssince),6,$if($and($greater($get(dayssince),21),$not($strcmp(%_system_month%,$substr(%last_played%,6,7)))),$if($not($strcmp(%_system_year%,$substr(%last_played%,1,4))),$select($substr(%last_played%,6,7),January,February,March,April,May,June,July,August,September,October,November,December)' '$substr(%last_played%,1,4),$ifgreater(2,$sub(%_system_month%,$substr(%last_played%,6,7)),'Last Month',$select($substr(%last_played%,6,7),January,February,March,April,May,June,July,August,September,October,November,December))),$ifgreater($div($add($get(dayssince),4),7),1,$div($add($get(dayssince),4),7)' Weeks Ago',Last Week)),$select($get(calcdayofweek),Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday)' '$get(dayperiod)),$if($strcmp($get(dayperiod),Night),Last,Yesterday)' '$get(dayperiod)),$if($strcmp($get(dayperiod),Night),Tonight,This $get(dayperiod)))),$puts(nat_lang_stamp,Never))

$set_global(nat_lang_stamp,$get(nat_lang_stamp))
$set_global(dayssince,$get(dayssince))

/////////////////////////////////////////

Also, rather than up it to version 0.4, I just made it 0.3.c, since it uses the same methodology, but with the cwb hooks.

I planned to clean this up a little more before posting it, but I've been slacking.

Also, I'm not too happy with the name I can up with for these.  Something more accurate might be "Relative Timestamps" or something.

Natural Language Timestamps

Reply #34
It seems to me you could severely abridge the dayssince calculation by using $cwb_datediff.  Here's the code I'm currently using for these timestamps:

Code: [Select]
/////////////////////////////////////////
// NATURAL LANGUAGE TIMESTAMPS
// by topdownjimmy
// v0.3.c - Dec 4, 2006
/////////////////////////////////////////

$puts(year,$left(%cwb_systemdate%,4))
$puts(month,$substr(%cwb_systemdate%,6,7))
$puts(day,$substr(%cwb_systemdate%,9,10))

$puts(dayssince,$cwb_datediff(%cwb_systemdate%,%last_played%))

// correct "dayssince" to consider early AM to be an extension of previous day
// $puts(dayssince,$sub($get(dayssince),$if($and($greater(7,%_system_hour%),$greater($substr(%last_played%,12,13),6)),1,0)))
$if($and($greater(%_system_hour%,6),$greater(7,$substr(%last_played%,12,13))),$puts(dayssince,$add($get(dayssince),1)),)

// calculate day of week
$puts(calcdayofweek,$add(1,$mod($add($substr(%last_played%,3,4),$div($substr(%last_played%,3,4),4),$select($substr(%last_played%,6,7),6,2,2,5,0,3,5,1,4,6,2,4),$substr(%last_played%,9,10)),7)))

// correct day of week to consider early AM to be an extension of previous day
$puts(calcdayofweek,$sub($get(calcdayofweek),$ifgreater(7,$substr(%last_played%,12,13),1,0)))
$if($strcmp($get(calcdayofweek),0),$puts(calcdayofweek,7),)

// calculate period of day (night, morning, etc.)
$puts(dayperiod,$select($add(1,$substr(%last_played%,12,13)),Night,Night,Night,Night,Night,Night,Night,Morning,Morning,Morning,Morning,Morning,Afternoon
,Afternoon,Afternoon,Afternoon,Afternoon,Evening,Evening,Evening,Evening,Night,Night,Night))

// calculate natural language timestamp
$if(%last_played%,$puts(nat_lang_stamp,$ifgreater($get(dayssince),0,$ifgreater($get(dayssince),1,$ifgreater($get(dayssince),6,$if($and($greater($get(dayssince),21),$not($strcmp(%_system_month%,$substr(%last_played%,6,7)))),$if($not($strcmp(%_system_year%,$substr(%last_played%,1,4))),$select($substr(%last_played%,6,7),January,February,March,April,May,June,July,August,September,October,November,December)' '$substr(%last_played%,1,4),$ifgreater(2,$sub(%_system_month%,$substr(%last_played%,6,7)),'Last Month',$select($substr(%last_played%,6,7),January,February,March,April,May,June,July,August,September,October,November,December))),$ifgreater($div($add($get(dayssince),4),7),1,$div($add($get(dayssince),4),7)' Weeks Ago',Last Week)),$select($get(calcdayofweek),Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday)' '$get(dayperiod)),$if($strcmp($get(dayperiod),Night),Last,Yesterday)' '$get(dayperiod)),$if($strcmp($get(dayperiod),Night),Tonight,This $get(dayperiod)))),$puts(nat_lang_stamp,Never))

$set_global(nat_lang_stamp,$get(nat_lang_stamp))
$set_global(dayssince,$get(dayssince))

/////////////////////////////////////////

Also, rather than up it to version 0.4, I just made it 0.3.c, since it uses the same methodology, but with the cwb hooks.

I planned to clean this up a little more before posting it, but I've been slacking.

Also, I'm not too happy with the name I can up with for these.  Something more accurate might be "Relative Timestamps" or something.


um... sorry if i ask a stupid question
where should i put youre script
im a newbie

Natural Language Timestamps

Reply #35
Put it in the "Variables" tab under the "Globals" tab in Columns UI's Playlist view preferences, then create a column with
$get_global(rel_timestamp)
for the "Display."

You'll need the cwb_hooks component.

And here's some fixed-up code (the one you quoted had major problems).  I changed the name of it to "Relative Timestamps" and the global variable to rel_timestamp, because it seems to make a lot more sense to me.

Code: [Select]
/////////////////////////////////////////
// RELATIVE TIMESTAMPS
// formerly known as natural language timestamps
// by topdownjimmy - v0.5.c - May 6, 2007
/////////////////////////////////////////

// calculate days since last play
$puts(dayssince,$cwb_datediff(%cwb_systemdate%,%last_played%))

// correct "dayssince" to consider early AM to be an extension of previous day
$puts(dayssince,$sub($get(dayssince),$if($and($greater(7,$substr(%cwb_systemdatetime%,12,13)),$greater($substr(%last_played%,12,13),6)),1,0)))
$if($and($greater($substr(%cwb_systemdatetime%,12,13),6),$greater(7,$substr(%last_played%,12,13))),$puts(dayssince,$add($get(dayssince),1)),)

// calculate day of week of last play
$puts(calcdayofweek,$add(1,$mod($add($substr(%last_played%,3,4),$div($substr(%last_played%,3,4),4),$select($substr(%last_played%,6,7),6,2,2,5,0,3,5,1,4,6,2,4),$substr(%last_played%,9,10)),7)))

// correct day of week to consider early AM to be an extension of previous day
$puts(calcdayofweek,$sub($get(calcdayofweek),$ifgreater(7,$substr(%last_played%,12,13),1,0)))
$if($strcmp($get(calcdayofweek),0),$puts(calcdayofweek,7),)

// calculate period of day of last play (night, morning, etc.)
$puts(dayperiod,$select($add(1,$substr(%last_played%,12,13)),Night,Night,Night,Night,Night,Night,Night,Morning,Morning,Morning,Morning,Morning,Afternoon
,Afternoon,Afternoon,Afternoon,Afternoon,Evening,Evening,Evening,Evening,Night,Night,Night))

// calculate natural language timestamp
$if(%last_played%,$puts(rel_timestamp,$ifgreater($get(dayssince),0,$ifgreater($get(dayssince),1,$ifgreater($get(dayssince),6,$if($and($greater($get(dayssince),21),$not($strcmp($left(%cwb_systemdate%,7),$left(%last_played%,7)))),$if($not($strcmp($left(%cwb_systemdate%,4),$substr(%last_played%,1,4))),$select($substr(%last_played%,6,7),January,February,March,April,May,June,July,August,September,October,November,December)' '$ifgreater($get(dayssince),334,$substr(%last_played%,1,4),),$ifgreater(2,$sub($substr(%cwb_systemdate%,6,7),$substr(%last_played%,6,7)),'Last Month',$select($substr(%last_played%,6,7),January,February,March,April,May,June,July,August,September,October,November,December))),$ifgreater($div($add($get(dayssince),4),7),1,$div($add($get(dayssince),4),7)' Weeks Ago',Last Week)),$select($get(calcdayofweek),Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday)' '$get(dayperiod)),$if($strcmp($get(dayperiod),Night),Last,Yesterday)' '$get(dayperiod)),$if($strcmp($get(dayperiod),Night),Tonight,This $get(dayperiod)))),$puts(rel_timestamp,Never))

$set_global(rel_timestamp,$get(rel_timestamp))

/////////////////////////////////////////

Re: Natural Language Timestamps

Reply #36
Hello
Is there any way to humanize the date in a column? (without using Column UI component)
This component used in the topic is deprecated.

Thanks