Filter operator for grouping by removing suffix

82 views
Skip to first unread message

Christoph Chalfin

unread,
Nov 26, 2020, 9:17:53 AM11/26/20
to TiddlyWiki

Hello everyone,

I just can´t wrap my head around this one, now have been trying different things for a couple of hours :(

I have several tiddlers with the name scheme:
$:/weekplan-2020-11-48-23-Monday-1
$:/weekplan-2020-11-48-23-Monday-2
$:/weekplan-2020-11-48-23-Monday-3
$:/weekplan-2020-11-48-24-Wednesday-1
$:/weekplan-2020-11-48-24-Wednesday-2
$:/weekplan-2020-11-48-25-Thursday-1
$:/weekplan-2020-11-48-23-Thursday-2
...

The numbers are: Year, Month, Week number, day of month, day of week, number counting

I now want to show in a table all the tiddlers with year 2020, month 11, week 48 and the ones with the same day should be in one table row in different columns.

I manage to filter all the tiddlers with the matching year, month and week by the prefix/removeprefix filter operator. Now I don´t get it how to group these tiddlers with the same day by removing the suffix number counting resulting in something like this:

23-Monday-1 23-Monday-2 23-Monday-3
24-Wednesday-1 24-Wednesday-2
25-Thursday-1 23-Thursday-2

Can I use the subfilter operator for that? Or is there a filter operator I am missing?

Thank you!
Christoph

Mark S.

unread,
Nov 26, 2020, 1:53:22 PM11/26/20
to TiddlyWiki
Something like the code below can do what you seem to want. But it's kind of complicated and
messy, requiring helper macros and the wikify widget. It's much easier if construct your tiddlers 
according to basic database design principles.

The first principle of database design is that you don't store multiple pieces of information in a 
single field. Unfortunately TW gets you off to a bad start, with the title field already performing at
least 3 different functions.

If you put year, month, week, and day all into their own fields, then it becomes much easier 
and understandable to create report tiddlers. It could probably be done in one or two list
widgets in 5.1.23prerelease using the new sortsub operator.

Ok, here's the code using your existing setup:

\define listdays(pfx)
<$list filter="""[prefix<__pfx__>]""" variable="thing1">
<$list filter="""[<thing1>split[-]nth[5]]"""/>
</$list>
\end

\define listweek2(pfx daynum)
<td>
<$list filter="""[prefix[$pfx$$daynum$]]""" >

</$list>
</td>
\end

\define listweek(pfx)
<tr><td>$pfx$</td>
<$wikify text="""<<listdays '$pfx$'>>""" name=daylist>
<$list filter="""[enlist<daylist>sort[]]""" variable=daynum>
<$macrocall $name=listweek2 pfx=<<__pfx__>> daynum=<<daynum>> />
</$list>
</$wikify>
</tr>
\end

<<listweek """$:/weekplan-2020-11-48-""">>


Christoph Chalfin

unread,
Nov 27, 2020, 4:29:14 AM11/27/20
to TiddlyWiki
Thank you so much for this detailed example!

I have two questions:
1) What do the three """ mean? Could you also just use one " or do the three have a special function?
2) I never really understood what the syntax <__pfx__> does. I get the $name$ and $(name)$ - but the other macro notations don´t come easily to me.

Mark S.

unread,
Nov 27, 2020, 11:16:02 AM11/27/20
to TiddlyWiki
The """ thing is a habit I go into to help prevent code that breaks when confronted with tiddlers that have spaces, quotes, or other odd punctuation. Very often it isn't actually needed.

It's a similar thing for the <__pfx__> syntax. It's a bit funky, but it is more robust when the content of the parameter might contain some unexpected punctuation. I probably could have used [$pfx$] instead.

The notation is really useful when you are using a variable define outside the macro (that is, a variable defined in the calling environment). Then you might call it like:

...tag<myvariable>...

which is a lot less clunky than other alternatives.

TW Tones

unread,
Nov 27, 2020, 4:12:08 PM11/27/20
to TiddlyWiki

scheuer.

I am building extensive public documentation, based on others work as well,  on the details of many things including the """ see here

Tones 

Reply all
Reply to author
Forward
0 new messages