Skip to content

Commit

Permalink
added computation of demo data from single list of events
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Mar 16, 2020
1 parent f9c0b40 commit 1362f2d
Showing 1 changed file with 75 additions and 7 deletions.
82 changes: 75 additions & 7 deletions src/store/modules/activity_daily.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import moment from 'moment';
import { unitOfTime } from 'moment';
import * as _ from 'lodash';
import { map, filter, values, groupBy, sumBy, sortBy, flow } from 'lodash/fp';
import queries from '~/queries';
import { loadClassesForQuery } from '~/util/classes';
import { get_day_start_with_offset } from '~/util/time';
Expand Down Expand Up @@ -195,21 +196,88 @@ const actions = {
// A function to load some demo data (for screenshots and stuff)
commit('start_loading', {});

const window_events = [
{
duration: 14.6 * 60,
data: {
app: 'Firefox',
title: 'Inbox - Gmail - Mozilla Firefox',
url: 'https://mail.google.com',
$category: ['Work'],
},
},
{
duration: 0.2 * 60 * 60,
data: {
app: 'Firefox',
title: 'reddit: the front page of the internet - Mozilla Firefox',
url: 'https://reddit.com',
$category: ['Media', 'Social Media'],
},
},
{
duration: 0.2 * 60 * 60,
data: {
app: 'Firefox',
title: 'YouTube - Mozilla Firefox',
url: 'https://youtube.com',
$category: ['Media', 'Video'],
},
},
{
duration: 0.15 * 60 * 60,
data: {
app: 'Firefox',
title: 'Home / Twitter - Mozilla Firefox',
url: 'https://twitter.com',
$category: ['Media', 'Social Media'],
},
},
{
duration: 0.4 * 60 * 60,
data: { app: 'Minecraft', title: 'Minecraft', $category: ['Media', 'Games'] },
},
{
duration: 3.15 * 60,
data: { app: 'Spotify', title: 'Spotify', $category: ['Media', 'Music'] },
},
];

function groupSumEventsBy(events, key, f) {
return flow(
filter(f),
groupBy(f),
values,
map((es: any) => {
return { duration: _.sumBy(es, 'duration'), data: { [key]: f(es[0]) } };
}),
sortBy('-duration')
)(events);
}

const app_events = groupSumEventsBy(window_events, 'app', (e: any) => e.data.app);
const title_events = groupSumEventsBy(window_events, 'title', (e: any) => e.data.title);
const cat_events = groupSumEventsBy(window_events, '$category', (e: any) => e.data.$category);
const url_events = groupSumEventsBy(window_events, 'url', (e: any) => e.data.url);
const domain_events = groupSumEventsBy(window_events, '$domain', (e: any) =>
e.data.url === undefined ? '' : new URL(e.data.url).host
);

commit('query_window_completed', {
duration: 30,
app_events: [{ duration: 10, data: { app: 'test' } }],
title_events: [{ duration: 10, data: { title: 'test' } }],
cat_events: [{ duration: 10, data: { $category: ['test', 'subtest'] } }],
duration: _.sumBy(window_events, 'duration'),
app_events,
title_events,
cat_events,
active_events: [
{ timestamp: new Date().toISOString(), duration: 1.5 * 60 * 60, data: { afk: 'not-afk' } },
],
});

commit('browser_buckets', ['aw-watcher-firefox']);
commit('query_browser_completed', {
duration: 20,
domains: [{ duration: 10, data: { $domain: 'github.com' } }],
urls: [{ duration: 10, data: { url: 'https://github.com/ActivityWatch/activitywatch' } }],
duration: _.sumBy(url_events, 'duration'),
domains: domain_events,
urls: url_events,
});

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

0 comments on commit 1362f2d

Please sign in to comment.