Sort data tiddlers (dictionary tiddlers) by an index

182 views
Skip to first unread message

Atronoush

unread,
Nov 29, 2019, 4:43:46 PM11/29/19
to TiddlyWiki
How one can list a set of data tiddlers by an index?

Consider dat01 dat02 dat03 all tagged with test and all have indexes ia and ib

e.g dat01 is

dat01
 ia
: 10
 ib
: 12.5


And then

<$list filter="[tag[test]sort[ia]]">


</$list>


but seems TW sort operator does not work with index. what do you think?

Atronoush

Mark S.

unread,
Nov 29, 2019, 7:42:41 PM11/29/19
to TiddlyWiki

<$list filter="[prefix[dat]getindex[ia]sort[]]">

</$list>

Eric Shulman

unread,
Nov 29, 2019, 11:21:38 PM11/29/19
to TiddlyWiki
On Friday, November 29, 2019 at 4:42:41 PM UTC-8, Mark S. wrote:
<$list filter="[prefix[dat]getindex[ia]sort[]]">

</$list>

@Mark: your answer will only return the sorted index values themselves, what @atro wants is the names of the tiddlers containing those index values

There *is* a solution, but it's not as simple.  Here's a (tested) demo that works:
\define getitems()
<$list filter="[tag[test]]">
   {{{ [<currentTiddler>getindex[ia]divide[1000]fixed[3]removeprefix[0.]] }}};<<currentTiddler>>
</$list>
\end

\define showoutput() <<currentTiddler>>={{##ia}}<br>

__BEFORE: test tiddlers:__<br>
<$list filter="[tag[test]]">
   <<showoutput>>
</$list>

__AFTER: test tiddlers, sorted by index "ia"__<br>
<$wikify name="items" text=<<getitems>>>
   <$list filter="[enlist<items>nsort[]]">
      <$tiddler tiddler={{{ [<currentTiddler>split[;]last[]] }}}>
         <<showoutput>>
      </$tiddler>
   </$list>
</$wikify>

1) The getitems() macro builds a list of titles preceded by their respective "ia" values (zero padded) with a semi-colon as a delimiter.

2) That list output is wikified, and used as input to another $list widget that sorts it numerically

3) Then, a $tiddler widget is used to remove the "ia;" prefix, resulting in the original tiddler title which is then used to show the output.

enjoy,
-e





Atronoush

unread,
Nov 30, 2019, 1:05:44 AM11/30/19
to TiddlyWiki
Hello Eric,
 Thank you for your solution! It is not straightforward and smart procedure but it works in my case!
In conclusion I understood you have added ia as a prefix to tiddler names and then sort them.

Thanks
Atro

Atronoush

unread,
Nov 30, 2019, 1:08:25 AM11/30/19
to TiddlyWiki
Eric,
 What should I do if the tiddler name has space like "dat04 new"?

Atro

On Saturday, November 30, 2019 at 7:51:38 AM UTC+3:30, Eric Shulman wrote:

Eric Shulman

unread,
Nov 30, 2019, 2:47:15 AM11/30/19
to TiddlyWiki
On Friday, November 29, 2019 at 10:08:25 PM UTC-8, Atronoush wrote:
Eric,
 What should I do if the tiddler name has space like "dat04 new"?

Use this revised definition for "getitems()":
\define getitems()
<$list filter="[tag[test]]">

   
<$text text="[["/>{{{ [<currentTiddler>getindex[ia]divide[1000]fixed[3]removeprefix[0.]] }}};<<currentTiddler>><$text text="]]"/>
</$list>
\end

What it does is to enclose each generated title inside doubled squarebrackets, which ensures that they are treated as single titles in all subsequent filter handling

Thus, if your tiddlers are named
dat01
dat
02
dat
03 with more words
dat04

The generated list of items will be:
[[nn;dat01]] [[nn;dat 02]] [[nn;dat 03 with more words]] [[nn;dat04]]

The rest of the code remains the same.

enjoy,
-e

Atronoush

unread,
Nov 30, 2019, 3:38:05 AM11/30/19
to TiddlyWiki
Hi Eric
 This works like a charm!

Many thanks

Atro

Mohammad

unread,
Dec 1, 2019, 5:34:59 AM12/1/19
to TiddlyWiki
Nice solution Eric! I tested this for hundreds of tiddlers (created by TiddlerCommander) and it seems a bit slow but works great!
I gonna to use this in my Dynamic Tables macro in Shiraz 2.0.0 plugin!

Cheers
Mohammad 

Eric Shulman

unread,
Dec 1, 2019, 7:26:40 AM12/1/19
to TiddlyWiki
On Sunday, December 1, 2019 at 2:34:59 AM UTC-8, Mohammad wrote:
Nice solution Eric! I tested this for hundreds of tiddlers (created by TiddlerCommander) and it seems a bit slow but works great!
I gonna to use this in my Dynamic Tables macro in Shiraz 2.0.0 plugin!

hmm... I just realized that it can be nominally less compute intensive... you don't actually need to use "fixed[3]removeprefix[0.]"

As long as the numbers are divided by a large enough power of 10 to shift all the values to the right of the decimal, they will be correctly "zero padded" for purposes of sorting numerically

Thus:
\define getitems()
<$list filter="[tag[test]]">

   
<$text text="[["/>{{{ [<currentTiddler>getindex[ia]divide[1000]] }}};<<currentTiddler>><$text text="]]"/>
</$list>
\end

-e

Mohammad

unread,
Dec 1, 2019, 7:36:53 AM12/1/19
to TiddlyWiki
Thanks, This should be quicker!
I will inform you my findings using this new improved one!

--Mohammad
Reply all
Reply to author
Forward
0 new messages