Table and filter query to include days of the week

Hi,

Hopefully this isn’t too convoluted.

Each tiddler has a field containing the week number (‘week’) and the first table groups the calculations according to the week number

firefox_8rIUNA1LlV

<table>
<tr>
<td> week</td>
<td> A</td>
<td> B</td>
</tr>

<$list filter="[tag[current]field:Y[1]get[week]unique[]!sort[]]" variable="week">
<tr>
<td> <<week>> </td>

<$list filter="[tag[current]field:week<week>get[week]count[]]  "variable="A">
<td> <<A>> </td>

<$list filter="[tag[current]field:week<week>] :filter[get[r]compare:number:gt[0]]:and[count[]]  " variable="B">
<td> <<B>> </td>

</$list>

What I’d also like to have is the calculations grouped by the day of the week. I used the created date, and much to my surprise, the first line does seem to convert this to the days and then group them, but the rest of the calculations don’t work - probably because it’s the completely wrong approach :roll_eyes:

firefox_3TS4QtLzgE

<table>
<tr>
<td> Day</td>
<td> A</td>
<td> B</td>
</tr>

<$list filter=" [tag[current]field:Y[1]get[created]format:date[DDD]unique[]sort[]] " variable="day">
<tr>
<td> <<day>> </td>

<$list filter="[tag[current]field:created<day>get[created]count[]]  "variable="A">
<td> <<A>> </td>

<$list filter="[tag[current]field:created<day>] :filter[get[r]compare:number:gt[0]]:and[count[]]  " variable="B">
<td> <<B>> </td>

Any pointers much appreciated.

Thanks
Jon

If you gave the test data with your example, we cloud reproduce and fix it, rather than just a desk exercise.

Where do you close the second list <$list> ?

  • Looks funny, use `]" variable=A >

I am not sure why you use the unique operator.

Try to use this instead in the “A” list:

get[created]format:date[DDD]match<day>count[]

Thanks, Yaisog, that works.

<table>
<tr>
<td> Day</td>
<td> A</td>

</tr>

<$list filter=" [tag[current]get[created]format:date[DDD]unique[]sort[]] " variable="day">
<tr>
<td> <<day>> </td>


<$list filter="[tag[current]get[created]format:date[DDD]match<day>count[]]  "variable="A">
<td> <<A>> </td>

So, in trying to understand what’s going on, I think the 1st line uses the created date to group the tiddlers according to the particular day of the week they were created.

The 2nd line then counts the number of tiddlers created on each day (A)

So, if each tiddler has a field ‘r’, how would I, for example, count the content of the field and display it in the next column (B)?

Sorry, I didn’t have enough time this morning to explain how it works, but I think you got it right. :+1:

[…] how would I, for example, count the content of the field […]

I’m not exactly sure what you mean by “count the content”. If field r contains a number and you want to add that number for all fields with the same weekday A, then you would best use the :reduce prefix. That one is a bit complicated, but powerful. If you can confirm that I correctly identfied what you want to do, I’ll be happy to explain it with some code, though.

Have a nice day
Yaisog

Hi Yaisog,

Many thanks for your help with this.

Yes, specifically, for ‘r’ I’d want to count the total of when r is <0 (and also =0 and >0)

( I’ve used this before: :filter[get[r]compare:number:lt[0]]:and[count[]] )

but so that the resulting number is associated with the particular day and appears in column (B)

If I were to write this in WikiText, it would look like this:

<$list filter="[tag[current]field:Y[1]get[created]format:date[DDD]unique[]sort[]]" variable="weekday">
	<tr>
		<td><<weekday>></td>
		<$let A={{{ [tag[current]get[created]format:date[DDD]match<weekday>count[]] }}}
		      B={{{ [tag[current]get[created]format:date[DDD]match<weekday>] :filter[get[r]compare:number:gt[0]] :and[count[]] }}} >
			<td><$text text=<<A>> /></td>
			<td><$text text=<<B>> /></td>
		</$let>
	</tr>
</$list>

I changed the inner two lists to simple variable assignments, since there is nothing to iterate over, just a single value. These $let assignments use inline filtered transclusions for that. The $text widgets just makes sure that the output doesn’t get “linkified”.

The filter expression for “B” starts the same as in my previous post, but ends with basically your code, using :filter and :and: All tiddlers with a date matching <<weekday>> are filtered to see if their r field contains a number greater than zero, and the remainder counted.

There were some syntax errors in your original code (e.g. missing spaces and </$list>s) that might have contributed to you not getting the expected results. I can’t guarantee for the code above, as I had no data to test it with, but I have a good feeling about it. :wink:

Also, check out this filter debug plugin that lets you see what’s going on inside filter runs. Makes programming more complex filter expressions much easier…

That looks great and if there was any justice in the world it would work…but unfortunately it doesn’t seem to - column B is 7 zeros!

I’ll mock something up and get back to you.

Thanks again
Jon

p.s. that filter debug plugin looks just what I need!

Hi Yaisog,

Here’s a demo which I hope is accurate:

https://5rise.tiddlyhost.com/

I adapted some pre-existing tiddlers so I don’t know why it is showing the created date as today.

Thanks again
Jon

Hi Jon,
that was absolutely my fault.

The problem was that the filter output in the definition of B after the match<weekday> check is not the original title anymore, but the name of the weekday. This name is then used in subsequent runs, and naturally will not find anything, as these tiddlers don’t exist.
The correct line should be:

B={{{ [tag[current]] :filter[get[created]format:date[DDD]match<weekday>] :filter[get[r]compare:number:gt[0]] :and[count[]] }}} >

Here, the date name check is moved into a separate :filter run, which doesn’t change the original titles, so they are still available for the other :filter run.

In the definition of A that is not a problem, since here the original titles are not required for count.

Have a nice day
Yaisog

1 Like

Hey Yaisog - no problem!

That works and just gives my wiki a whole new functionality - thanks a lot!

You’ve encouraged me to try and learn about filters and I’ll practice with your plugin.

Have a nice day yourself!
Jon