Skip to content

Instantly share code, notes, and snippets.

@mmichaelb
Last active March 31, 2023 09:27
Show Gist options
  • Save mmichaelb/25ae920b4b2dded536690851e8fcb813 to your computer and use it in GitHub Desktop.
Save mmichaelb/25ae920b4b2dded536690851e8fcb813 to your computer and use it in GitHub Desktop.
ActivityWatch Stopwatch Aggregation Cheat Sheet

Stopwatch related Aggregation Cheat Sheet

Gather the data from ActivityWatch

Select the time range and type in the following command

stopwatch_events = query_bucket(find_bucket("aw-stopwatch"));
RETURN = stopwatch_events;

Save them to a file named stopwatch.json and use the following jq-commands to gather data.

Enrich data with a date field

jq < stopwatch.json 'map(. + {"date":(.timestamp | capture("(?<time>\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})") | .time + "Z" | fromdate | strftime("%Y-%m-%d"))})' > stopwatch-date-added.json

Retrieve total duration of results

jq < stopwatch.json 'group_by(.data.label) | map(.[0] + {"count": length, "duration": (map(.duration) | add)}) | map(. + {"hours": (.duration / 60 / 60 | tostring | capture("(?<number>\\d+\\.{0,1}\\d{0,2})") | .number | tonumber)})'

Retrieve grouped duration of results grouped by day and project

jq < stopwatch-date-added.json 'group_by(.date,.data.label) | map(.[0] + {"count": length, "duration": (map(.duration) | add)}) | map(. + {"hours": (.duration / 60 / 60 | tostring | capture("(?<number>\\d+\\.{0,1}\\d{0,2})") | .number | tonumber)})' > stopwatch-grouped.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment