So, how does the Regex work? Can't seem to match any window titles

Hello there,

New here and a bit green, but worked in IT and data, so I have enough knowledge to be dangerous.

I’ve found that ActivityWatch does exactly what I need in order to track my gaming addiction, but I’m struggling to get information from queries. I’m trying to match a set of window titles for a time period, and the query looks something like this (taken from the default query):

afk_events = query_bucket(find_bucket(“aw-watcher-afk_”));
window_events = query_bucket(find_bucket(“aw-watcher-window_”));
window_events = filter_period_intersect(window_events, filter_keyvals(afk_events, “status”, [“not-afk”]));
merged_events = merge_events_by_keys(window_events, [“title”]);
final_events = filter_keyvals(merged_events, “title”, [’(?i)activity.*’]);
RETURN = sort_by_duration(final_events);

and while merged_events clearly has window titles in it that have “Activity” in the string, when I check for the final_events variable, nothing shows up. What am I doing wrong here?

I haven’t been able to find any information regarding what filtering can be done (where do I need to look for things like “filter_period_intersect” syntax and other queries etc?), and I can’t seem to get the regex to work. Any ideas?

Thanks in advance.

Andy

Hi Andy.

Try using filter_keyvals_regex instead of filter_keyvals and applying the filter before you merge the events.

This works for me.

afk_events = query_bucket(find_bucket("aw-watcher-afk_"));
window_events = query_bucket(find_bucket("aw-watcher-window_"));
window_events = filter_period_intersect(window_events, filter_keyvals(afk_events, "status", ["not-afk"]));
window_events = filter_keyvals_regex(window_events, "title", "(?i)activity");
merged_events = merge_events_by_keys(window_events, ["title"]);
RETURN = sort_by_duration(merged_events);

Hope that helps.

3nvh

Superb, thank you very much. I need to spend more time looking at the API. Didn’t find any of the functions when I looked the first time.