#Values and timestamps
Every value in eLucid8 has a timestamp. A result is a pair: its data (a number, a boolean, eod or an error) and a time in milliseconds. For data that came from outside, the timestamp is the time the data give: when a reading was taken, or when it arrived. For a computed value, it is the latest timestamp of everything the value was computed from. So every answer says how recent the newest data behind it are.
This page gives the rules, how outputs carry timestamps, and three uses: leakage checks in feature tables, end-to-end alarm latency, and data freshness. Every example is in the language's notation v0.2, is checked by a test (packages/evaluator/test/timestamps.test.ts), and runs as written in the playground, as the Tutorial describes: -- table x = … is a table whose rows are separated by ;, and an answer ends with , at time N ms when its timestamp is not 0.
#Where timestamps come from
- A time column. In the playground, a table may have a
tscolumn: each row's timestamp in milliseconds. In a deployment, an input's entry names its column with"time": "ts"(or another column's name; for JSON lines, a field). A row with no time (an empty cell, ornull) has timestamp 0. - Times by coordinate. When an input's timestamps are a function of one of its coordinates, such as a reading every second, a deployment says so instead of listing them:
"time": { "dimension": "tick", "everyMs": 1000 }gives the data at tick k the timestamp k × 1000. A list of times ("timestamps": [...]), or a CSV or JSON-lines file of them, may be given instead ofeveryMs(Command reference). - 0 otherwise. Data without times, constants such as
1, and coordinates such as#thave timestamp 0.
#How operators combine them
| expression | its timestamp |
|---|---|
a constant, a coordinate #d, the literals eod and error("…") | 0 |
| data from an input | the data's |
an operator (+, <, and, not, …) or a maths function | the latest of its operands' |
if c then a else b | the latest of the condition's and the branch taken's (the other branch is not demanded, so it does not count) |
first.d e, next.d e, a fby.d b | the timestamp of the value read, unchanged |
y wvr.d q, y asa.d q, y upon.d q | the latest of the timestamps of every q the walk examined (eod and errors included) and, where y is read, of y at the position read (The walk of wvr, asa and upon) |
v[d = e] | the latest of the value read and the expressions giving its coordinates |
an aggregate (sum, mean, min, max, count) over a region | the latest of every element it combined and of the region's |
| the ends, counts and positions listed of a region, written inside an aggregate | counted in the aggregate's timestamp, with its elements |
time(e) | e's timestamp; its data is that timestamp too (where e is eod, time(e) is eod, with e's timestamp) |
iseod(e), iserror(e) | e's |
an input answered on demand (model[amount = x]) | its completion time: the question starts at the latest timestamp of the coordinates it is asked at, and is answered after the time the program took; a late result, the deadline's time |
-- How timestamps combine.
a = input("a", t : 4)
b = input("b", t : 4)
s = a + b
c = if a > 1 then b else 0
total = sum a over (t : 0 .. 1) end
when = time(a)
later = time(a) + 1
-- table a = t,value,ts; 0,1,100; 1,2,200; 2,4,300; 3,5,400
-- table b = t,value,ts; 0,0,1000; 1,3,2000; 2,1,3000; 3,2,4000
-- expect s[t = 0] = 1, at time 1000 ms
-- expect c[t = 0] = 0, at time 100 ms
-- expect c[t = 1] = 3, at time 2000 ms
-- expect total = 3, at time 200 ms
-- expect when[t = 1] = 200, at time 200 ms
-- expect later[t = 1] = 201, at time 200 ms
c at t = 0 takes the else branch: the condition read a at 100 ms, and the constant 0 has no time, so its timestamp is 100. At t = 1 it takes b, at 2,000 ms.
#eod and errors
eod and error have timestamps too:
- eod with timestamp 0: the literal
eod; a point where the data have no row; a point outside a value's bound; a coordinate below 0. An error literal,error("…"), has timestamp 0 too, soif reading > 100 then error("too high") else readingis stamped with the reading's time. - The data's timestamp: an eod or error that a row of the data gives (a row whose value is
error: message, oreod, which a table writes only as the last row of a line along a dimension declaredinf). - The operator's timestamp: an eod or error that propagates through an operator takes the operator's timestamp, the latest of its operands', like any other result.
-- eod and errors with timestamps.
a = input("a", t : inf)
b = input("b", t : 4)
s = a + b
ended = iseod(a)
-- table a = t,value,ts; 0,1,100; 1,2,200; 2,error: sensor fault,300; 3,eod,400
-- table b = t,value,ts; 0,0,1000; 1,3,2000; 2,1,3000; 3,2,4000
-- expect a[t = 3] = eod, at time 400 ms
-- expect a[t = 9] = eod
-- expect s[t = 3] = eod, at time 4000 ms
-- expect s[t = 2] = error data from a[t = 2]: sensor fault, at time 3000 ms
-- expect ended[t = 3] = true, at time 400 ms
#Choosing data by its timestamp: asof, hold, window
Three operators look along a value's dimension d for data by its timestamp, so that streams at different rates, or driven by events, can meet:
asof.d v at T endisvat the point alongdwith the latest timestamp at or beforeT.hold.d v at T within M endis the same, but steps back over eod points (never over an error) to the latest data, and only among data less thanMmilliseconds older thanT, with timestamps in (T − M, T]; if there are none, it gives missing data when data lie both before that window and afterT(the data stopped and resumed), and eod otherwise. It isasof.d v at T within M skip eod end, andwithin Mandskip eodcan also be written onasofitself, and onlatest, which is stale the same way.sum v over (d : window.d w at T) end, a window, aggregatesv's data with timestamps in thewmilliseconds up toT, that is in (T − w, T];mean,countand the other aggregates reduce it as they reduce any region: if any of them is eod, so is the result, unless the aggregate saysskip eod. Its timestamp is the latest in the window, andT's andw's.
Two more operators give a position instead of a value: latest.d v at T end is the last position along d where v has data with a timestamp at most T (eod if there is none), and after.d v at T end the first position whose timestamp is later than T (eod if there is none). Durations can be written with a unit, 250ms, 30s, 5min, 2h, 1d, 1w, and moments as utc("2026-10-18T12:00:00Z").
Points where v has no data (no row) are never chosen. When two points have the same timestamp, the later one along d wins. The result's timestamp is the latest of the data chosen and of T's own timestamp. The Tutorial shows the three side by side (section 9); the uses below show them at work.
The points along d need not be in timestamp order: each operator chooses by timestamp, wherever a point sits. A point with no row is skipped, but a row whose value is eod is data: asof can choose it and give eod, while hold steps back past it. With calibrations 1.05 at 230 ms and eod at 380 ms, asof at 390 ms gives eod (timestamp 380), and hold with a maximum age of 200 ms gives 1.05 (timestamp 230).
If you know pandas: asof is merge_asof with direction="backward"; hold is closer to Series.asof, which skips missing values, together with merge_asof's tolerance; window is a time-based rolling window. Unlike pandas, eLucid8 does not need the data sorted by time.
#Timestamps in outputs
The elucid8 command writes each result with its timestamp, except in CSV, where timestamps are written only when asked: --timestamps on the command line, "timestamps": true in the configuration's output or on an output, or timestamps=True in the Python package (Command reference). A CSV file is often read by people and spreadsheets, and a file read and written back should look the same; the other formats are mostly read by programs, which then get the timestamps of what they read, unless --no-timestamps or "timestamps": false leaves them out. With this program, data and deployment configuration:
x = input("x", t : 6)
running = x fby.t running + next.t x
t,value,ts
0,3,1000
1,1,2000
2,4,3000
3,0,4000
4,5,5000
5,9,6000
{ "format": "elucid8-deploy/2",
"inputs": { "x": { "from": "x.csv", "time": "ts" } },
"queries": [ "running[t = 3..5]" ] }
JSON lines (the default) carry
tsin each outcome, after its data, when it is not 0:{"name":"running","context":{"t":3},"outcome":{"kind":"value","value":8,"ts":4000}} {"name":"running","context":{"t":4},"outcome":{"kind":"value","value":13,"ts":5000}} {"name":"running","context":{"t":5},"outcome":{"kind":"value","value":22,"ts":6000}}CSV (
--format csv) has no timestamps unless asked:name,t,running_value,running_kind,running_message running,3,8,value, running,4,13,value, running,5,22,value,With
--timestamps, arunning_tscolumn after them:name,t,running_value,running_kind,running_message,running_ts running,3,8,value,,4000 running,4,13,value,,5000 running,5,22,value,,6000Apache Arrow and Apache Parquet have an
int64running_tscolumn, one per row.Frames (
--format frame) have atsentry. Where every cell's timestamp is a function of its coordinate on one axis, as here, it is written once per coordinate of that axis,{"axis": …, "values": […]}; otherwise it is one timestamp per cell:{"name":"running","axes":[{"name":"t","range":[3,5]}],"type":"number","values":[8,13,22],"kinds":[0,0,0],"kindNames":["value","eod","error"],"ts":{"axis":"t","values":[4000,5000,6000]},"errors":{}}NumPy
.npzhasrunning_ts.npy, 64-bit integers. Where the timestamps are a function of one axis, it has size 1 along every other axis, so it broadcasts againstrunning_value.npy, andframe.jsonnames the axis ("tsAxis").Records (an output's rows, whether the program names it or
deploy.jsonlists it) have a timestamp column per channel,<channel>_ts, in Arrow, Parquet and.npz, and in CSV when asked ("timestamps": trueon the output); in JSON lines each outcome carries itsts.
The Command reference describes every format.
#What timestamps are good for
#Leakage checks in feature tables
A feature for a model must be computed only from data before the moment it describes: a feature "as of midnight" that read a purchase made at noon leaks the future into training. The timestamp of each feature is the latest purchase it read, so a check is one comparison: time(feature) must not be after the cut-off.
-- A leakage check: a feature's timestamp must not be after its cut-off.
spend = input("spend", customer : 2, hour : 72)
day_spend = restrict sum spend over (hour : window.hour 86400000 at #day * 86400000) end
to (customer : 2, day : 3) end
same_day = restrict sum spend over (hour : window.hour 86400000 at (#day + 1) * 86400000) end
to (customer : 2, day : 3) end
leak = restrict time(day_spend) > #day * 86400000
to (customer : 2, day : 3) end
leak_same_day = restrict time(same_day) > #day * 86400000
to (customer : 2, day : 3) end
leaks = count 1 over (customer : 0 .. 1, day : 0 .. 2) if leak end
leaks_same_day = count 1 over (customer : 0 .. 1, day : 0 .. 2) if leak_same_day end
-- table spend = customer,hour,value,ts; 0,5,10,18000000; 0,30,20,108000000; 1,26,7,93600000; 0,50,4,180000000
-- expect day_spend[customer = 0, day = 2] = 20, at time 108000000 ms
-- expect leak[customer = 0, day = 2] = false, at time 108000000 ms
-- expect same_day[customer = 0, day = 1] = 20, at time 108000000 ms
-- expect leak_same_day[customer = 0, day = 1] = true, at time 108000000 ms
-- expect leaks = 0, at time 108000000 ms
-- expect leaks_same_day = 4, at time 180000000 ms
Each purchase's timestamp is its hour's time (hour × 3,600,000 ms). day_spend sums a customer's purchases in the 24 hours up to midnight at the start of the day (day × 86,400,000 ms): no feature reads anything after its cut-off, so leaks is 0. same_day sums the day itself: four of its six features read purchases made after their day's midnight, and the check finds all four. The check needs no knowledge of how a feature was computed; it would find a leak through any chain of values, since timestamps travel through every operator.
#End-to-end alarm latency
When data carry the time they arrived, an alarm's timestamp is the arrival of the last reading it needed: the earliest moment the alarm could have been raised. Its latency from the moment the readings were taken follows by subtraction.
-- End-to-end latency: when the last reading an alarm needed arrived.
reading = input("reading", t : 3, x : 3)
level = mean reading over (x : #x - 1 .. #x + 1) end
alarm = level > 50
latency = time(alarm) - #t * 1000
worst = max latency over (t : 0 .. 2, x : 0 .. 2) end
-- table reading = t,x,value,ts; 0,0,40,20; 0,1,55,250; 0,2,70,40; 1,0,45,1030; 1,1,60,1900; 1,2,65,1050; 2,0,50,2010; 2,1,48,2020; 2,2,52,2030
-- expect alarm[t = 0, x = 0] = false, at time 250 ms
-- expect alarm[t = 1, x = 2] = true, at time 1900 ms
-- expect latency[t = 1, x = 2] = 900, at time 1900 ms
-- expect worst = 900, at time 2030 ms
Three sensors (x 0 to 2) take a reading each second (tick t at t × 1,000 ms), and each reading's timestamp is when it arrived. The alarm at sensor 2, tick 1 reads its neighbours: sensor 1's reading arrived 900 ms late, at 1,900 ms, so the alarm could not be raised before then. worst is the largest latency over the whole block.
#Data freshness with hold's maximum age
hold's within is how old the data it uses may be. A value that must not act on stale data says so, and gets missing data instead while the readings have stopped, or eod past the newest reading:
-- Freshness: the latest reading, if it is at most 2.5 s old.
r = input("r", t : 10)
fresh = restrict hold.t r at #k * 1000 within 2500 end
to (k : 10) end
age = restrict #k * 1000 - time(asof.t r at #k * 1000 end)
to (k : 10) end
seen = restrict latest.t r at #k * 1000 within 2500 end
to (k : 10) end
-- table r = t,value,ts; 0,1,0; 1,2,1000; 2,3,2000; 6,7,6000
-- expect fresh[k = 3] = 3, at time 2000 ms
-- expect fresh[k = 5] = error missing: hold: no data within 2500 ms before 5000, at time 2000 ms
-- expect fresh[k = 6] = 7, at time 6000 ms
-- expect age[k = 3] = 1000, at time 2000 ms
-- expect age[k = 5] = 3000, at time 2000 ms
-- expect seen[k = 3] = 2, at time 2000 ms
-- expect seen[k = 5] = error missing: latest: no data within 2500 ms before 5000, at time 2000 ms
The readings stop after 2,000 ms and resume at 6,000 ms. At 3,000 ms (k = 3) the latest reading is 1,000 ms old, and fresh uses it. At 5,000 ms it is 3,000 ms old, beyond 2,500, so fresh is missing data: no reading lies in the 2,500 ms up to 5,000 ms, while readings lie before them and after them (an error of kind missing, stamped with the last reading's time, 2,000 ms). A window wholly past the newest reading, or before the first, is outside the data: eod there. age gives the age itself. seen, the position of the reading fresh uses, is stale the same way: latest … within M is missing data where hold is.
#Where the idea comes from
Wadge and Yoder argued for timestamps on both requests and responses in a demand-driven system, and noted that "this is not the same as adding extra time dimensions" (W. Wadge and A. Yoder, "The Possible-World Wide Web", in M. A. Orgun and E. A. Ashcroft (eds.), Intensional Programming I, World Scientific, 1996, §7, pp. 210–211). eLucid8 does the same: a value's timestamp is not a coordinate, and time stays out of its dimensions. The difference is what a timestamp says. In their proposal, a page's timestamp is an interval of validity, the times between which the page stays the same. In eLucid8 it is one time, the time of the newest data the value was computed from.
#See also
- Tutorial, section 9: timestamps and alignment, step by step.
- Time and real time in eLucid8: logical time, timestamps and deadlines.
- Command reference: inputs with times, and every output format.