-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessages_processing.py
More file actions
70 lines (55 loc) · 2.17 KB
/
messages_processing.py
File metadata and controls
70 lines (55 loc) · 2.17 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
61
62
63
64
65
66
67
68
69
70
def read_messages(samples_path):
res_dict = {}
with open(samples_path, 'r') as file:
next(file)
for line in file:
# split line into each field
cols = line.split(",")
participant = cols[-1]
trial = cols[0]
resp_time = cols[3]
file_name = cols[5]
# label dict entries by participant
if participant not in res_dict:
res_dict[participant] = {}
# add a subdict for each trial
if trial not in res_dict[participant]:
res_dict[participant][trial] = {}
# add the response time to the trial subdict
if "resp_time" not in res_dict[participant][trial]:
# adjust for the time only the fixation is visible
res_dict[participant][trial]["resp_time"] = float(resp_time)
if "orig_side" not in res_dict[participant][trial]:
if "left" in file_name:
res_dict[participant][trial]["orig_side"] = "left"
else:
res_dict[participant][trial]["orig_side"] = "right"
return res_dict
def avg_response_time(messages_dict):
l_total_resp_time = 0
l_total_num = 0
r_total_resp_time = 0
r_total_num = 0
for participant in messages_dict:
for trial in messages_dict[participant]:
resp_time = messages_dict[participant][trial]["resp_time"]
if messages_dict[participant][trial]["orig_side"] == "left":
l_total_resp_time += resp_time
l_total_num += 1
else:
r_total_resp_time += resp_time
r_total_num += 1
total_resp_time = l_total_resp_time + r_total_resp_time
total_num = l_total_num + r_total_num
l_avg = l_total_resp_time/l_total_num
r_avg = r_total_resp_time/r_total_num
avg = total_resp_time/total_num
return l_avg, r_avg, avg
if __name__ == "__main__":
res = read_messages("Pilot_messages.csv")
# print(len(res))
# print(res)
# print(len(res["SPa\n"]))
# print(res["SPa\n"]["1"])
average = avg_response_time(res)
print(average)