Repository navigation
Best way to pull data by Window Title or App Name? #151
Description
Activity
Hi Yi,
There's currently no way to do this as neatly as with selfspy, but @johan-bjareholt is currently working on making it easier with his query2 PRs that are likely to get merged in early next year.
In the meantime, you can do this yourself with a little bit of Python by taking a look at transforms like
filter_period_intersectandfilter_keyvals.The ActivityWatch equivalent of
selfstats -P Google-chrome --clock 00:00 --tactivewould look something like this:from datetime import datetime from aw_core.transforms import filter_period_intersect, filter_keyvals import aw_client client = aw_client.ActivityWatchClient() starttime = datetime.now().replace(hour=0, minute=0) windowevents = client.get_events("your_window_bucket", starttime=starttime) chrome_events = filter_keyvals(windowevents, "app", "google-chrome") afkevents = client.get_events("your_afk_events", starttime=starttime) afkevents_filtered = filter_keyvals(afkevents, "status", "not-afk") chrome_events_filtered = filter_period_intersect(windowevents, afkevents_filtered)
I'm unable to test the code right now, so it probably needs some modification to work.
Happy to hear you're liking ActivityWatch! I hope you keep using it and give us feedback on things we could improve 🙂
HI Erik,
Got you!
It works like a charm as long as I changefilter_keyvals(events, "key", "vals")tofilter_keyvals(events, "key", ["vals"]), since we should pass in a list instead of a str.Also, I guess I can just use
full_chunkmethod to get total duration for each app or title.For the query2, I think it would be great to have a function checks for substring or let us using regex.
Thanks!
@qpskcn1 Awesome that you got it working!
And yeah, we will definitely be adding regexes :)
Also, I guess I can just use full_chunk method to get total duration for each app or title.
Just so you know, the full_chunk will later be replaced with another chunking method when the query2 PRs are merged. It will be replaced with a merge_events_by_keys function which works differently, so you will have to do it once for an app summary and once again for titles separately.
Hi,
I've been using ActivityWatch for a week, and it is much better than selfspy I used before.
Here is my question: what is the best way to pull data by Window Title or app name?
From aw_client, I can only use
starttime,endtimeandlimitsto get events. And then I have to iterate over all data again to get what I want. So is there any way to use a query to pull the data I want? Just likeselfstats -P Google-chrome --clock 00:00 --tactivewill show all events using chrome.Besides, how can I exclude afk time by using existing aw_core packages?
Thanks,
Yi