-
Notifications
You must be signed in to change notification settings - Fork 2
/
CSVGen.py
135 lines (116 loc) · 4.09 KB
/
CSVGen.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
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
130
131
132
133
134
135
import random
import time
import EEGDataGen as dataGen
import msvcrt as keyboard
import numpy as np
from Processing import DataReader
class CSVDataReader:
def __init__(self):
self.globle_direction = "Right"
self.fileName = ""
def intro(self):
print("Get Ready to Focus ")
print("Please hit the key 'R' when asked to Enter Right and 'L' for Left")
index = 5
while index > 0:
t0 = time.time()
print(index)
while True:
t1 = time.time()
if (t1 - t0) > 1:
break
index -= 1
def inputLoop(self, dr, fileNameBin, fileNameRaw):
endTime = time.time() + self.randomTime()
direction = self.randomFlag()
# while true, enter the loop, have a time checker that breaks it, but while doing this if you end up
# out of range you need to extend the loop
while time.time() < endTime:
readIn = [0, 0, 0]
print("\nENTER " + direction + "\n")
keyboard.getch()
readIn[0], readIn[1], readIn[2] = dr.get_data()
self.writeFileBin(direction, fileNameBin, readIn)
self.writeFileRaw(direction, fileNameRaw, readIn)
def writeFileBin(self, direction, fileName, readIn):
size = 10
final = ""
for i in range(size):
final += str(round(readIn[2][i]))
final += ","
final += direction + "\n"
file = open(fileName, "a")
file.write(final)
def writeFileRaw(self, direction, fileName, readIn):
size = 4
final = str(readIn[0]) + ","
for i in range(size):
final += str(readIn[1][i, :]) # type: ignore
final += ","
final += direction + "\n"
file = open(fileName, "a")
file.write(final)
def withinRange(self, readIn):
threshold1 = 13
threshold2 = 29
input1Valid = readIn[0] > threshold1 and readIn[0] < threshold2
input2Valid = readIn[1] > threshold1 and readIn[1] < threshold2
if input1Valid and input2Valid:
return True
else:
return False
# here for test only
def randomFlag(self):
if self.globle_direction == "Right":
self.globle_direction = "Left"
return "Left"
elif self.globle_direction == "Left":
self.globle_direction = "Up"
return "Up"
elif self.globle_direction == "Up":
self.globle_direction = "Down"
return "Down"
elif self.globle_direction == "Down":
self.globle_direction = "Blink"
return "Blink"
else:
self.globle_direction = "Right"
return "Right"
def randomTime(self):
# return random.randint(2, 5)
return 10
# New function
def makeHeader(self):
self.fileNameBin = dataGen.findEmptyFile("bin")
file = open(self.fileNameBin, "w")
file.close()
# New function
def writeFile(self, direction, bands):
size = bands.shape[0]
final = ""
for i in range(size):
final += str(round(bands[i])) # type: ignore
final += ","
final += direction + "\n"
file = open(self.fileNameBin, "a")
file.write(final)
def main(self):
dr = DataReader(500)
focusTime = 0.25 * 60
finalTime = time.time() + focusTime
fileHeader = (
"d1,t1,a1,b1,g1,d2,t2,a2,b2,g2,d3,t3,a3,b3,g3,d4,t4,a4,b4,g4,Direction\n"
)
fileNameBin = dataGen.findEmptyFile("bin")
fileNameRaw = dataGen.findEmptyFile("raw")
file = open(fileNameBin, "w")
file.write(fileHeader)
file.close()
self.intro()
while time.time() < finalTime:
self.inputLoop(dr, fileNameBin, fileNameRaw)
if __name__ == "__main__":
# Method call for main: This initializes and completes method calls using the UserInterface and EncryptionProcessor classes to
# facilitate the execution of the encrytion application.
dr = CSVDataReader()
dr.main()