Skip to content

Add example: export events for external workflow-mining tools - #122

Open
aashnology wants to merge 2 commits into
ActivityWatch:masterfrom
aashnology:add-workflow-mining-export-example
Open

aashnology wants to merge 2 commits into
ActivityWatch:masterfrom
aashnology:add-workflow-mining-export-example

Conversation

@aashnology

Copy link
Copy Markdown

Adds examples/export_for_workflow_mining.py, which reuses the existing categorizing + AFK-filtering canonical query (same pattern as load_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, and mypy with the existing config. README updated to list it alongside the other examples.

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.
@greptile-apps

greptile-apps Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Low risk] Adds an example script and documentation.

The PR appears safe to merge, though the exporter has non-blocking ordering, file-preservation, and test-coverage issues.

Findings

  1. P2 Timestamps can sort incorrectly ▶
  2. P2 Failed writes damage prior exports ▶
  3. P2 Export path lacks test coverage ▶

Summary

Adds a command-line example that queries categorized, AFK-filtered window events and exports a flat JSON list, with a README entry. The timestamp ordering, destination write, and test coverage merit improvement.

Reviews (1) · Last reviewed commit: "Add example: export events for external ..."

Comment thread examples/export_for_workflow_mining.py Outdated
{"timestamp": e["timestamp"], "duration": e["duration"], "data": e["data"]}
for e in data[0]["events"]
]
events.sort(key=lambda e: e["timestamp"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Timestamps can sort incorrectly If returned events have different UTC offsets, such as across a daylight-saving change, sorting their timestamp strings can put them in the wrong time order. That gives downstream tools an incorrect event sequence. Parse or normalize the timestamps before sorting.

Comment thread examples/export_for_workflow_mining.py Outdated
Comment on lines +68 to +69
with open(args.out, "w") as f:
json.dump(events, f, indent=2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Comment on lines +74 to +75
if __name__ == "__main__":
main()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant