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
Pattern bar and percentage of a day (Read 5251 times)
Derek Van Ittersum
Full Member
*
Offline



Posts: 168

Pattern bar and percentage of a day
Mar 17th, 2011, 9:07am
 
Hi all,

I've recently begun using a time logging application for the iPhone which lets me export a CSV file of all my activities for a day, with the start and stop times.  Naturally, I thought it would be cool to turn this into a table in numbers, then dump into Tinderbox and plot it using the Timeline feature.  Works great!

Now I'd like to do some more visualizations, but am a bit stumped.  I'd like to plot a horizontal progress bar showing what percentage of a given time period (one day, one week, one month, etc.) was devoted to a particular activity.  Each note has a $StartDate and $EndDate.  I've collected notes into agents based on their names (notes are named by the activity--e.g., "write"; "net surfing"; etc.).  I'm thinking I can just apply the progress bar to the "net surfing" agent somehow and get a display that shows me what percentage of a day, week, etc. I've been doing that activity.  

Where I'm stuck is how to do the date math that will result in a number that can be plugged into the Pattern attribute.  Can dates be compared in this way?

Also--I'm not yet using the newest TBX version, but am planning to upgrade soon.  So if the answer is significantly different in past and present versions, I'll just upgrade immediately to the present and use that code.
Back to top
 
« Last Edit: Mar 17th, 2011, 9:08am by Derek Van Ittersum »  
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Pattern bar and percentage of a day
Reply #1 - Mar 17th, 2011, 9:35am
 
I'm on the way to the airport so I'll have to limit myself for now to hints. Some ideas:

a) play around with simply plugging in dummy numbers to see if your display is what you have in mind, and to get the hang of the pattern. For example, the $Pattern bar(50) is a 50% bar.

b) Simply subtracting dates gives you the different in days, which won't help you much. If your time logging program can give you an elapsed time in addition to $StartDate and $EndDate, that would be handy.

c) Yes, Tinderbox 5.8 has a bunch of improvements to the action language -- some inspired by your curricular experiment!  And the revised parser is far more predictable in its behavior. Upgrading is likely to save you some time.

d) The key to getting this right is to separate it into two parts. One part computes the elapsed time on the task, eventually generating a percentage from 0-100. The second part plugs that into a pattern: $Pattern="bar{"+$TaskTime+")"
Back to top
 
 
WWW   IP Logged
Derek Van Ittersum
Full Member
*
Offline



Posts: 168

Re: Pattern bar and percentage of a day
Reply #2 - Mar 17th, 2011, 10:53am
 
Thanks for the hints Mark.  I'm partway there:

I created a action that computes the duration in terms of minutes with this code:  

$MyDuration=minutes($StartDate,$EndDate)

So now I figure there's two steps left, both of which I'm having trouble figuring out.

I need to add up all the "MyDuration" values for a given activity.  This should be easy--I have all the "Net Surfing" (for instance) notes for a particular day captured in an agent.  How do I get the agent to add the values of MyDuration in all its children and spit out a number somewhere (maybe as $DurationTotal)?

Second, I need to use that number to create a percentage to display in the pattern.  Since we're working on minutes per day, it would be X/1440, right?  Can I do, for any given agent, the following:

$Pattern='bar("+$DurationTotal+"/1440*100)'
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Pattern bar and percentage of a day
Reply #3 - Mar 17th, 2011, 11:34am
 
I suggest that the container sum its children

    $DurationTotal=sum(children,$Duration)

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

User - not staff!

Posts: 5689
Southsea, UK
Re: Pattern bar and percentage of a day
Reply #4 - Mar 17th, 2011, 11:52am
 
For the $Pattern, you don't need to turn those number literals (e.g. 1440) to string literals by quoting them. Instead, use:

  $Pattern = "bar((($DurationTotal/1440)*100))"

I'm assuming $DurationTotal is a Number type field.  Note how I've use parentheses to guide order of execution. First, $DurationTotal is divided by 1440 to get the fraction of the day. That result is then multiplied by 100 to get a percentage which is then used by bar().

However, given that you don't store that percentage - it's only made to set bar() - you could use the alternate syntax: bar(value,min,max). This gives a simpler bit of code:

  $Pattern = "bar($DurationTotal,0,1440)"

As 0 equates to 0% and 1440 to 100%, $DurationTotal is therefore drawn as the percentage. Note that the whole bar() string is quoted as it's a pattern name like "cylinder" or "lines". Within it the arguments are all attribute references or literal numbers, neither of which need quotes.

The other, first, part of your question is hard to guess as you've described the data but not the context. If I understand it, the activity is the name of a note. Presumably one per activity? And per day? In other words, from what notes/agents are you drawing the data and where is it then presented.

For sake of argument, if each day is a container, why not make a table of activities & their duration and a container plot. Note though that you can't label the container plot but as (I assume) both the table and container plot have data drawn in $OutlineOrder order (unless otherwise actively sorted) then the table could act as a form of caption.

If your display is outline, don't forget Colour Swatches; the latter are bar() or vbar() pattern data drawn into the outline column where the link creation marker is drawn. That of course means you won't see the swatch for a selected note as the link creation widget replaces it temporarily.
Back to top
 
« Last Edit: Mar 17th, 2011, 11:56am by Mark Anderson »  

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



Posts: 168

Re: Pattern bar and percentage of a day
Reply #5 - Mar 17th, 2011, 4:05pm
 
Thanks so much for the help here.  I've got what I need to make it work and will share soon, but am now trying to automate things by creating self-referring agents that will let me make prototypes.

What I am attempting to make is a structure with a container note with the name of a particular day (e.g., $Name="3/15/11").  Within that container are agents that collect the notes representing each activity of the day.  Something like this:

3/15/11 (Container Note)
--Write (Agent)
----Write: $StartDate=3/15/11 10AM
----Write: $StartDate=3/15/11 12PM
--Net (Agent)
----Net: $StartDate=3/15/11 11AM

etc.
I have put the following into the Rule of the prototype Agent, but am not getting what I expect. I expect to get an Agent that looks for notes that have the same name as the Agent itself and notes that have the same StartDate as the name of the parent container.

$AgentQuery='(Name.contains("'+$Name+'"))&($StartDate=="$Name(parent)")'

I can post a file if that's easier, but hopefully there's just something obvious I'm missing with the Query code above.
Back to top
 
« Last Edit: Mar 17th, 2011, 4:06pm by Derek Van Ittersum »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Pattern bar and percentage of a day
Reply #6 - Mar 17th, 2011, 5:52pm
 
OK, I tested in tested in v5.8.0 but I provide an alternate solution for older versions.

In v5.8.0, set the prototype's $RuleDisabled to true before adding the Rule:

$AgentQuery='($Name.contains($Name(agent)))&($StartDate.format("l")==$Name(paren
t))'


Pre v5.8 there is no $RuleDisabled so you want to wrap the rule so it's not executed in the prototype:

if(!$IsPrototype){$AgentQuery='($Name.contains($Name(agent)))&($StartDate.format
("l")==$Name(parent))'}


Notes:

The new '.contains' attaches to an attribute reference. Thus $Name.contains("pattern") not Name.contains("pattern"). The whole idea is no more guesswork about when you leave off the $ to do a contains match to an attribute.

I'm assuming too the the day containers use a specific note format. I suggest making a prototype for the containers with the Rule:

$Name = $StartDate.format("l")

plus set $StartDate as a key adornment.

Back to top
 
« Last Edit: Mar 17th, 2011, 5:56pm by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print