ActivityWatch / activitywatch

The best free and open-source automated time tracker. Cross-platform, extensible, privacy-focused.
https://activitywatch.net/
Mozilla Public License 2.0
11.86k stars 543 forks source link

web: non-afk time is not being properly tallyed up #687

Closed kewde closed 2 years ago

kewde commented 2 years ago

Describe the bug

The timeline barchart + time active of the activity view is under-reporting the actual hours. activitywatchbug activitywatchbughalffix

To Reproduce

Count up non-afk time for a day, compare it with what's shown in the "Activity view" under "time active".

Expected behavior

All Non-AFK time being properly tallyed

github-actions[bot] commented 2 years ago

Hi there! As you're new to this repo, please make sure you've used an appropriate issue template and searched for duplicates (it helps us focus on actual development!). We'd also like to suggest that you read our contribution guidelines and our code of conduct. Thanks a bunch for opening your first issue! 🙏

kewde commented 2 years ago

I noticed that the returned output of the HTTP request for /query doesn't include any events for the hour 4 PM. Either the query is broken or the query engine behind it is malfunctioning.

The 13th element (index 12) represents the 4PM column because Activity Watch starts counting from 4 AM. As you can see in the screenshot, it's empty. activitywatchbugquery

{
    "query": [
        "\n    events = flood(query_bucket(\"aw-watcher-window_DESKTOP-T3POCHP\"));",
        "\n\nnot_afk = flood(query_bucket(\"aw-watcher-afk_DESKTOP-T3POCHP\"));",
        "\n         not_afk = filter_keyvals(not_afk, \"status\", [\"not-afk\"]);",
        "\n\n    browser_events = [];",
        "\n  \nevents = filter_period_intersect(events, not_afk);",
        "\nevents = categorize(events, [[[\"Work\"],{\"type\":\"regex\",\"regex\":\"Google Docs|libreoffice|ReText\"}],[[\"Work\",\"Programming\"],{\"type\":\"regex\",\"regex\":\"GitHub|Stack Overflow|BitBucket|Gitlab|vim|Spyder|kate|Ghidra|Scite|VirtualBoxVM\"}],[[\"Work\",\"Programming\",\"ActivityWatch\"],{\"type\":\"regex\",\"regex\":\"ActivityWatch|aw-\",\"ignore_case\":true}],[[\"Work\",\"Image\"],{\"type\":\"regex\",\"regex\":\"Gimp|Inkscape\"}],[[\"Work\",\"Video\"],{\"type\":\"regex\",\"regex\":\"Kdenlive\"}],[[\"Work\",\"Audio\"],{\"type\":\"regex\",\"regex\":\"Audacity\"}],[[\"Work\",\"3D\"],{\"type\":\"regex\",\"regex\":\"Blender\"}],[[\"Media\",\"Games\"],{\"type\":\"regex\",\"regex\":\"Minecraft|RimWorld\"}],[[\"Media\",\"Video\"],{\"type\":\"regex\",\"regex\":\"YouTube|Plex|VLC\"}],[[\"Media\",\"Social Media\"],{\"type\":\"regex\",\"regex\":\"reddit|Facebook|Twitter|Instagram|devRant\",\"ignore_case\":true}],[[\"Media\",\"Music\"],{\"type\":\"regex\",\"regex\":\"Spotify|Deezer\",\"ignore_case\":true}],[[\"Comms\",\"IM\"],{\"type\":\"regex\",\"regex\":\"Messenger|Telegram|Signal|WhatsApp|Rambox|Slack|Riot|Discord|Nheko\",\"ignore_case\":true}],[[\"Comms\",\"Email\"],{\"type\":\"regex\",\"regex\":\"Gmail|Thunderbird|mutt|alpine\"}],[[\"Work\",\"Research\"],{\"type\":\"regex\",\"regex\":\"msedge|chrome\"}]]);",
        "\n\n    cat_events   = sort_by_duration(merge_events_by_keys(events, [\"$category\"]));",
        "\n    RETURN = { \"cat_events\": cat_events };",
        "\n  ;"
    ],
    "timeperiods": [
        "2021-11-10T04:00:00+01:00/2021-11-10T05:00:00+01:00",
        "2021-11-10T05:00:00+01:00/2021-11-10T06:00:00+01:00",
        "2021-11-10T06:00:00+01:00/2021-11-10T07:00:00+01:00",
        "2021-11-10T07:00:00+01:00/2021-11-10T08:00:00+01:00",
        "2021-11-10T08:00:00+01:00/2021-11-10T09:00:00+01:00",
        "2021-11-10T09:00:00+01:00/2021-11-10T10:00:00+01:00",
        "2021-11-10T10:00:00+01:00/2021-11-10T11:00:00+01:00",
        "2021-11-10T11:00:00+01:00/2021-11-10T12:00:00+01:00",
        "2021-11-10T12:00:00+01:00/2021-11-10T13:00:00+01:00",
        "2021-11-10T13:00:00+01:00/2021-11-10T14:00:00+01:00",
        "2021-11-10T14:00:00+01:00/2021-11-10T15:00:00+01:00",
        "2021-11-10T15:00:00+01:00/2021-11-10T16:00:00+01:00",
        "2021-11-10T16:00:00+01:00/2021-11-10T17:00:00+01:00",
        "2021-11-10T17:00:00+01:00/2021-11-10T18:00:00+01:00",
        "2021-11-10T18:00:00+01:00/2021-11-10T19:00:00+01:00",
        "2021-11-10T19:00:00+01:00/2021-11-10T20:00:00+01:00",
        "2021-11-10T20:00:00+01:00/2021-11-10T21:00:00+01:00",
        "2021-11-10T21:00:00+01:00/2021-11-10T22:00:00+01:00",
        "2021-11-10T22:00:00+01:00/2021-11-10T23:00:00+01:00",
        "2021-11-10T23:00:00+01:00/2021-11-11T00:00:00+01:00",
        "2021-11-11T00:00:00+01:00/2021-11-11T01:00:00+01:00",
        "2021-11-11T01:00:00+01:00/2021-11-11T02:00:00+01:00",
        "2021-11-11T02:00:00+01:00/2021-11-11T03:00:00+01:00",
        "2021-11-11T03:00:00+01:00/2021-11-11T04:00:00+01:00"
    ]
}
ErikBjare commented 2 years ago

Looks like a duplicate of https://github.com/ActivityWatch/activitywatch/issues/609, which is fixed in master (and available in nightly releases, see #507).

Not sure about the non-afk time not adding up though (might be related to the above issue, but not sure). If you could try a nightly build and report back that would be helpful!

Edit: the non-afk time not adding up may be fixed by https://github.com/ActivityWatch/aw-core/pull/105

kewde commented 2 years ago

@ErikBjare The barchart has been fixed by switching over to Rust.

When I tallyed up the times again and my initial calculation was wrong. I'm still getting a few minutes of difference between what's show in 'Time Active' and manually adding up the non-afk events in the timeline but it's in the order of minutes, which is acceptable to me.

I'll give the nightlies a go on my personal machine, thanks for the quick response!