Skip to content

Commit 1362f2d

Browse files
committed
added computation of demo data from single list of events
1 parent f9c0b40 commit 1362f2d

File tree

1 file changed

+75
-7
lines changed

1 file changed

+75
-7
lines changed

src/store/modules/activity_daily.ts

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import moment from 'moment';
22
import { unitOfTime } from 'moment';
33
import * as _ from 'lodash';
4+
import { map, filter, values, groupBy, sumBy, sortBy, flow } from 'lodash/fp';
45
import queries from '~/queries';
56
import { loadClassesForQuery } from '~/util/classes';
67
import { get_day_start_with_offset } from '~/util/time';
@@ -195,21 +196,88 @@ const actions = {
195196
// A function to load some demo data (for screenshots and stuff)
196197
commit('start_loading', {});
197198

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+
198266
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,
203271
active_events: [
204272
{ timestamp: new Date().toISOString(), duration: 1.5 * 60 * 60, data: { afk: 'not-afk' } },
205273
],
206274
});
207275

208276
commit('browser_buckets', ['aw-watcher-firefox']);
209277
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,
213281
});
214282

215283
commit('editor_buckets', ['aw-watcher-vim']);

0 commit comments

Comments
 (0)