|
1 | 1 | import moment from 'moment'; |
2 | 2 | import { unitOfTime } from 'moment'; |
3 | 3 | import * as _ from 'lodash'; |
| 4 | +import { map, filter, values, groupBy, sortBy, flow, reverse } from 'lodash/fp'; |
4 | 5 | import queries from '~/queries'; |
5 | 6 | import { loadClassesForQuery } from '~/util/classes'; |
6 | 7 | import { get_day_start_with_offset } from '~/util/time'; |
@@ -195,21 +196,131 @@ const actions = { |
195 | 196 | // A function to load some demo data (for screenshots and stuff) |
196 | 197 | commit('start_loading', {}); |
197 | 198 |
|
| 199 | + const window_events = [ |
| 200 | + { |
| 201 | + duration: 32.1 * 60, |
| 202 | + data: { |
| 203 | + app: 'Firefox', |
| 204 | + title: 'ActivityWatch/activitywatch: Track how you spend your time - Mozilla Firefox', |
| 205 | + url: 'https://github.com/ActivityWatch/activitywatch', |
| 206 | + $category: ['Work', 'Programming', 'ActivityWatch'], |
| 207 | + }, |
| 208 | + }, |
| 209 | + { |
| 210 | + duration: 14.6 * 60, |
| 211 | + data: { |
| 212 | + app: 'Firefox', |
| 213 | + title: 'Inbox - Gmail - Mozilla Firefox', |
| 214 | + url: 'https://mail.google.com', |
| 215 | + $category: ['Comms', 'Email'], |
| 216 | + }, |
| 217 | + }, |
| 218 | + { |
| 219 | + duration: 0.2 * 60 * 60, |
| 220 | + data: { |
| 221 | + app: 'Firefox', |
| 222 | + title: 'reddit: the front page of the internet - Mozilla Firefox', |
| 223 | + url: 'https://reddit.com', |
| 224 | + $category: ['Media', 'Social Media'], |
| 225 | + }, |
| 226 | + }, |
| 227 | + { |
| 228 | + duration: 0.2 * 60 * 60, |
| 229 | + data: { |
| 230 | + app: 'Firefox', |
| 231 | + title: 'YouTube - Mozilla Firefox', |
| 232 | + url: 'https://youtube.com', |
| 233 | + $category: ['Media', 'Video'], |
| 234 | + }, |
| 235 | + }, |
| 236 | + { |
| 237 | + duration: 0.15 * 60 * 60, |
| 238 | + data: { |
| 239 | + app: 'Firefox', |
| 240 | + title: 'Home / Twitter - Mozilla Firefox', |
| 241 | + url: 'https://twitter.com', |
| 242 | + $category: ['Media', 'Social Media'], |
| 243 | + }, |
| 244 | + }, |
| 245 | + { |
| 246 | + duration: 0.15 * 60 * 60, |
| 247 | + data: { |
| 248 | + app: 'Firefox', |
| 249 | + title: 'Stack Overflow', |
| 250 | + url: 'https://stackoverflow.com', |
| 251 | + $category: ['Work', 'Programming'], |
| 252 | + }, |
| 253 | + }, |
| 254 | + { |
| 255 | + duration: 48.2 * 60, |
| 256 | + data: { |
| 257 | + app: 'Terminal', |
| 258 | + title: 'vim ~/code/activitywatch/aw-server/aw-webui/src', |
| 259 | + $category: ['Work', 'Programming', 'ActivityWatch'], |
| 260 | + }, |
| 261 | + }, |
| 262 | + { |
| 263 | + duration: 12.6 * 60, |
| 264 | + data: { |
| 265 | + app: 'Terminal', |
| 266 | + title: 'bash ~/code/activitywatch', |
| 267 | + $category: ['Work', 'Programming', 'ActivityWatch'], |
| 268 | + }, |
| 269 | + }, |
| 270 | + { |
| 271 | + duration: 58.1 * 60, |
| 272 | + data: { |
| 273 | + app: 'zoom', |
| 274 | + title: 'Zoom Meeting', |
| 275 | + $category: ['Comms', 'Video Conferencing'], |
| 276 | + }, |
| 277 | + }, |
| 278 | + { |
| 279 | + duration: 0.4 * 60 * 60, |
| 280 | + data: { app: 'Minecraft', title: 'Minecraft', $category: ['Media', 'Games'] }, |
| 281 | + }, |
| 282 | + { |
| 283 | + duration: 3.15 * 60, |
| 284 | + data: { app: 'Spotify', title: 'Spotify', $category: ['Media', 'Music'] }, |
| 285 | + }, |
| 286 | + ]; |
| 287 | + |
| 288 | + function groupSumEventsBy(events, key, f) { |
| 289 | + return flow( |
| 290 | + filter(f), |
| 291 | + groupBy(f), |
| 292 | + values, |
| 293 | + map((es: any) => { |
| 294 | + return { duration: _.sumBy(es, 'duration'), data: { [key]: f(es[0]) } }; |
| 295 | + }), |
| 296 | + sortBy('duration'), |
| 297 | + reverse |
| 298 | + )(events); |
| 299 | + } |
| 300 | + |
| 301 | + const app_events = groupSumEventsBy(window_events, 'app', (e: any) => e.data.app); |
| 302 | + const title_events = groupSumEventsBy(window_events, 'title', (e: any) => e.data.title); |
| 303 | + const cat_events = groupSumEventsBy(window_events, '$category', (e: any) => e.data.$category); |
| 304 | + const url_events = groupSumEventsBy(window_events, 'url', (e: any) => e.data.url); |
| 305 | + const domain_events = groupSumEventsBy(window_events, '$domain', (e: any) => |
| 306 | + e.data.url === undefined ? '' : new URL(e.data.url).host |
| 307 | + ); |
| 308 | + |
198 | 309 | commit('query_window_completed', { |
199 | | - duration: 30, |
200 | | - app_events: [{ duration: 10, data: { app: 'test' } }], |
201 | | - title_events: [{ duration: 10, data: { title: 'test' } }], |
202 | | - cat_events: [{ duration: 10, data: { $category: ['test', 'subtest'] } }], |
| 310 | + duration: _.sumBy(window_events, 'duration'), |
| 311 | + app_events, |
| 312 | + title_events, |
| 313 | + cat_events, |
203 | 314 | active_events: [ |
204 | 315 | { timestamp: new Date().toISOString(), duration: 1.5 * 60 * 60, data: { afk: 'not-afk' } }, |
205 | 316 | ], |
206 | 317 | }); |
207 | 318 |
|
208 | 319 | commit('browser_buckets', ['aw-watcher-firefox']); |
209 | 320 | commit('query_browser_completed', { |
210 | | - duration: 20, |
211 | | - domains: [{ duration: 10, data: { $domain: 'github.com' } }], |
212 | | - urls: [{ duration: 10, data: { url: 'https://github.com/ActivityWatch/activitywatch' } }], |
| 321 | + duration: _.sumBy(url_events, 'duration'), |
| 322 | + domains: domain_events, |
| 323 | + urls: url_events, |
213 | 324 | }); |
214 | 325 |
|
215 | 326 | commit('editor_buckets', ['aw-watcher-vim']); |
|
0 commit comments