Add example: export events for external workflow-mining tools - #122
aashnology wants to merge 2 commits into
Conversation
Adds examples/export_for_workflow_mining.py, which reuses the existing
categorizing + AFK-filtering canonical query (same approach as
load_dataframe.py) and writes a flat, sorted JSON list of
{timestamp, duration, data} records -- the minimal shape a downstream
sequence-clustering or process-mining tool needs, without every raw
watcher heartbeat a full bucket dump would include.
Passes ruff, mypy, and py_compile with the repo's existing config.
README updated to list it alongside the other examples.
|
| {"timestamp": e["timestamp"], "duration": e["duration"], "data": e["data"]} | ||
| for e in data[0]["events"] | ||
| ] | ||
| events.sort(key=lambda e: e["timestamp"]) |
There was a problem hiding this comment.
| with open(args.out, "w") as f: | ||
| json.dump(events, f, indent=2) |
There was a problem hiding this comment.
Failed writes damage prior exports Opening the output path with
"w" immediately truncates any existing export. If serialization fails or the process is interrupted, the previous complete file is left empty or partial. Write to a temporary file and replace the destination only after the export succeeds.
| if __name__ == "__main__": | ||
| main() |
There was a problem hiding this comment.
Export path lacks test coverage The examples test target runs other scripts, but only imports this one; the
__main__ guard means it never executes the query or writes JSON. A broken export could therefore pass the existing checks. Add a test or example-test invocation that checks the resulting JSON.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
- sort by iso8601.parse_date(), not the raw timestamp string: two valid ISO8601 timestamps using different UTC offsets can sort backwards as strings even though one is unambiguously earlier once parsed - write via a temp file + os.replace() so a failure partway through serialization can't leave a truncated file in place of a prior good export - add test_* functions (matching suggest_categories_gpt.py's convention) covering the query-building, sorting, field-filtering, and atomic-write behavior -- runnable via 'make test-examples'
Adds
examples/export_for_workflow_mining.py, which reuses the existing categorizing + AFK-filtering canonical query (same pattern asload_dataframe.py) and writes a flat, time-sorted JSON list of{timestamp, duration, data}records — the minimal shape a downstream sequence-clustering or process-mining tool needs, without every raw watcher heartbeat a full bucket dump would include.Tested against the repo's own tooling: passes
py_compile,ruff check, andmypywith the existing config. README updated to list it alongside the other examples.