How Do I automatically keep track of my daily writing progress?

Here, is one solution (example file at end of post):

Constituent parts of solution:

  • The completion data is put in the title using a Display Expression
    • As the Display Expression involves some calculation and because you might run a number of these, it is more efficient to calculate the numbers and make up the overall string and store it, then make the dd just report that stored value.
    • Here we do the calculations in a rule but if running a lot of those , you could move the rule code to an edict instead (edicts can be force refreshed on remand and otherwise run on creation, on doc open and then once an hour)
  • Each note stores its word count in $WordCount (auto-calculated)
  • A container can fetch the total word count of its child notes via sum(), e.g. sum(children,$WordCount). Not used here but sum all descendants of the container use sum(descendants,$WordCount)

I used your sample TBX for the text, first using a ‘lipsum’ generation to make the desired number of words for each child note so the $WordCount is correct. to prove this look at the Display Expression for each child note, which is $Name+" "+$WordCount.

I then made 2 user attributes via the Inspector:

  • A Number-type TargetNumber. This holds the target word count you desire. this will be set in the container note where we do the calculation, but could be stored in, and referenced from, any note if you prefer.
  • A String-type ReportString. This holds the pre-calculated title that is used as the Display Expression
    • Thus our example container’s true $Name is “5000 Words” but due to the Display Expression we see “5000 Words (5000/3922) 78.44”

The rule is this:

// make variable to hold aggregate child word count
var:number vProgress = sum(children,$WordCount);
// make variable to hold that count as a % with 2 DPs
var:string vPct = ((vProgress/$TargetNumber)*100).format(2);
// start building ReportString value to use in Display Expression
// take existing title
$ReportString = $Name;
// add target number and actual count
$ReportString += " ("+ $TargetNumber+"/"+vProgress+") ";
// add percentage
$ReportString += vPct;

(N.B. this code in the demo file is not commented - it is only here for explanatory purposes)

Lastly, set the container note’s Display Expression to $ReportString in the Text Inspector:

As we’ve already calculated % progress, we can throw in a map view progress bar for free:

This is done by adding this to code to the end of the container’s rule:

$Pattern = "bar("+vPct+")";

I added a map view tab to the test doc so you can easily see this. Setting a pattern on the container does mean the container sub-map viewport is not shown. So, if you need the latter, don’t bother with the extra line of code.

Your example TBX with the above changes: Automatic word count and percentage statistics-demo.tbx (172.2 KB)

5 Likes