Comparing multiple values against multiple values

Hi ,

if i have tiddlers tagged with Tag1 and have field1
and tiddlers tagged with Tag2 that have field1 and field 2

can i run a filer that would do the follwoing

for each tiddler tagged with Tag1, find all Tag2 tiddlers that have a smaller value in field 1 ,then sum their field 2 values

so for example

  • Tiddler A Tags= Tag1 Field1= 2
  • Tiddler B Tags= Tag1 Field1= 1
  • TIddler C Tags= Tag1 Field1= 4
  • Tiddler D Tags= Tag2 Field1= 3 Field2=1
  • Tiddler E Tags= Tag2 Field1= 1 Field2=1
  • Tiddler F Tags= Tag2 Field1= 1 Field2=2

1.TiddlerA has a higher value in Field1 compared to TIddlerE and Tiddler F but not TiddlerD , so the filter should return 3 (sum of field2),
2.Tiddler B has a value in field1 that is not greater than any tiddlers tagged with Tag2 so it should evaluate to 0
3.tiddler C has a value in field 1 greater than all tiddlers tagged with tag2 , so it should evaluate to 4

i have done this

<$set name= "var1" filter = "[tag[tag1]get[field1]]">

<$list filter ="[tag[tag2]] :filter[get[field1]compare:number:lt<var1>] :and[get[field2]sum[]]" variable = "var2">

it doesnt work , is it possible to do this ?, so can i have the result come as 3 0 4
for which i might even sum[] them together if i choose to ?

thank you verymuch

We should be able to find an answer to do this, but before putting more time into it, I think there is value reconsidering the design that is resulting in your need to do this. I recall you asked a similar question in the past where you are in someways forcing yourself to do gymnastics with tiddlywiki where a different design approach could avoid this question altogether.

  • Also providing the test data against which to test the solution would be helpful otherwise anyone that tries to help has to create that test data.
  • Also consider exposing the real world data (even if dummy data) you are trying to manage rather than abstract tagsN and FieldN names and simple integer values because it becomes too abstract for people to easily visualise.
    • If you are trying to hide Intellectual property be aware you are publicly showing and requesting help with the algorithm that is going to drive it.
  • There is a strong possibility that you have made a design error outside of the information you have presented to us, and an answer to this question will not solve the bigger picture.
    • I say this based on decades of experience.

Thanks tones,

no i am not really trying to hide anything, except , perhaps my ignorance:)

but , i have put some dummy data in https://greedy-lump-20.tiddlyhost.com/
i have also put together this diagram that hopefully might explain what i want , does it make sense to you ?
what i want is for the compare operator to take the first value in the first list and evaluate it against all other values in the second list , then returns from the second list all the values that pass the evaluation

then

do the same for the second value in the first list , then the third and so forth

@paulgilbert2000 perhaps others can contribute now you have spelt it out more clearly however I will assist later in my day.

Observations (tell me if I am incorrect);

  • This is effectivly one list nested in another, the first list runs off and gets its values in a second list for each member of the first list (with a condition).
  • You want to accumulate the results of each item the second list.
  • You want to accumulate the above result for all items in the first list, presenting a grand title.

I would be tempted to use nested list widgets however widgets in effect “only display outputs” so it is difficult to accumulate values. However lists are also sets and we can use filters and variables to “accumulate values” accross multiple widget invocations, but you need to concider;

  • Because you want a numeric total for all matching tiddlers you need not retain the tiddler titles, but you have to make sure;

Some filter operators remove duplicate items which can cause unexpected results when using the mathematics operators. See Dominant Append for details.

TiddlyWiki script is not a procedural programing language, we cant define a variable that is added to by all child processes, so somehow we need to collect the results of the inner lists and give them to the outer lists, to do the final sum.

  • We need a trigger to set values in fields so if you are happy with a click to sum we could make a batch process to compute the current value, because we can set a field to collect found values. Using actions.