Discussion:
[tw] Re: How to calculate (sum, avg) with fields and store the result in an other field?
(too old to reply)
Matthew Lauber
2017-08-04 18:30:53 UTC
Permalink
Raw Message
The issue is that the assignment doesn't work like that. You can't assign
to a field like that, regardless of whether it's math or text or anything
else. The equals sign is just another letter when it's used in html.
You'd probably need to play around with macros and the <$action-setfield>
widget to get what you want to happen. AS you can see in your example. The
<$calc> widget did add the two fields together resulting in the 8 you see
in the example.

Matt Lauber
Hello dear helpers,
in some tiddlers I have some (< 20) fields with numbers in them, ie
{{!!field1}}=2, {{!!field2}}=4 and {{!!field3}}=5 and so on.
I imported $:/plugins/mklauber/math.js
<http://mklauber.github.io/tiddly-mathjs/#%24%3A%2Fplugins%2Fmklauber%2Fmath.js>
from http://mklauber.github.io/tiddly-mathjs/
Using <$calc>, I *cannot *add the sum of these three fields
{{!!field4}}=<$calc>{{!!field1}} + {{!!field2}} + {{!!field3}}</$calc> into
field4.
What went wrong?
I need a solution for automatically calculating with the values of my
fields (+, -, *, :, percent, average) and to store the result in an other
named field. Is there such a solution out there? (Statistical values
calculated about all tiddlers with these fields would be great.)
The use case is to calculate the average points of students they got in
some tests (and to get the average of all students).
Greetings,
Uwe
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/adcb2e66-a2d4-4202-bfc9-1d8c626affe0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Matthew Lauber
2017-08-04 18:50:32 UTC
Permalink
Raw Message
Here's a wiki with what you want, I think. You have to click the calculate
button to put the value in the field.
Hello dear helpers,
in some tiddlers I have some (< 20) fields with numbers in them, ie
{{!!field1}}=2, {{!!field2}}=4 and {{!!field3}}=5 and so on.
I imported $:/plugins/mklauber/math.js
<http://mklauber.github.io/tiddly-mathjs/#%24%3A%2Fplugins%2Fmklauber%2Fmath.js>
from http://mklauber.github.io/tiddly-mathjs/
Using <$calc>, I *cannot *add the sum of these three fields
{{!!field4}}=<$calc>{{!!field1}} + {{!!field2}} + {{!!field3}}</$calc> into
field4.
What went wrong?
I need a solution for automatically calculating with the values of my
fields (+, -, *, :, percent, average) and to store the result in an other
named field. Is there such a solution out there? (Statistical values
calculated about all tiddlers with these fields would be great.)
The use case is to calculate the average points of students they got in
some tests (and to get the average of all students).
Greetings,
Uwe
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/800dc9cc-d2fd-4cd7-808d-9e59f8b9d92f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Uwe
2017-08-08 09:50:02 UTC
Permalink
Raw Message
I totally agree.

Nonetheless, thanks to any contribution to this issue, maybe it helps
others.

Here is the solution, I made:


