-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagetimes.py
35 lines (28 loc) · 1.09 KB
/
pagetimes.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
'''
(Designed for oTree 3.0+)
To run this script:
python pagetimes.py infile.csv outfile.csv
infile.csv should be the name of the "page times" csv file you downloaded from oTree.
The script will create your outfile.csv with an extra column,
showing how much time was spent on each page.
You can modify this script to tabulate other things, e.g. how much time a participant spent on wait pages in total.
'''
from sys import argv
from csv import DictReader, DictWriter
times = {}
with open(argv[1]) as inf, open(argv[2], 'w', newline='') as outf:
reader = DictReader(inf)
writer = DictWriter(outf, fieldnames=reader.fieldnames + ['seconds_on_page'])
writer.writeheader()
for row in reader:
pcode = row['participant_code']
# to learn what Epoch time is, search on Google.
time = int(row.get('epoch_time_completed') or row.get('epoch_time'))
last_time = times.get(pcode)
if last_time:
delta = time - last_time
else:
delta = ''
row['seconds_on_page'] = delta
writer.writerow(row)
times[pcode] = time