...
Code Block | ||
---|---|---|
| ||
ruleset timing_tracker { meta { shares entries } global { entries = function() { ent:timings.defaultsTo({}).values() } } rule timing_first_use { select when timing started or timing finished if ent:timings then noop() notfired { ent:timings := {} } } rule timing_started { select when timing started number re#n0*(\d+)#i setting(ordinal_string) pre { key = "N" + ordinal_string } if ent:timings >< key then noop() notfired { ent:timings{key} := { "ordinal": ordinal_string.as("Number"), "number": event:attr("number"), "name": event:attr("name"), "time_out": time:now() } } } rule timing_finished { select when timing finished number re#n0*(\d+)#i setting(ordinal_string) pre { key = "N" + ordinal_string } if ent:timings >< key then noop() fired { ent:timings := ent:timings.put({[key,"time_in"],} := time:now()) } } } |
Rule timing_finished
(lines 31-40) selects when the event with domain timing
and type finished
occurs, provided it has an attribute number
matching the regular expression in line 32. If it does, the rule is selected with ordinal_string
set to the number. In the rule prelude, a normalized key
is built from the ordinal value. If there is already a timing with that key
, the rule fires, performing no action, and in its fired
postlude sets (to the current time) an attribute time_in
on the map for that timing.
...