forked from kixlab/creativeconnect-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_analysis.py
More file actions
60 lines (55 loc) · 1.46 KB
/
log_analysis.py
File metadata and controls
60 lines (55 loc) · 1.46 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Read jsonl file
import json
userId = [
"P1",
"P2",
"P3",
"P4",
"P5",
"P6",
"P8",
"P9",
"P10",
"P11",
"P13",
"P14",
"P15",
"P16",
]
conditions = ["TREATMENT", "CONTROL"]
f_w = open("log_analysis.csv", "w")
f_w.write("id,condition,num,time,rate\n")
for id in userId:
for condition in conditions:
print(id + "-" + condition)
file_path = "logs/" + id + "-" + condition + ".jsonl"
log_data = []
with open(file_path, "r") as f:
for line in f:
log_data.append(json.loads(line))
sketch_data = []
start_time = log_data[0]["timestamp"]
num = 1
for i in range(len(log_data)):
if log_data[i]["action"] == "finishSketch":
f_w.write(
id
+ ","
+ condition
+ ","
+ str(num)
+ ","
+ str(log_data[i]["timestamp"] - start_time)
+ ","
+ str(log_data[i]["data"]["rate"])
+ "\n"
)
sketch_data.append(
{
"time": log_data[i]["timestamp"] - start_time,
"rate": log_data[i]["data"]["rate"],
}
)
num += 1
start_time = log_data[i]["timestamp"]
print(sketch_data)