Habit tracker - can dependency on MathyJS and TiddlyFormula plug in be removed?

I was trying to use a Habit tracker created by @Sii some years back. He was using MathyThing and TiddlyFormula plug-ins for it to work. Is it possible to modify the code using native TW features to avoid dependency on MathyJS and TiddlyFormula plug in.

1 Like

@arunnbabu81 I don’t know about MathyThing but it may possible to replace the formulas in the mushroom brackets now we have unix time, you could add and subtract days with that and keep the calendar relationships, or make use of the days operator.

  • however I personally would not bother unless I had a very good reason because it could be quite fiddly.
  • If I did I would probably start afresh and use what I see as the requirements and start again.

Can anyone familiar with formula plug in by eblaster tell whether it is possible to recreate this code from the habit tracker using wikitext

<$wikify name="day1" text="(= year(add_days(now(),{{!!day-diff}}))&'/'&month(add_days(now(),{{!!day-diff}}))&'/'&day(add_days(now(),{{!!day-diff}})) =)">

Learning filter expression is enough for me…Forumla plugin is too much for my head.

I’m now developing a new habit tracker plugin, with only filter expression and action widget, see tiddly-gittly.github.io/tw-gamification/#DevelopSubPlugin for usage preview.

1 Like

I think to make your example work, you have to remove the outer quotes " ". The mushroom braces delimit the formula (= =).

I’m not familiar with the formula plugin, but here is code which does what I think that code is doing (adding number of days to the current date)

\function msPerDay() 86400000
\function add.days(timestamp numDays) [<numDays>multiply<msPerDay>add<timestamp>]

!! Test cases

One day from now:
{{{[add.days<now TIMESTAMP>,[1]format:timestamp[YYYY/0MM/0DD]]}}}

10 days from now: 
{{{[add.days<now TIMESTAMP>,[10]format:timestamp[YYYY/0MM/0DD]]}}}

Leap day 2024! (may need to adjust depending on your timezone)
{{{[add.days[1709478163000],[-3]format:timestamp[YYYY/0MM/0DD]]}}}

!! Drop-in replacement for the wikify
<$let day1={{{[add.days<now TIMESTAMP>,{!!day-diff}format:timestamp[YYYY/0MM/0DD]]}}}>
</$let>

see demo of the above code on the share site

2 Likes

I am on a journey now…will test this once i am back home…thank you @btheado for taking time to help

@btheado Here is what I could come up with- Share demo

I don’t know how to do this part from the original habit tracker {{!!day-diff}}-1 , {{!!day-diff}}-2 etc

Given below is the original habit tracker code made by sii

<$wikify name="day1" text="(= year(add_days(now(),{{!!day-diff}}))&'/'&month(add_days(now(),{{!!day-diff}}))&'/'&day(add_days(now(),{{!!day-diff}})) =)">
<$wikify name="day2" text="(= year(add_days(now(),{{!!day-diff}}-1))&'/'&month(add_days(now(),{{!!day-diff}}-1))&'/'&day(add_days(now(),{{!!day-diff}}-1)) =)">
<$wikify name="day3" text="(= year(add_days(now(),{{!!day-diff}}-2))&'/'&month(add_days(now(),{{!!day-diff}}-2))&'/'&day(add_days(now(),{{!!day-diff}}-2)) =)">
<$wikify name="day4" text="(= year(add_days(now(),{{!!day-diff}}-3))&'/'&month(add_days(now(),{{!!day-diff}}-3))&'/'&day(add_days(now(),{{!!day-diff}}-3)) =)">
<$wikify name="day5" text="(= year(add_days(now(),{{!!day-diff}}-4))&'/'&month(add_days(now(),{{!!day-diff}}-4))&'/'&day(add_days(now(),{{!!day-diff}}-4)) =)">
<$wikify name="day6" text="(= year(add_days(now(),{{!!day-diff}}-5))&'/'&month(add_days(now(),{{!!day-diff}}-5))&'/'&day(add_days(now(),{{!!day-diff}}-5)) =)">
<$wikify name="day7" text="(= year(add_days(now(),{{!!day-diff}}-6))&'/'&month(add_days(now(),{{!!day-diff}}-6))&'/'&day(add_days(now(),{{!!day-diff}}-6)) =)">

Maybe this will help you get closer

<$list filter="[range[0],[-6]add{!!day-diff}]" variable=numDays>

{{{[add.days<now TIMESTAMP>,<numDays>format:timestamp[YYYY/0MM/0DD]]}}}
</$list>

It outputs today’s date and the 6 prior days.

@btheado Share demo I made some valiant effort to almost reach the final result. But on shifting the days using the buttons at the top, newly added dates are showing the marked response of the previous dates instead of showing blank spaces. Which part of the code needs correction ?

\define increment(field:counter)
<$action-setfield $field=$field$ $value={{{ [all[current]get[$field$]!is[blank]else[0]add[1]] }}}/>
\end
\define decrement(field:counter)
<$action-setfield $field=$field$ $value={{{ [all[current]get[$field$]!is[blank]else[0]add[-1]] }}}/>
\end

\function msPerDay() 86400000
\function add.days(timestamp numDays) [<numDays>multiply<msPerDay>add<timestamp>]
<$button actions=<<increment day-diff>>>
{{$:/core/images/chevron-left}}
</$button>
<$button actions=<<decrement day-diff>>>
{{$:/core/images/chevron-right}}
</$button>

<$button style="float:right;">
<$action-sendmessage $message="tm-new-tiddler" title="" tags="habit"/>
New habit
</$button>

<table class="styled-table">
<tr>
<th>Habit</th>
<$list filter="[range[0],[-6]add{!!day-diff}]" variable=numDays>
<th>{{{[add.days<now TIMESTAMP>,<numDays>format:timestamp[YYYY/0MM/0DD]]}}}</th>
</$list>
</tr>
<$list filter="[tag[habit]]">
<$wikify name="data" text="<<currentTiddler>>/data" tag="habit-json" caption=<<currentTiddler>> >
<tr>
<td><$link to=<<currentTiddler>>><$view field="caption"/></$link></td>
<$list filter="[range[0],[-6]add{!!day-diff}]" variable=numDays>
<$let day-of-week={{{[add.days<now TIMESTAMP>,<numDays>format:timestamp[YYYY/0MM/0DD]]}}}>
<td>
<$reveal type="match" stateTitle=<<data>> stateIndex=<<day-of-week>> text="yes">
<$button setTitle=<<data>> setIndex=<<day-of-week>> setTo="no" class="tc-btn-invisible">{{tick-wiki.png}}</$button>
</$reveal>
<$reveal type="match" stateTitle=<<data>> stateIndex=<<day-of-week>> text="no">
<$button setTitle=<<data>> setIndex=<<day-of-week>> setTo="yes" class="tc-btn-invisible">{{cross-wiki.png}}</$button>
</$reveal>
<$reveal type="match" stateTitle=<<data>> stateIndex=<<day-of-week>> text="">
<$button setTitle=<<data>> setIndex=<<day-of-week>> setTo="yes" class="tc-btn-invisible">{{ellipsis-wiki.png}}</$button>
</$reveal>
</td>
</$let>
</$list>
</tr>
</$wikify>
</$list>
</table>

This <$list filter="[tag[habit]]"> is redefining currentTiddler and therefore the nested relative reference {{!!day-diff}} no longer does what you want.

One way to fix it is to capture {{!!day-diff}} into a variable prior to the list widget changing currentTiddler.

1 Like

So finally I got a habit tracker using wikitext only- here is the share demo

Thank you @btheado for guiding me along the correct path each time I was making a mistake. Thank you so much.

1 Like