Added to TW-Scripts (will be available in next update)
On Thursday, January 2, 2020 at 11:34:11 PM UTC+3:30, Mark S. wrote:
>
> Unfortunately, things aren't always that easy. One of the problems with TW
> list filters is that they sometimes produce results one at a time, rather
> than as a title list. Many of the convenient operators (like sum) that we
> would like to use, on the other hand, often want to see a title list. In
> this case, you can't grab all the values out of a data tiddler -- you have
> to enumerate them one by one, and then pack them into something that can be
> turned back into a title list. The trick here is to do the enumeration in a
> macro, wikify that macro, and then split the results. If that seems like a
> lot of extra steps, it's only because ... it is.
>
> Anyway, this seems to work.
>
> Good luck!
>
>
> \define sumlist() <$list filter="[all[current]indexes[]]" variable="index"
> >{{{ [all[current]getindex<index>] }}},</$list>
>
> <table>
> <th>Idea</th><th>Vote Count</th><th>Sum</th><th>Avg Score</th>
> <$list filter="[tag<currentTiddler>]">
> <tr>
> <td>{{!!title}}</td>
> <$list filter="[all[current]indexes[]count[]]" variable="count">
> <$wikify name="sumlist" text="""<<sumlist>>""">
> <$list filter="[<sumlist>split[,]sum[]]" variable="sum">
> <$list filter="[<sum>divide<count>]" variable="avg">
> <td><<count>></td>
> <td><<sum>></td>
> <td><<avg>></td>
> </$list>
> </$list>
> </$wikify>
> </$list></tr>
> </$list>
> </table>
>
>
>
>
> On Thursday, January 2, 2020 at 6:34:12 AM UTC-8, Stobot wrote:
>>
>> Hello All,
>>
>> I must be missing easy, but is there a way to easily reference the values
>> of data tiddlers within filter notation? I'm trying to build a 'voting'
>> mechanism for my multi-user wiki. My initial thought would be do have each
>> "item to be voted on" as a data tiddler, and store the "score" under their
>> username, so that I can tell how many people voted, and what the average
>> score was. Each data tiddler would be tagged with the name of the vote.
>>
>> So, I have for instance a data tiddler named "Idea 1", "Idea 2", "Idea 3"
>> and so on. "Idea 1" would look like:
>> User A:1
>> User B:2
>> User C:2
>> User D:3
>> User E:1
>> etc.
>>
>> Each data tiddler would be tagged "Vote on this" or something. Here's my
>> code so far for the "Vote on this" tiddler:
>>
>> <table>
>> <th>Idea</th><th>Vote Count</th><th>Avg Score</th>
>> <$list filter="[tag<currentTiddler>]">
>> <tr>
>> <td>{{!!title}}</td>
>> <td><$list filter="[all[current]indexes[]count[]]"></$list></td>
>> <td><$list filter="[all[current]indexes[]get[value]] +sum[]]">
>> </$list></td>
>> </tr>
>> </$list>
>> </table>
>>
>> The line with the get[value] +sum[] is where I'm stuck. Obviously sum
>> doesn't get me all the way to average, but sum/count will work once I
>> figure out the reference part.
>>
>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/594be77c-4e47-480c-8fb5-e6f53c6683c7%40googlegroups.com.