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
collect_if --- seeking greater efficiency (Read 4466 times)
Loryn
Full Member
*
Offline



Posts: 97

collect_if --- seeking greater efficiency
Jun 17th, 2008, 7:19am
 
In an Agent Action, I use the following pattern:

Code:
Field1(agent) = count(collect_if(child,$TextFrom="Number1",$Name));
Field2(agent) = count(collect_if(child,$TextFrom="Number2",$Name));
Field3(agent) = count(collect_if(child,$TextFrom="Number3",$Name));
TermScore(agent) = ($Field1*2) + ($Field2*1) + ($Field3*0.5)
 



Is there a more efficient way of writing this code? It seems horribly inefficient that I create a set simply to count the number of entries within it.

I notice the manual (for 4.2.4) documents sum_if. Is there a count_if function available? Or is there some other way I can conditionally count the child-aliases returned by the agent?
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: collect_if --- seeking greater efficiency
Reply #1 - Jun 17th, 2008, 11:46am
 
If you might have other uses for a list of notes that meet the collect_if criterion, you could simple make several auxilliary agents with the query

    TextFrom="..."

Alternatively, you could keep each of the sets around in separate attributes

       Set1=collect_if(child,$TextFrom="Number1",$Name);

perhaps running this action in a low-priority agent.  Then, you could update

     Field1=count(Set1)

This is probably better for debugging and reuse -- and it lets you separate parts of the work into agents (which have adjustable priorities) and other parts into rules (which are constantly updated)



I'm not even certain that count_if would be more efficient in your case.
Back to top
 
 
WWW   IP Logged
Loryn
Full Member
*
Offline



Posts: 97

Re: collect_if --- seeking greater efficiency
Reply #2 - Jun 17th, 2008, 4:31pm
 
Thanks, Mark.

You're right your suggested version being better for maintenance and debugging.

Should I need to perform any other query on these children, I will certainly refactor the code along the lines you suggest.
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print