-
-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented audible-as-active #85
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,25 +2,46 @@ import _ from 'lodash'; | |
|
||
// TODO: Sanitize string input of buckets | ||
|
||
// Helper function returning a query that defines a variable events_active | ||
// that can be used to filter away non-active time. | ||
// TODO: Handle events from all available browser buckets, as done in: https://github.com/ActivityWatch/aw-webui/pull/108 | ||
// TODO: Don't count audible as activity if window isn't active | ||
// NOTE: This returns a string, not a list of strings. | ||
function _events_active(afkbucket, browserbucket, audibleAsActive) { | ||
return ( | ||
`events_active = []; | ||
events_afk = flood(query_bucket("${afkbucket}")); | ||
events_active = period_union(events_active, filter_keyvals(events_afk, "status", ["not-afk"]))` | ||
) + ( | ||
audibleAsActive ? | ||
`events_browser = flood(query_bucket("${browserbucket}")); | ||
events_audible = filter_keyvals(events_browser, "audible", [true]); | ||
events_active = period_union(events_active, events_audible);` | ||
: '' | ||
); | ||
} | ||
|
||
export function windowQuery(windowbucket, afkbucket, appcount, titlecount, filterAFK) { | ||
// TODO: Take into account audible browser activity (tricky) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should probably be removed, after testing. |
||
let code = ( | ||
`events = flood(query_bucket("${windowbucket}")); | ||
not_afk = flood(query_bucket("${afkbucket}")); | ||
not_afk = filter_keyvals(not_afk, "status", ["not-afk"]);` | ||
`events = flood(query_bucket("${windowbucket}"));` | ||
) + ( | ||
filterAFK ? 'events = filter_period_intersect(events, not_afk);' : '' | ||
filterAFK ? | ||
`not_afk = flood(query_bucket("${afkbucket}")); | ||
not_afk = filter_keyvals(not_afk, "status", ["not-afk"]); | ||
events = filter_period_intersect(events, not_afk);` | ||
: '' | ||
) + ( | ||
`title_events = merge_events_by_keys(events, ["app", "title"]); | ||
title_events = sort_by_duration(title_events); | ||
app_events = merge_events_by_keys(title_events, ["app"]); | ||
app_events = sort_by_duration(app_events); | ||
|
||
events = sort_by_timestamp(events); | ||
app_chunks = chunk_events_by_key(events, "app"); | ||
app_events = limit_events(app_events, ${appcount}); | ||
title_events = limit_events(title_events, ${titlecount}); | ||
duration = sum_durations(events); | ||
RETURN = {"app_events": app_events, "title_events": title_events, "app_chunks": app_chunks, "duration": duration};` | ||
title_events = sort_by_duration(title_events); | ||
app_events = merge_events_by_keys(title_events, ["app"]); | ||
app_events = sort_by_duration(app_events); | ||
events = sort_by_timestamp(events); | ||
app_chunks = chunk_events_by_key(events, "app"); | ||
app_events = limit_events(app_events, ${appcount}); | ||
title_events = limit_events(title_events, ${titlecount}); | ||
duration = sum_durations(events); | ||
RETURN = {"app_events": app_events, "title_events": title_events, "app_chunks": app_chunks, "duration": duration};` | ||
); | ||
let lines = code.split(";"); | ||
return _.map(lines, (l) => l + ";"); | ||
|
@@ -41,61 +62,58 @@ export function appQuery(appbucket, limit) { | |
return _.map(lines, (l) => l + ";"); | ||
} | ||
|
||
export function browserSummaryQuery(browserbucket, windowbucket, afkbucket, count, filterAFK) { | ||
export function browserSummaryQuery(browserbucket, windowbucket, afkbucket, count, filterAFK, audibleAsActive) { | ||
var browser_appnames = ""; | ||
if (browserbucket.endsWith("-chrome")){ | ||
browser_appnames = JSON.stringify(["Google-chrome", "chrome.exe", "Chromium", "Google Chrome", "Chromium-browser", "Chromium-browser-chromium", "Google-chrome-beta", "Google-chrome-unstable"]); | ||
} else if (browserbucket.endsWith("-firefox")){ | ||
browser_appnames = JSON.stringify(["Firefox", "Firefox.exe", "firefox", "firefox.exe", "Firefox Developer Edition", "Firefox Beta", "Nightly"]); | ||
} | ||
|
||
return [ | ||
'events = flood(query_bucket("' + browserbucket + '"));', | ||
'window_browser = flood(query_bucket("' + windowbucket + '"));', | ||
'window_browser = filter_keyvals(window_browser, "app", ' + browser_appnames + ');', | ||
].concat(filterAFK ? [ | ||
'not_afk = flood(query_bucket("' + afkbucket + '"));', | ||
'not_afk = filter_keyvals(not_afk, "status", ["not-afk"]);', | ||
'window_browser = filter_period_intersect(window_browser, not_afk);', | ||
] : []) | ||
.concat([ | ||
'events = filter_period_intersect(events, window_browser);', | ||
'events = split_url_events(events);', | ||
'urls = merge_events_by_keys(events, ["url"]);', | ||
'urls = sort_by_duration(urls);', | ||
'urls = limit_events(urls, ' + count + ');', | ||
'domains = split_url_events(events);', | ||
'domains = merge_events_by_keys(domains, ["domain"]);', | ||
'domains = sort_by_duration(domains);', | ||
'domains = limit_events(domains, ' + count + ');', | ||
'chunks = chunk_events_by_key(events, "domain");', | ||
'duration = sum_durations(events);', | ||
'RETURN = {"domains": domains, "urls": urls, "chunks": chunks, "duration": duration};', | ||
]); | ||
let code = ( | ||
`events_browser = flood(query_bucket("${browserbucket}")); | ||
events_window_browser = filter_keyvals(flood(query_bucket("${windowbucket}")), "app", ${browser_appnames});` | ||
) + ( | ||
filterAFK ? _events_active(afkbucket, browserbucket, audibleAsActive) : '' | ||
) + ( | ||
`events_window_browser = filter_period_intersect(events_window_browser, events_active); | ||
events = filter_period_intersect(events, events_window_browser); | ||
events = split_url_events(events); | ||
urls = merge_events_by_keys(events, ["domain", "url"]); | ||
urls = limit_events(sort_by_duration(urls), ${count}); | ||
domains = split_url_events(events); | ||
domains = merge_events_by_keys(domains, ["domain"]); | ||
domains = sort_by_duration(domains); | ||
domains = limit_events(domains, ${count}); | ||
chunks = chunk_events_by_key(events, "domain"); | ||
duration = sum_durations(events); | ||
RETURN = {"domains": domains, "urls": urls, "chunks": chunks, "duration": duration};` | ||
); | ||
let lines = code.split(";"); | ||
return _.map(lines, (l) => l + ";"); | ||
} | ||
|
||
export function editorActivityQuery(editorbucket, limit) { | ||
return [ | ||
'editorbucket = "' + editorbucket + '";', | ||
'events = flood(query_bucket(editorbucket));', | ||
'files = sort_by_duration(merge_events_by_keys(events, ["file", "language"]));', | ||
'files = limit_events(files, ' + limit + ');', | ||
'languages = sort_by_duration(merge_events_by_keys(events, ["language"]));', | ||
'languages = limit_events(languages, ' + limit + ');', | ||
'projects = sort_by_duration(merge_events_by_keys(events, ["project"]));', | ||
'projects = limit_events(projects, ' + limit + ');', | ||
'duration = sum_durations(events);', | ||
'RETURN = {"files": files, "languages": languages, "projects": projects, "duration": duration};' | ||
]; | ||
export function editorActivityQuery (editorbucket, limit){ | ||
let code = ( | ||
`editorbucket = "${editorbucket}"; | ||
events = flood(query_bucket(editorbucket)); | ||
files = sort_by_duration(merge_events_by_keys(events, ["file", "language"])); | ||
files = limit_events(files, ${limit}); | ||
languages = sort_by_duration(merge_events_by_keys(events, ["language"])); | ||
languages = limit_events(languages, ${limit}); | ||
projects = sort_by_duration(merge_events_by_keys(events, ["project"])); | ||
projects = limit_events(projects, ${limit}); | ||
duration = sum_durations(events); | ||
RETURN = {"files": files, "languages": languages, "projects": projects, "duration": duration};` | ||
); | ||
let lines = code.split(";"); | ||
return _.map(lines, (l) => l + ";"); | ||
} | ||
|
||
export function dailyActivityQuery(afkbucket) { | ||
return [ | ||
'afkbucket = "' + afkbucket + '";', | ||
'not_afk = flood(query_bucket(afkbucket));', | ||
'not_afk = merge_events_by_keys(not_afk, ["status"]);', | ||
'RETURN = not_afk;' | ||
]; | ||
export function dailyActivityQuery(afkbucket, browserbucket, audibleAsActive) { | ||
return _events_active(afkbucket, browserbucket, audibleAsActive).concat([ | ||
'RETURN = events_active;' | ||
]); | ||
} | ||
|
||
export function dailyActivityQueryAndroid(androidbucket) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,8 @@ div | |
div | ||
b-form-checkbox(v-model="filterAFK") | ||
| Filter away AFK time | ||
b-form-checkbox(v-model="countAudibleAsActive") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking of removing this though, just adds unnecessary complexity. It's not like I'm expecting anyone to not want this, and it isn't saved across page reloads anyway which makes it kinda bad UX. It's useful in testing though, which is an argument in favor of it I guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is important if someone for example often leaves their computer for extended periods of time with for example Spotify or YouTube in the foreground while not actually being at the computer but only having it for playing music. |
||
| Count browser audible as active | ||
|
||
|
||
</template> | ||
|
@@ -217,6 +219,7 @@ export default { | |
today: moment().startOf('day').format("YYYY-MM-DD"), | ||
|
||
filterAFK: true, | ||
countAudibleAsActive: true, | ||
timelineShowAFK: true, | ||
|
||
view: "summary", | ||
|
@@ -310,7 +313,7 @@ export default { | |
readableWebDuration: function() { return time.seconds_to_duration(this.web_duration) }, | ||
readableEditorDuration: function() { return time.seconds_to_duration(this.editor_duration) }, | ||
host: function() { return this.$route.params.host }, | ||
date: function() { | ||
date: function() { | ||
var dateParam = this.$route.params.date; | ||
var dateMoment = dateParam ? moment(dateParam) : moment(); | ||
return dateMoment.startOf('day').format(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a blocker.
I think we would need to finish implementing the combination of window events and browser events (ActivityWatch/aw-server-rust#179) before making headway on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, it works just fine as I did it in #262