Skip to content

Best way to pull data by Window Title or App Name? #151

Description

@qpskcn1

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, endtime and limits to 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 like selfstats -P Google-chrome --clock 00:00 --tactive will show all events using chrome.

Besides, how can I exclude afk time by using existing aw_core packages?

Thanks,
Yi

Activity

  1. ErikBjare commented on Dec 6, 2017

    @ErikBjare
    Member

    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_intersect and filter_keyvals.

    The ActivityWatch equivalent of selfstats -P Google-chrome --clock 00:00 --tactive would 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 🙂

  2. qpskcn1 commented on Dec 6, 2017

    @qpskcn1
    Author

    HI Erik,

    Got you!
    It works like a charm as long as I change filter_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_chunk method 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!

  3. ErikBjare commented on Dec 7, 2017

    @ErikBjare
    Member

    @qpskcn1 Awesome that you got it working!

    And yeah, we will definitely be adding regexes :)

  4. johan-bjareholt commented on Dec 7, 2017

    @johan-bjareholt
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions