categories.window: the events of a range with its history, for aimsight-app and the CLI (figures unchanged, +3 code lines)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a008ea8fcc
commit
428ebaacfe
2 files changed
+9
-4
No files matched your search
@@ -108,6 +108,13 @@ def events(measurements, end=None, folder=None):
|
||||
return classify(episodes)
|
||||
|
||||
|
||||
def window(measurements, start, end, history=timedelta(days=3)):
|
||||
"""The events of [start, end) (UTC datetimes), the detectors given `history` of earlier measurements too (the rule of
|
||||
the CLI below): those ending at or after start. For a caller (aimsight-app) as for the CLI."""
|
||||
chunk = {s: k for s, ms in measurements.items() if (k := [m for m in ms if start - history <= m["t"] < end])}
|
||||
return [v for v in events(chunk, end) if v["end"] >= iso(start)] if chunk else []
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
p = argparse.ArgumentParser(description="One line per event; --chunk: each chunk classified alone.")
|
||||
@@ -128,9 +135,7 @@ if __name__ == "__main__":
|
||||
t = start
|
||||
while t < end:
|
||||
b = min(t + timedelta(days=a.chunk), end) if a.chunk else end
|
||||
h = t - timedelta(days=a.history)
|
||||
chunk = {s: k for s, ms in measurements.items() if (k := [m for m in ms if h <= m["t"] < b])}
|
||||
evs = [v for v in events(chunk, b, a.folder) if v["end"] >= iso(t)] if chunk else []
|
||||
evs = window(measurements, t, b, timedelta(days=a.history))
|
||||
if a.chunk:
|
||||
print(f"== {iso(t)} → {iso(b)}: {len(evs) or 'nothing'}")
|
||||
for v in evs:
|
||||
|
||||
Reference in new issue
Block a user