01:1
02:0
03:1 etc
Runs completed=2
I'd like to count those '1' values in order to get a total of runs completed, but I'm stumped. Does anybody know how to count, add or mathematically manipulate data dictionary values? I'm using the pre-release version. Thanks.
Ie an index and value pair.
If so you can treat the value in a data tiddler like the value in a field.
I will try and post more on this later.
I even know how to do in before prerelease.
Regards
Tony
01:1
02:0
03:1
04:1
05:0
etc.
Any clues on counting the '1' values much appreciated.
\define all-values()<$list filter="[[Data]indexes[]]" variable=item><$view tiddler=Data index=<<item>>/></$list>\end
all-values: <<all-values>>
<$wikify name=string text="<<all-values>>">
String: <<string>>
<$set name=result filter="[<string>split[]sum[]]"> Set sum Result: <<result>><br></$set>
<$set name=result filter="[<string>split[]] +[count[]]"> Set Count: <<result>><br></$set> <hr> <$list filter="[<string>split[]sum[]]" variable=datum> List Result: <<datum>><br></$list>
<$list filter="[<string>split[]]" variable=datum> List: <<datum>><br></$list>
</$wikify>
\define all-values(data-tiddler) <$list filter="[[$data-tiddler$]indexes[]]" variable=item> <$view tiddler=Data index=<<item>>/></$list>
all-values: "<<all-values Data>>"<br>
<$wikify name=string text="<<all-values Data>>">
String: "<<string>>"<br>
<$set name=result filter="[<string>split[ ]sum[]]">
Set sum Result: <<result>><br>
<
/$set>
<$set name=result filter="[<string>split[ ]count[]]">
Set Count: <<result>><br>
</
$set>
<hr>
<$list filter="[<string>split[ ]sum[]]" variable=datum>
List Result: <<datum>><br>
<
/$list>
<hr>
<$list filter="[<string>split[ ]]" variable=datum>
List Item: <<datum>><br>
</$list>
<hr>
<h3>Count exact number of items with value "1" in prefix/suffix</h3>
<$set name=result filter="[<string>split[ ]prefix[1]suffix[1]count[]]">
Set Count: <<result>><br>
</
$set>
<$set name=result filter="[<string>split[ ]prefix[1]suffix[1]sum[]]">
Set Sum: <<result>><br>
</$set>
<$list filter="[<string>split[ ]prefix[1]suffix[1]count[]]" variable=result>
List Result Count: <<result>><br>
</$list>
<$list filter="[<string>split[ ]prefix[1]suffix[1]sum[]]" variable=result>
List Result Sum: <<result>><br>
</$list>
<h3>Best Method? (with Wikify)</h3>Use this {{{ [<string>split[ ]prefix[1]suffix[1]count[]] }}}Or this <$text text={{{ [<string>split[ ]prefix[1]suffix[1]count[]] }}}/>
If values only 0 or 1 use `{{{ [<string>split[ ]sum[]] }}}` giving {{{ [<string>split[ ]sum[]] }}}
</$wikify>
Do you think we could also provide values with other inputs like values<varname> values{!!fieldname} values{tiddlername!!fieldname} if it could parse this with spaces as the delimiter then numeric lists in a variable will not be deduped and can feed into our maths operators.
values[1 2 1 2 3]sum[]
I noticed when using macros or action widgets such as newttiddler parameters of the form name=value can be automatically converted to variables containing the value. I would like to see a method to do this with multiple key value pairs exposed for users. Solutions such as yours would benefit from returning such key value pairs that they could be handled like this. Imagin if we could iterate a data tiddler and have <<key>> and <<value>> and even <<indexnumber>> returned.
We could also have data tiddlers we access primarily by index number.
Regards
Tony
I think I understand what you mean but my observation of this was calling a modal with key=value pairs and at least within the modal the variables are populated. This looks like a workaround however the modal needs to define a close action and that could write the variables values elsewhere, like tiddlers or fields. Or even write a tiddler taged as a macro that defines and sets global variables.
In fact writing the content of a global macro may be a way to bypass this limitation.
I know this is a somewhat advanced idea and I may not have expressed it well but I hope you see what I mean.
Thony
-m
The problem is, that filter operators have no knowledge about the widget context they are called in. They are designed to have no side effects.
PMario if you can, could I ask you for an example of how to count the '1's as per my original post?
01: 0
02: 1
03: 1
04: 0
05: 1
06: 0
I've got it working with TonyM's method but not worked it out with your PR version. At the moment I'm more interested in manipulating values rather than keys so the many examples on your demo page help a lot, but the one example I needed wasn't there (always the case when I'm looking for examples!)
Thanks again guys, it's a valuable discussion.