<$fieldmangler>
<$list filter="[is[current]tag[Aktiv]]">
<$button message="tm-remove-tag" param="Aktiv">&not;Aktiv</$button>
</$list>
<$list filter="[is[current]!tag[Aktiv]]">
<$button message="tm-add-tag" param="Aktiv">Aktiv</$button>
</$list>
</$fieldmangler>
<$fieldmangler>
<$list filter="[is[current]tag[m]]">
<$button message="tm-remove-tag" param="m">&not;m</$button>
</$list>
<$list filter="[is[current]!tag[m]]">
<$button message="tm-add-tag" param="m">m</$button>
</$list>
</$fieldmangler>
<$fieldmangler>
<$list filter="[is[current]tag[w]]">
<$button message="tm-remove-tag" param="w">&not;w</$button>
</$list>
<$list filter="[is[current]!tag[w]]">
<$button message="tm-add-tag" param="w">w</$button>
</$list>
</$fieldmangler>
<$fieldmangler>
<$list filter="[is[current]tag[FW51]]">
<$button message="tm-remove-tag" param="FW51">&not;FW51</$button>
</$list>
<$list filter="[is[current]!tag[FW51]]">
<$button message="tm-add-tag" param="FW51">FW51</$button>
</$list>
</$fieldmangler>
<$fieldmangler>
<$list filter="[is[current]tag[FW61]]">
<$button message="tm-remove-tag" param="FW61">&not;FW61</$button>
</$list>
<$list filter="[is[current]!tag[FW61]]">
<$button message="tm-add-tag" param="FW61">FW61</$button>
</$list>
</$fieldmangler>
<$fieldmangler>
<$list filter="[is[current]tag[FW71]]">
<$button message="tm-remove-tag" param="FW71">&not;FW71</$button>
</$list>
<$list filter="[is[current]!tag[FW71]]">
<$button message="tm-add-tag" param="FW71">FW71</$button>
</$list>
</$fieldmangler>
<$fieldmangler>
<$list filter="[is[current]tag[Facharbeit]]">
<$button message="tm-remove-tag"
param="Facharbeit">&not;Facharbeit</$button>
</$list>
<$list filter="[is[current]!tag[Facharbeit]]">
<$button message="tm-add-tag" param="Facharbeit">Facharbeit</$button>
</$list>
</$fieldmangler>
<!-- Berechne die Summen fÃŒr alle tiddler, die mit FW51 getaggt sind. Das
kann spÀter der tag ctr sein.-->

{{!!title}}

[[Wirtschaftsinformatik]]

US01 KA01 + KA02: <$edit-text field='fw51-wi-ka01' size=2/> + <$edit-text
field='fw51-wi-ka02' size=2/> = {{!!fw51-wi-ka1u2}}<br>
US02 KA03 + KA04: <$edit-text field='fw51-wi-ka03' size=2/> + <$edit-text
field='fw51-wi-ka04' size=2/> = {{!!fw51-wi-ka3u4}}<br>
//= {{!!fw51-wi-ka1b4}} Punkte Zwischenzeugnis// <br>

MS01 KA05 + KA06: <$edit-text field='fw51-wi-ka05' size=2/> + <$edit-text
field='fw51-wi-ka06' size=2/> = {{!!fw51-wi-ka5u6}} <br>
= ''{{!!fw51-us-os-wi-summe}}'' Punkte Abschlusszeugnis<br>

PÀd. Punkte Abschlusszeugnis WI: <$edit-text
field='fw51-wi-zeugnis_abschluss' size=2/><br>

<$button>WI: Aktualisieren und Speichern
<$action-sumfield2 $filter='[tag[FW51]]' $sumfield='fw51-wi-ka01'
$sumfield2='fw51-wi-ka02' $storefield='fw51-wi-ka1u2'/>
<$action-sumfield2 $filter='[tag[FW51]]' $sumfield='fw51-wi-ka03'
$sumfield2='fw51-wi-ka04' $storefield='fw51-wi-ka3u4'/>
<$action-sumfield2 $filter='[tag[FW51]]' $sumfield='fw51-wi-ka1u2'
$sumfield2='fw51-wi-ka3u4' $storefield='fw51-wi-ka1b4'/>
<$action-sumfield2 $filter='[tag[FW51]]' $sumfield='fw51-wi-ka05'
$sumfield2='fw51-wi-ka06' $storefield='fw51-wi-ka5u6'/>
<$action-sumfield2 $filter='[tag[FW51]]' $sumfield='fw51-wi-ka1u2'
$sumfield2='fw51-wi-ka3u4' $storefield='fw51-us-wi-summe'/>
<$action-sumfield2 $filter='[tag[FW51]]' $sumfield='fw51-us-wi-summe'
$sumfield2='fw51-wi-ka5u6' $storefield='fw51-us-os-wi-summe'/>
</$button>

---

{{!!title}}

[[Controlling]]

MS02 KA01 + KA02: <$edit-text field='fw51-ctr-ka01' size=2/> + <$edit-text
field='fw51-ctr-ka02' size=2/> <br>//= {{!!fw51-ctr-ka1u2}} Punkte
Zwischenzeugnis// <br>

