Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Distributing a list into groups - Automatically (Read 3519 times)
Rodney
Full Member
*
Offline



Posts: 38

Distributing a list into groups - Automatically
Jun 17th, 2011, 9:59pm
 
I have been working on a concept to automatically distribute a list into groups. In my particular case I was wanting to have a list distributed for certain tasks each day of the month. I wanted to be able to add or take away from the master list and have this automatically reflected in the groups (you can also add or take away the number of groups).

I am sure there are others who have done something similar but thought I would post this since I have learned so much from others talking about their usages for Tinderbox. Here is the link to a template file.

http://bit.ly/kFYrcT

I have copied in below a brief explanation that you can also find in the template file linked above.

I look forward to hearing comments and further suggestions.

Goal:
To be able to equally distribute a list of notes into a set of groups. This must be done in such a way that items can be added or removed and groups can be added or moved.

Process:

Finding the number of notes for each group:    see note: Primary Factor

Because there is not a floor function (can not force to always round down) the following code is required to find the distribution for each group before calculating with the remainder

$TestResult=($ChildCount(/Master List))/($ChildCount(/Groups)); $PrimaryFactor=round($TestResult);  if($PrimaryFactor>$TestResult) {$PrimaryFactor=$PrimaryFactor-1;};

Here is the calculation for the number remaining after equal distribution:
$Remainder=$ChildCount(/Master List)-($PrimaryFactor)*($ChildCount(/Groups))

The next step is to establish the sibling order range for each group: see agent: proto_group

Here we bring the PrimaryFactor already calculated from the note:
$PrimaryFactor=$PrimaryFactor(PrimaryFactor);

Next we have to establish if this group requires an extra note to take care of the remainder:
if($SiblingOrder<=$Remainder(PrimaryFactor)) {$AdjustedFactor=($PrimaryFactor+1)} else{$AdjustedFactor=$PrimaryFactor};

Now we can establish the range for each group (this is calculated by looking at $SiblingOrder)
if($SiblingOrder=1) {$LowerLimit=1} else {$LowerLimit=$UpperLimit(previousSibling)+1}; $UpperLimit=($LowerLimit+$AdjustedFactor)-1

Finally this is the Agent Query which gathers the notes for each group

$Name(parent)=="Master List"&($SiblingOrder>=$LowerLimit(agent))&($SiblingOrder<=$UpperLimit(agent))
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Distributing a list into groups - Automatically
Reply #1 - Jun 18th, 2011, 1:13pm
 
Nice, and thanks for sharing the demo too. Might help better show off your results if you gave the proto_Group prototype this display expression:

$Name+"  ("+$ChildCount+")"

That way, if the user adds a few notes to "Master List" the effect is visible immediately in the outline.

As shown in demos in a couple of other recent threads, if doing long rules, queries etc., it can be useful to put the code in a note (using the build-in "code" prototype) for easy editing. In which case use the code note's Rule to set the target notes attribute. Thus if you put the query for proto_Group into a code note, then the latter's Rule would be:

$AgentQuery("proto_Group) = $Text.

THe latter approach is not a requirement or even necessarily best practice. It's just been my experience that once I'm using more than short snippets of code a 'code note' approach helps so much, especially were testing/tweaking is required.
Back to top
 
« Last Edit: Jun 18th, 2011, 1:13pm by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Rodney
Full Member
*
Offline



Posts: 38

Re: Distributing a list into groups - Automatically
Reply #2 - Jun 19th, 2011, 7:12pm
 
Thanks for your interaction Mark. I hadn't thought of the putting in a $childcount but can see why it could be handy.

I had forgotten about the suggestion for linking rules & queries to a note's text. I like this and will have to implement it more.

I also forgot to mention Mark B's assistance in helping me figure out the trick to round down.
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print