Get maximum number of tiddlers created a day

112 views
Skip to first unread message

Euthymious

unread,
Jun 16, 2021, 4:31:11 AM6/16/21
to TiddlyWiki
Hello!
I got stuck on this seemingly simle question.
It is rather easy to count tiddlers created each day:

<$list filter="[!is[system]eachday[created]get[created]]">
On  {{{ [<currentTiddler>]}}}
{{{ [sameday<currentTiddler>count[]] }}}  tiddlers were created<br>
</$list>

But is it possible to pick one maximum number?

TW Tones

unread,
Jun 16, 2021, 9:21:26 PM6/16/21
to TiddlyWiki
Euthymious,

What do you mean by "But is it possible to pick one maximum number?"

Do you mean limit the output?
<$list filter="[!is[system]eachday[created]get[created]limit[20]]">
On  {{{ [<currentTiddler>]}}}
{{{ [sameday<currentTiddler>count[]] }}}  tiddlers were created<br>
</$list>

Tones

Euthymious

unread,
Jun 17, 2021, 9:27:18 AM6/17/21
to TiddlyWiki
Tones, 

No, I mean finding a day, when the largest number of tiddlers were created.

I guess, I should somehow pass the output of all those  [sameday<currentTiddler>count[]] to [maxall[]] but can't figure out how.

четверг, 17 июня 2021 г. в 04:21:26 UTC+3, TW Tones:

David Gifford

unread,
Jun 17, 2021, 10:03:06 AM6/17/21
to TiddlyWiki
Sort by highest?

Euthymious

unread,
Jun 17, 2021, 10:26:07 AM6/17/21
to TiddlyWiki
David,
well, I haven't thought of sorting, but that would be useful, too

четверг, 17 июня 2021 г. в 17:03:06 UTC+3, David Gifford:

Eric Shulman

unread,
Jun 17, 2021, 10:34:46 AM6/17/21
to TiddlyWiki
On Thursday, June 17, 2021 at 6:27:18 AM UTC-7 Euthymious wrote:
No, I mean finding a day, when the largest number of tiddlers were created.
I guess, I should somehow pass the output of all those  [sameday<currentTiddler>count[]] to [maxall[]] but can't figure out how.

Try this:
\define getCounts()
<$list filter="[!is[system]eachday[created]get[created]]">
{{{ [sameday<currentTiddler>count[]pad[3]] }}};<<currentTiddler>><br>
</$list>
\end

<$wikify name="countlist" text=<<getCounts>>>
On {{{ [enlist<countlist>sort[]last[]split[;]rest[]] }}} {{{ [enlist<countlist>sort[]last[]split[;]first[]trim[0]] }}} tiddlers were created<br>
</$wikify>

Notes:
1) Just like your in original code, the getCounts() macro produces a list of each day and the number of tiddlers created for that day
2) However, the output is formatted as "count;date", where the count is zero-padded to 3 digits so all count values are the same number of characters
3) The <<getCounts>> macro is passed to $wikify to capture its output in a variable named "countlist"
4) Then, using filtered transclusion, enlist[] the captured output, sort[] it in ascending order (i.e., by the 3 digit "count" value) and get the last item (i.e., the one with the largest count value)
5) To produce the date output, you split[] the last item at the ";" separator and use rest[] to get the date
6) To produce the count output, you split[] the last item at the ";" separator and use first[] to get the count, trimmed to remove any zero padding

enjoy,
-e

Euthymious

unread,
Jun 17, 2021, 11:03:57 AM6/17/21
to TiddlyWiki
Eric,
Thank you for the solution and even more for the great explanation. 

четверг, 17 июня 2021 г. в 17:34:46 UTC+3, Eric Shulman:

Eric Shulman

unread,
Jun 17, 2021, 11:06:26 AM6/17/21
to TiddlyWiki
addendum:

Here's a bit of additional coding to provide nicer formatting to the result:
\define formatDate()
<$tiddler tiddler=<<thisdate>>><$view field="title" format="date" template="[UTC]DDD, DDth MMM YYYY" /></$tiddler>
\end

<$wikify name="countlist" text=<<getCounts>>>
<$vars thisdate={{{ [enlist<countlist>sort[]last[]split[;]rest[]] }}}
      thiscount={{{ [enlist<countlist>sort[]last[]split[;]first[]trim[0]] }}}>
On <<formatDate>>, <<thiscount>> tiddlers were created<br>
</$vars>
</$wikify>

Notes:
1) The formatDate() macro takes a system date, stored in the <<thisdate>> variable, and converts it to a nicely formatted date string
2) Use $vars to extract and hold the date and count values as variables, "thisdate" and "thiscount"
3) Then display the desired output text, referencing <<formatDate>> and <<thiscount>>

enjoy,
-e
Reply all
Reply to author
Forward
0 new messages