-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_event_drops.py
executable file
·42 lines (36 loc) · 1.36 KB
/
make_event_drops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /usr/bin/env python3
# Toy script for putting data in the format required by https://github.com/marmelab/EventDrops
# In[]: import lib and data
import pandas as pd
import numpy as np
infile = '~/Desktop/p1-10116.csv' # sample file for testing
outfile = 'visualisations/results/p1-10116-eventDrops.json'
dtypes = {
'userId': str,
'projectId': str,
'email': str,
'CASSIGNMENTNAME': str,
'time': int,
'Type': object,
'Subtype': object,
'onTestCase': object
}
df = pd.read_csv(infile, \
dtype=dtypes, \
na_values=[], \
low_memory=False, \
usecols=list(dtypes.keys()), \
index_col=False)
df.sort_values(by='time', ascending=[1], inplace=True)
df.fillna('', inplace=True)
df = df[df['Type'].isin(['Edit', 'Launch'])]
df.loc[(df.Type == 'Edit') & (df.onTestCase == '1'), 'Subtype'] = 'Test'
df.loc[(df.Type == 'Edit') & (df.onTestCase == '0'), 'Subtype'] = 'Normal'
# In[]: df is only Edits and Launches
type_groups = df.groupby(['Type', 'Subtype'])
type_groups = type_groups.aggregate({ 'time': lambda t: tuple(t) }).reset_index()
type_groups['Type'] += type_groups['Subtype']
type_groups.rename(columns={ 'Type': 'name', 'time': 'data' }, inplace=True) # event-drops expects this
type_groups = type_groups.drop('Subtype', axis=1)
# In[]: write out json
type_groups.to_json(path_or_buf=outfile, orient='records')