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
@@ -9,7 +9,7 @@ AIMsight anomaly detectors (Python 3, standard library only) and their benchmark
|
||||
- The measurements are read by `scripts/data.py` of the tools repository, the sibling `~/aimsight-tools` (`categories.py` puts it on the path); a reading fix is made there.
|
||||
- Label files (JSONL): `id`, `start`, `end`, `family`, `description` (and `review`, `analysis`); the project uses `labeling/auto` only.
|
||||
- Two repositories use this one through a `detectors -> ~/aimsight-detectors` link (one copy on the workstation: a commit here is live for both at once); a rename here needs the matching change there:
|
||||
- aimsight-app: `categories.events`, `categories.CATEGORIES` (`process`: `images`, `none`, `check`), the event fields (`start`, `end`, `category`, `text`, `sensors`, `ignore`, `episodes`), the `--from/--to` CLIs, `bench/score.py` (the command shown in the page);
|
||||
- aimsight-app: `categories.window` (the events of a range, with its history), `categories.CATEGORIES` (`process`: `images`, `none`, `check`), the event fields (`start`, `end`, `category`, `text`, `sensors`, `ignore`, `episodes`), the `--from/--to` CLIs, `bench/score.py` (the command shown in the page);
|
||||
- Optimizer (`optimize` skill and its agents): `scripts/categories.py --from/--to`, `bench/` (`score.py`, `regression.py`, `compare.py`, `sensors.py`); its upgrader changes `scripts/*.py` and `thresholds.md`, one commit per fix.
|
||||
|
||||
## Rules
|
||||
|
||||
@@ -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