Skip to content

Commit f0a06dd

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

1 file changed

Lines changed: 85 additions & 7 deletions

File tree

src/store/modules/activity_daily.ts

Lines changed: 85 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, sortBy, flow, reverse } 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,98 @@ 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: 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: ['Work'],
216+
},
217+
},
218+
{
219+
duration: 21.17 * 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.4 * 60 * 60,
247+
data: { app: 'Minecraft', title: 'Minecraft', $category: ['Media', 'Games'] },
248+
},
249+
{
250+
duration: 3.15 * 60,
251+
data: { app: 'Spotify', title: 'Spotify', $category: ['Media', 'Music'] },
252+
},
253+
];
254+
255+
function groupSumEventsBy(events, key, f) {
256+
return flow(
257+
filter(f),
258+
groupBy(f),
259+
values,
260+
map((es: any) => {
261+
return { duration: _.sumBy(es, 'duration'), data: { [key]: f(es[0]) } };
262+
}),
263+
sortBy('duration'),
264+
reverse
265+
)(events);
266+
}
267+
268+
const app_events = groupSumEventsBy(window_events, 'app', (e: any) => e.data.app);
269+
const title_events = groupSumEventsBy(window_events, 'title', (e: any) => e.data.title);
270+
const cat_events = groupSumEventsBy(window_events, '$category', (e: any) => e.data.$category);
271+
const url_events = groupSumEventsBy(window_events, 'url', (e: any) => e.data.url);
272+
const domain_events = groupSumEventsBy(window_events, '$domain', (e: any) =>
273+
e.data.url === undefined ? '' : new URL(e.data.url).host
274+
);
275+
198276
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'] } }],
277+
duration: _.sumBy(window_events, 'duration'),
278+
app_events,
279+
title_events,
280+
cat_events,
203281
active_events: [
204282
{ timestamp: new Date().toISOString(), duration: 1.5 * 60 * 60, data: { afk: 'not-afk' } },
205283
],
206284
});
207285

208286
commit('browser_buckets', ['aw-watcher-firefox']);
209287
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' } }],
288+
duration: _.sumBy(url_events, 'duration'),
289+
domains: domain_events,
290+
urls: url_events,
213291
});
214292

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

0 commit comments

Comments
 (0)