OS01 KA03 + KA04: <$edit-text field='fw51-ctr-ka03' size=2/> + <$edit-text
field='fw51-ctr-ka04' size=2/> = {{!!fw51-ctr-ka3u4}} <br>
= ''{{!!fw51-ctr-summe}}'' Punkte Abschlusszeugnis<br>

PÀd. Punkte Abschlusszeugnis CTR: <$edit-text
field='fw51-ctr-zeugnis_abschluss' size=2/><br>

<$button>CTR: Aktualisieren und Speichern
<$action-sumfield2 $filter='[tag[FW51]]'| $sumfield='fw51-ctr-ka01'
$sumfield2='fw51-ctr-ka02'| $storefield='fw51-ctr-ka1u2'/>
<$action-sumfield2 $filter='[tag[FW51]]'| $sumfield='fw51-ctr-ka03'
$sumfield2='fw51-ctr-ka04'| $storefield='fw51-ctr-ka3u4'/>
<$action-sumfield2 $filter='[tag[FW51]]'| $sumfield='fw51-ctr-ka1u2'
$sumfield2='fw51-ctr-ka3u4'| $storefield='fw51-ctr-summe'/>
</$button>

And this is the (button based) solution only for adding the percentage
based points, not for the points themselves, not for the grades.

Automatically calculating values in the fields and in the tiddler like this
example would be a great simplification:

{{!!schnitt}}=({{!!field1}}+{{!!field2}}+{{!!field3}}+{{!!field4}})/4

To comfortably calc with (more than two) fields is often needed. Perhaps
some day a developer will see this problem and solve it. Let me know. ;-)

Greetings,

Uwe
Welcome to the club of non-functioning math in TW.
Its a mess of half solutions.
Josiah
in some tiddlers I have some (< 20) fields with numbers in them, ie
{{!!field1}}=2, {{!!field2}}=4 and {{!!field3}}=5 and so on.
I imported $:/plugins/mklauber/math.js
<http://mklauber.github.io/tiddly-mathjs/#%24%3A%2Fplugins%2Fmklauber%2Fmath.js>
from http://mklauber.github.io/tiddly-mathjs/
Using <$calc>, I *cannot *add the sum of these three fields
{{!!field4}}=<$calc>{{!!field1}} + {{!!field2}} + {{!!field3}}</$calc>
into field4.
What went wrong?
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/0c194ce7-8bf5-43c1-80ab-59387f60d437%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mat
2017-08-08 11:09:54 UTC
Permalink
Raw Message
Post by Uwe
Automatically calculating values in the fields and in the tiddler like
{{!!schnitt}}=({{!!field1}}+{{!!field2}}+{{!!field3}}+{{!!field4}})/4
While it's not direct (i.e not optimized), it should not be overly
difficult to make a macro with a listwidget and the argument "( field1 +
field2 + field3 + field4 ) / 4" and iterates through this to pairwise (i.e
two numbers and one operator at a time) apply one of the existing
calculators (e.g Thomas Elmigers rpn plugin).

But then, there must be a *zillion* great js calculators that could just be
wrapped up as a TW plugin (...he said confidently without having ever made
a js plugin)

<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/2d4e6f85-a9e3-4d9a-b08f-f30e122eaf26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Uwe
2017-08-08 14:28:44 UTC
Permalink
Raw Message
So I have tried this with Thomas Elmigers rpn plugin, found here:
https://tid.li/tw5/plugins.html
https://tid.li/tw5/hacks.html#rpnTest


<$macrocall $name="rpn" a={{!!field1}} b={{!!field2}} operation="+" 2/>

<$macrocall $name="rpn" a={{!!field3}} b={{!!field4}} operation="+" 2/>

It is also not possible to add more than 2 fields in a macrocall.

But how can I add the results of each of these expressions? (Has it
something to do with the listwidget you mentioned?)

