-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessfile.py
More file actions
129 lines (87 loc) · 3.83 KB
/
processfile.py
File metadata and controls
129 lines (87 loc) · 3.83 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 10 10:29:27 2013
@author: kundlj
"""
from os.path import isfile
def process_file_gonogo(filename):
""" Processes a single GoNoGo file generated by the LRC's GoNoGo reation
game. filename is the name of the .txt file. """
if not isfile(filename):
return
info = [x.strip('.txt') for x in filename.split('_')]
subject = info[1][8:]
session = info[2][8:]
trial = info[3][6:]
with open(filename, 'r') as filepointer:
data = filepointer.readlines()
data = [x.strip('\n').split(' ') for x in data]
valid = []
hit = miss = no_reaction = false_pos = false_alarm = 0.0
for item in data:
if len(item) < 2:
false_alarm += 1
continue
else:
time = int(item[0])
color = item[1]
if color == 'A' and time <= 1000:
hit += 1
valid.append(time)
elif color == 'A' and time > 1000:
miss += 1
elif color == 'B' and time > 1000:
no_reaction += 1
elif color == 'B' and time <= 1000:
false_pos += 1
valid.sort()
valid_median = valid[len(valid)/2]
valid_mean = sum(valid)/len(valid)
percent_missed = float(miss/(miss + hit) * 100)
percent_false = float(false_pos/(false_pos + no_reaction) * 100)
error_rate = float((miss + false_pos + false_alarm) / len(data))
ten_percent = len(valid)/10
switch = ten_percent/2
top_median = valid[len(valid) - ten_percent + switch]
top_mean = sum(valid[len(valid) - ten_percent:])/ten_percent
bottom_median = valid[switch]
bottom_mean = sum(valid[:ten_percent])/ten_percent
top_thruput = float((100 * (hit + no_reaction)/len(data))/top_median)
bottom_thruput = float((100 * (hit + no_reaction)/len(data))/bottom_median)
return [[subject, session, trial], [valid_median, valid_mean, \
percent_missed, percent_false, error_rate, top_median, top_mean, \
bottom_median, bottom_mean, top_thruput, bottom_thruput]]
def process_file_audio(filename):
""" Processes a single GoNoGo file generated by the LRC's GoNoGo reation
game. filename is the name of the .txt file. """
if not isfile(filename):
return
info = [x.rstrip('.txt') for x in filename.split('_')]
subject = info[1][8:]
session = info[2][8:]
trial = info[3][6:]
with open(filename, 'r') as filepointer:
data = filepointer.readlines()
data = [x.strip('\n').split(' ') for x in data]
valid = data[:len(data)-2]
valid = [int(val) for sublist in valid for val in sublist]
hit = float(len(valid))
miss = float(data[len(data)-1][3])
false_alarm = float(data[len(data)-2][4])
valid.sort()
valid_median = valid[len(valid)/2]
valid_mean = sum(valid)/len(valid)
percent_missed = float(miss/(miss + hit) * 100)
percent_false = float(false_alarm/(false_alarm + len(valid) + miss) * 100)
error_rate = float((miss + false_alarm) / (false_alarm + len(valid) + miss))
ten_percent = len(valid)/10
switch = ten_percent/2
top_median = valid[len(valid) - ten_percent + switch]
top_mean = sum(valid[len(valid) - ten_percent:])/ten_percent
bottom_median = valid[switch]
bottom_mean = sum(valid[:ten_percent])/ten_percent
top_thruput = float((100 * (hit)/len(data))/top_median)
bottom_thruput = float((100 * (hit)/len(data))/bottom_median)
return [[subject, session, trial], [valid_median, valid_mean, \
percent_missed, percent_false, error_rate, top_median, top_mean, \
bottom_median, bottom_mean, top_thruput, bottom_thruput]]