All,
I’ve been playing around with some code today to trace a given railroad line in a contiguous fashion from one station to the next and putting the results in a table (see code & example output below). So far, so good. Note: each track segment is in its own tiddler with a tag of trackage and a tag of the railroad that built that segment. Each tiddler has a “to” field and a “from” field to hold the names of the ends of the segment.
One of the things I’ve been trying to figure out this afternoon is how to sum all of the mileages to have a total length. I have not been able to find a way to do this yet. I’ve been looking at the reduce filter run prefix and the accumulator variable, but I don’t think that will work in this case because I’m entering and exiting the list widget multiple times.
For a railroad that has a single, contiguous line summing the mileages is easy because I would just sum up all of the trackage tiddlers in a separate step. However, there are many times where a railroad has branches that go off in different directions or the railroad has several disjointed segments. The included procedure does not handle these cases so I’m trying to think ahead. The included procedure also only handles one direction (does not handle starting in the middle).
I’m looking for assistance in how to:
- Extend this procedure to branches and disjointed segments.
- Sum the mileage for a given segment.
Thanks very much for reading and any suggestions you may have. Please let me know if you have any questions or I need to include something else.
\procedure trace-forward(trackage)
<$let
company={{{ [<trackage>get[company]] }}}
nextfrom={{{ [<trackage>get[to]] }}}
>
<$list filter="[tag[trackage]company<company>from<nextfrom>track[C]]">
<tr>
<td><$transclude $tiddler=<<currentTiddler>> $field="from" /></td>
<td><$transclude $tiddler=<<currentTiddler>> $field="to" /></td>
<td style="text-align: right; padding-right: 1em;"><$transclude $tiddler=<<currentTiddler>> $field="mileage" /></td>
<td><$transclude $tiddler=<<trackage>> $field="date" /></td>
</tr>
<$transclude $variable="trace-forward" trackage=<<currentTiddler>> />
</$list>
</$let>
\end
\procedure trace(trackage)
<table style="caption-side: top;">
<caption style="text-align: left;">Construction trace:</caption>
<tr>
<th>From</th>
<th>To</th>
<th>Miles</th>
<th>Completed</th>
</tr>
<tr>
<td><$transclude $tiddler=<<trackage>> $field="from" /></td>
<td><$transclude $tiddler=<<trackage>> $field="to" /></td>
<td style="text-align: right; padding-right: 1em;"><$transclude $tiddler=<<trackage>> $field="mileage" /></td>
<td><$transclude $tiddler=<<trackage>> $field="date" /></td>
</tr>
<$transclude $variable="trace-forward" trackage=<<trackage>> />
</table>
\end