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
finding "first unchecked child" (Read 2655 times)
leif
Full Member
*
Offline



Posts: 39

finding "first unchecked child"
Feb 19th, 2017, 10:42pm
 
I'm way out of practice with Tinderbox.  I need a query that matches the english "the first unchecked child of this note".  Any help appreciated.

Thanks!
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: finding "first unchecked child"
Reply #1 - Feb 20th, 2017, 7:20am
 
Are you asking for an agent to list the first unchecked child of all notes with checked children (or containers you've somehow (how?) indicated as needing to be in this query)? Are you expecting an agent that has just one match? Or, are you asking for the container notes to find the first unchecked item? If so, where is this info displayed.

You could just reverse sort the container on $Checked, so all checked items list at the end in outline order but I've a sense there may already be some sort of order applied.

You can't do an agent query and sort as you'd need to sort on $OutlineOrder(original) and $Sort doesn't support offset references.

There probably is a way to do what you want, if we can have a bit more info as to context, albeit possibly not via the means you envisaged. It would help to know which view you're using and the volume of data (finding things in a container of 5-10 items is a different from one with 1000 items).
Back to top
 
 

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



Posts: 39

Re: finding "first unchecked child"
Reply #2 - Feb 20th, 2017, 8:51am
 
Mark,
I'm trying to get a kind of note that inherits an attribute from one of its direct children (the top unchecked child in an ordered list).  Since I'm expecting to use the process often, but not to need the data for wider reuse, I expected to create a prototype with a rule/edict, rather than using an agent and then selecting within that agent's results.

Edit: found it!  Thanks!
Code:
$MyAttribute=collect_if(children,!$Checked,$MyAttribute).at(0) 

Back to top
 
« Last Edit: Feb 20th, 2017, 9:21am by leif »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: finding "first unchecked child"
Reply #3 - Feb 20th, 2017, 9:21am
 
Ah, that helps a lot. Try this as the container's $Rule:

$MyNumber=(collect_if(children,$Checked==false,$SiblingOrder)).sort.at(0);
$MyString = $Path(child[$MyNumber-1]);
$MyNumber=;


The container's $MyString will update to show the full $Path of the first un-ticked child note. If you just want the title, use $Name instead of $Path in the rule. In case there are many children, the $MyNumber=; code just purges $MyNumber each cycle so you don't save unnecessary data.

The $Path is set using a designator of the pattern child[N]. As $SiblingOrder numbers form 1 and child[N] from zero we need to nerf $MyNumber by one before use.

If you need $MyString and $MyNumber for other things just substitute a String-type and a Number-type user attribute of your choice.

I hope that helps.
Back to top
 
« Last Edit: Feb 20th, 2017, 9:21am by Mark Anderson »  

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



Posts: 39

Re: finding "first unchecked child"
Reply #4 - Feb 20th, 2017, 9:27am
 
Mark,

Thanks for your help.

I see you're using the ".sort" operator in your code.  IIRC, tha sorts the list alphabetically.  Since the child notes are already sequentially ordered, can I assume that "collect_if()" keeps that sequence?
Back to top
 
« Last Edit: Feb 20th, 2017, 9:27am by leif »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: finding "first unchecked child"
Reply #5 - Feb 20th, 2017, 10:35am
 
Sure, I tried sort in early tests and using a different target attribute.  Here, I should have used List.nsort(). In truth I think you can leave the sorting bit out as .at[0] should likely get you the number you want. Just bear it in mind in case you start seeing incorrect choices getting detected.

Quote:
can I assume that "collect_if()" keeps that sequence?


That's really the point. collect() and collect_if() return lists which retain creation order but we don't know the list creation order. Whilst likely [sic] to be $Out;lineOrder of matching items, I suspect that the more complex the filtering of group/if-condition, the greater the likelihood that you might need to sort. I think on reflection that I'd not sort and be open to the fact it may transpire that I need to.

This nuance aside, hopefully it's working on your data?
Back to top
 
 

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



Posts: 39

Re: finding "first unchecked child"
Reply #6 - Feb 20th, 2017, 8:51pm
 
Mark,
It is working, thank you.
Back to top
 
 
  IP Logged
Rob Forsyth
Full Member
*
Offline



Posts: 63

Re: finding "first unchecked child"
Reply #7 - Feb 25th, 2017, 5:30pm
 
Building on this thread a little, I'm working on a rostering project as an exercise-for-the-reader that has notes with custom attributes of $RotaDay (the date that needs cover allocated) and $RosterName (the person who will be assigned to cover that day. My intention is to automate this process by developing a rule that allocates a $RosterNames to the first un-allocated $RotaDay according to a score reflecting various factors such as how many days each person has done in the previous x months (so as to ensure a roughly equitable sharing of duties) and when that person was last rostered (so as to avoid them having a long run of days on continuous duty). I'm wrestling with how best to handle this and am currently wondering if it's possible to design an agent query that (analogously to the question in this thread) identifies the first note with a blank $RosterName  but also its previous x siblings (sorted by data order).

Having pulled the notes into an agent I think I can see how to develop a rule to calculate a score for each person on the rota along the lines above and then assign it to the note, so that the system will then move on to the next unallocated note
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: finding "first unchecked child"
Reply #8 - Feb 25th, 2017, 10:09pm
 
Whoah, Nelly!

You can get the nth child of an agent, and your note can get its own sibling order. So this can be done.

Or, you could write a new agent that picks off the unassigned note, and its N previous siblings. That might be cleaner.

Back to top
 
 
WWW   IP Logged
Rob Forsyth
Full Member
*
Offline



Posts: 63

Re: finding "first unchecked child"
Reply #9 - Feb 26th, 2017, 3:57am
 
It's the latter I'm trying to do. Sorry if that wasn't clear
Back to top
 
 
  IP Logged
Rob Forsyth
Full Member
*
Offline



Posts: 63

Re: finding "first unchecked child"
Reply #10 - Feb 28th, 2017, 11:16am
 
Again sorry if my previous question wasn't clear but I would appreciate a bit of a steer in formulating an agent query that will search another container in the outline for the first child (lowest $SiblingOrder) in that container meeting a criterion (in my case !$MyAttribute, i.e. my attribute is null) and collect in the agent that note but also the preceding n siblings (in $SiblingOrder) of that note

Thanks
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: finding "first unchecked child"
Reply #11 - Feb 28th, 2017, 12:19pm
 
I don't believe this sort of nested query is possible in one go.  You either need 2 agents (one for each task, second getting data from the first). Or use a single agent that takes 2 cycles  [sic] to evaluate. In pass #1 the agent's rule is run:

$MyNumber=(collect_if(find(inside("Some Container") & $IsAlias==false),$Checked==false,$SiblingOrder)).sort.at(0);


The agent's $MyNumber holds the sibling order number for the first un-checked child of container "Some container". The $IsAlias==false part is needed as find() doesn't de-dupe matches unlike an agent which aims to return only one match per note, only matching as alias if the latter is in scope and the original isn't; otherwise the original is taken as the only match.

The agent query is:

inside("Some Container") & $SiblingOrder(original)<$MyNumber(agent)

Remember this takes TWO agent/rule cycles to complete. Pass #1 sets the agent $MyNumber which is then used in the second pass. As long as the source isn't volatile, i.e. you're not playing with the tick-boxes at source, the query result should be stable after pass #2.

In truth, I sense one really shouldn't be doing this in a production task and certainly not as a demo/example shared with casual users. There is too much scope for hard-to-explain-to-a-novice issues in the outcome. I'd rate the above as for 'experienced driver on a closed track',
Back to top
 
 

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



Posts: 63

Re: finding "first unchecked child"
Reply #12 - Feb 28th, 2017, 2:27pm
 
OK thanks Mark! Will give it a whirl. Comments about not using in mission-critical settings duly noted!
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print