|
1 | 1 | import moment from 'moment'; |
2 | 2 | import { unitOfTime } from 'moment'; |
3 | 3 | import * as _ from 'lodash'; |
| 4 | +import { map, filter, values, groupBy, sumBy, sortBy, flow } 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,88 @@ 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: 14.6 * 60, |
| 202 | + data: { |
| 203 | + app: 'Firefox', |
| 204 | + title: 'Inbox - Gmail - Mozilla Firefox', |
| 205 | + url: 'https://mail.google.com', |
| 206 | + $category: ['Work'], |
| 207 | + }, |
| 208 | + }, |
| 209 | + { |
| 210 | + duration: 0.2 * 60 * 60, |
| 211 | + data: { |
| 212 | + app: 'Firefox', |
| 213 | + title: 'reddit: the front page of the internet - Mozilla Firefox', |
| 214 | + url: 'https://reddit.com', |
| 215 | + $category: ['Media', 'Social Media'], |
| 216 | + }, |
| 217 | + }, |
| 218 | + { |
| 219 | + duration: 0.2 * 60 * 60, |
| 220 | + data: { |
| 221 | + app: 'Firefox', |
| 222 | + title: 'YouTube - Mozilla Firefox', |
| 223 | + url: 'https://youtube.com', |
| 224 | + $category: ['Media', 'Video'], |
| 225 | + }, |
| 226 | + }, |
| 227 | + { |
| 228 | + duration: 0.15 * 60 * 60, |
| 229 | + data: { |
| 230 | + app: 'Firefox', |
| 231 | + title: 'Home / Twitter - Mozilla Firefox', |
| 232 | + url: 'https://twitter.com', |
| 233 | + $category: ['Media', 'Social Media'], |
| 234 | + }, |
| 235 | + }, |
| 236 | + { |
| 237 | + duration: 0.4 * 60 * 60, |
| 238 | + data: { app: 'Minecraft', title: 'Minecraft', $category: ['Media', 'Games'] }, |
| 239 | + }, |
| 240 | + { |
| 241 | + duration: 3.15 * 60, |
| 242 | + data: { app: 'Spotify', title: 'Spotify', $category: ['Media', 'Music'] }, |
| 243 | + }, |
| 244 | + ]; |
| 245 | + |
| 246 | + function groupSumEventsBy(events, key, f) { |
| 247 | + return flow( |
| 248 | + filter(f), |
| 249 | + groupBy(f), |
| 250 | + values, |
| 251 | + map((es: any) => { |
| 252 | + return { duration: _.sumBy(es, 'duration'), data: { [key]: f(es[0]) } }; |
| 253 | + }), |
| 254 | + sortBy('-duration') |
| 255 | + )(events); |
| 256 | + } |
| 257 | + |
| 258 | + const app_events = groupSumEventsBy(window_events, 'app', (e: any) => e.data.app); |
| 259 | + const title_events = groupSumEventsBy(window_events, 'title', (e: any) => e.data.title); |
| 260 | + const cat_events = groupSumEventsBy(window_events, '$category', (e: any) => e.data.$category); |
| 261 | + const url_events = groupSumEventsBy(window_events, 'url', (e: any) => e.data.url); |
| 262 | + const domain_events = groupSumEventsBy(window_events, '$domain', (e: any) => |
| 263 | + e.data.url === undefined ? '' : new URL(e.data.url).host |
| 264 | + ); |
| 265 | + |
198 | 266 | 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'] } }], |
| 267 | + duration: _.sumBy(window_events, 'duration'), |
| 268 | + app_events, |
| 269 | + title_events, |
| 270 | + cat_events, |
203 | 271 | active_events: [ |
204 | 272 | { timestamp: new Date().toISOString(), duration: 1.5 * 60 * 60, data: { afk: 'not-afk' } }, |
205 | 273 | ], |
206 | 274 | }); |
207 | 275 |
|
208 | 276 | commit('browser_buckets', ['aw-watcher-firefox']); |
209 | 277 | 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' } }], |
| 278 | + duration: _.sumBy(url_events, 'duration'), |
| 279 | + domains: domain_events, |
| 280 | + urls: url_events, |
213 | 281 | }); |
214 | 282 |
|
215 | 283 | commit('editor_buckets', ['aw-watcher-vim']); |
|
0 commit comments