Perhaps anyone has an idea for a completely other solution of the problem
(see first post). [Please not: An external link to an Excel spreadsheet ;-)]
Post by Mat
Post by Uwe
Automatically calculating values in the fields and in the tiddler like
{{!!schnitt}}=({{!!field1}}+{{!!field2}}+{{!!field3}}+{{!!field4}})/4
While it's not direct (i.e not optimized), it should not be overly
difficult to make a macro with a listwidget and the argument "( field1 +
field2 + field3 + field4 ) / 4" and iterates through this to pairwise (i.e
two numbers and one operator at a time) apply one of the existing
calculators (e.g Thomas Elmigers rpn plugin).
But then, there must be a *zillion* great js calculators that could just
be wrapped up as a TW plugin (...he said confidently without having ever
made a js plugin)
<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/df4f3904-b933-46c1-9625-d95f8497e68e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mat
2017-08-08 17:01:16 UTC
Permalink
Raw Message
Post by Uwe
So I have tried this with Thomas Elmigers rpn plugin,
But how can I add the results of each of these expressions? (Has it
something to do with the listwidget you mentioned?)
Yes, listwidget. I have not tried it so I may miss something fundamental
but, basically, you'd iterate through the arguments recursively using the
rpn to calculate "up til now" along the way. I'm a bit unsure of how to
handle parentheses but spontaneously I'd think the first listwidget
filtering must be to split out such sub-statements (i.e surrounded with
parentheses) and then do the iteration with the rpn on it's contents. If
you could accept statements without parentheses, I think it would be more
direct and simpler. Regardless; if you have limited experience with filter
operators in TW... then I guess you have some fun ahead of you ;-) ...BUT,
as noted, I don't think it would make for an effective solution given that
there surely are optimized js calculators that can(?) be 'tiddlified'.

<:-)
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/ca168494-66eb-4dde-8944-2ec5bd7d246d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thomas Elmiger
2017-08-10 06:36:11 UTC
Permalink
Raw Message
Hi Uwe

Try this structure to sum 4 fields in 1 macrocall:

<$macrocall $name="rpn" a=<<rpn "{{rpnTest!!example-1}}"
"{{rpnTest!!example-1}}" +>> b=<<rpn "{{rpnTest!!example-1}}"
"{{rpnTest!!example-1}}" +>> operation="+"/>

Hint: in the shortcut <<syntax>> the tiddler from where to get the field
value must be specified in the transclusion.

All the best,
Thomas
Post by Uwe
https://tid.li/tw5/plugins.html
https://tid.li/tw5/hacks.html#rpnTest
<$macrocall $name="rpn" a={{!!field1}} b={{!!field2}} operation="+" 2/>
<$macrocall $name="rpn" a={{!!field3}} b={{!!field4}} operation="+" 2/>
It is also not possible to add more than 2 fields in a macrocall.
Well, as demonstrated, it IS possible, but not very intuitive ;–)
And: I would not recommend to try to add another level – the code gets too
complicated. So 4 operands would be the limit.
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/fbcfeddb-e0b4-4fac-8b8d-8a5c69826d98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Mark S.' via TiddlyWiki
2017-08-08 14:43:46 UTC
Permalink
Raw Message
A different approach would be to use mathcell
(http://mathcell.tiddlyspot.com/) that emulates spreadsheet-like abilities.

Good luck,
Mark
Hello dear helpers,
in some tiddlers I have some (< 20) fields with numbers in them, ie
{{!!field1}}=2, {{!!field2}}=4 and {{!!field3}}=5 and so on.
I imported $:/plugins/mklauber/math.js
<http://mklauber.github.io/tiddly-mathjs/#%24%3A%2Fplugins%2Fmklauber%2Fmath.js>
from http://mklauber.github.io/tiddly-mathjs/
Using <$calc>, I *cannot *add the sum of these three fields
{{!!field4}}=<$calc>{{!!field1}} + {{!!field2}} + {{!!field3}}</$calc> into
field4.
What went wrong?
I need a solution for automatically calculating with the values of my
fields (+, -, *, :, percent, average) and to store the result in an other
named field. Is there such a solution out there? (Statistical values
calculated about all tiddlers with these fields would be great.)
The use case is to calculate the average points of students they got in
some tests (and to get the average of all students).
Greetings,
Uwe
--
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 tiddlywiki+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/0b4eaccb-84b6-4dbd-b313-9eb27bd3c48e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...