-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzener.py
More file actions
150 lines (133 loc) · 5.57 KB
/
zener.py
File metadata and controls
150 lines (133 loc) · 5.57 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import tkinter as tk
from functools import partial
from random import choice
from time import time
from sqlite3 import Connection
class Game():
def __init__(self, mode, game_length, name, mood, start_time, brain_parent, heart_parent=None):
self.brain_parent = brain_parent
if heart_parent is not None:
self.heart_parent = heart_parent
else:
self.heart_parent = None
print('Creating Game now!')
self.attempts = 0
self.length = int(game_length.get())
self.options = []
self.data = {}
root = tk.Tk()
root.title('Game')
att = tk.Label(root, text=str(self.attempts)+'/'+str(self.length))
img_circle = tk.PhotoImage(master=root, file="images/circle.gif")
self.options.append(img_circle)
circle = tk.Canvas(root, width=141, height=169)
circle.create_image(70, 84, image=img_circle)
circle.grid(row=1, column=1)
choose_circle = tk.Button(root, text="Choose", command=partial(
self.human_choice, img_circle, mode, att, name, mood, start_time, root
))
choose_circle.grid(row=2, column=1)
img_cross = tk.PhotoImage(master=root, file="images/cross.gif")
self.options.append(img_cross)
cross = tk.Canvas(root, width=141, height=169)
cross.create_image(70, 84, image=img_cross)
cross.grid(row=1, column=2)
choose_cross = tk.Button(root, text="Choose", command=partial(
self.human_choice, img_cross, mode, att, name, mood, start_time, root
))
choose_cross.grid(row=2, column=2)
img_waves = tk.PhotoImage(master=root, file="images/waves.gif")
self.options.append(img_waves)
waves = tk.Canvas(root, width=141, height=169)
waves.create_image(70, 84, image=img_waves)
waves.grid(row=1, column=3)
choose_waves = tk.Button(root, text="Choose", command=partial(
self.human_choice, img_waves, mode, att, name, mood, start_time, root
))
choose_waves.grid(row=2, column=3)
img_square = tk.PhotoImage(master=root, file="images/square.gif")
self.options.append(img_square)
square = tk.Canvas(root, width=141, height=169)
square.create_image(70, 84, image=img_square)
square.grid(row=1, column=4)
choose_square = tk.Button(root, text="Choose", command=partial(
self.human_choice, img_square, mode, att, name, mood, start_time, root
))
choose_square.grid(row=2, column=4)
img_star = tk.PhotoImage(master=root, file="images/star.gif")
self.options.append(img_star)
star = tk.Canvas(root, width=141, height=169)
star.create_image(70, 84, image=img_star)
star.grid(row=1, column=5)
choose_star = tk.Button(root, text="Choose", command=partial(
self.human_choice, img_star, mode, att, name, mood, start_time, root
))
choose_star.grid(row=2, column=5)
att.grid(row=3, column=1, columnspan=5)
if mode.get() == 2:
self.cpu_choice = choice(self.options)
root.mainloop()
def human_choice(self, img, mode, att, name, mood, start_time, root):
timestamp = time()
self.attempts += 1
if mode.get() == 1:
self.cpu_choice = choice(self.options)
if img == self.cpu_choice:
success = 1
#print('Psychic!')
else:
success = 0
#print('Dunce!')
self.data[self.attempts] = [str(success), str(timestamp)]
att.configure(text=str(self.attempts)+'/'+str(self.length))
if self.attempts == self.length:
self.record_data(mode, name, mood, start_time)
root.destroy()
if mode.get() == 2:
self.cpu_choice = choice(self.options)
def record_data(self, mode, name, mood, start_time):
self.brain_parent.send('Done!')
if self.heart_parent:
self.heart_parent.send('Done!')
for x in self.data.keys():
print('Attempt #:', str(x))
print(self.data[x][1] + ': ' + self.data[x][0])
db = Connection('db.sqlite')
curs = db.cursor()
if mode.get() == 1:
_type = 'zener_precognition'
elif mode.get() == 2:
_type = 'zener_clairvoyance'
filepath = 'Biofeedback/' + name.get().replace(' ', '_') + '/zener/' + start_time + '/'
tests_insert = (
'insert into Tests (Name, Mood, Type, CSV_filepath) ' +
'Values ("'+name.get()+'", "'+mood.get('1.0', 'end')+'", "'+_type+'", "'+filepath+'");'
)
print(tests_insert)
curs.execute(tests_insert)
try:
test_num = str(curs.execute('select max(Number) from Tests;').fetchall()[0][0] + 1)
except TypeError:
test_num = '1'
table_name = 'test' + test_num
create_test = """
CREATE TABLE """ + table_name + """(
Number INTEGER NOT NULL,
Guess INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
Correct INTEGER NOT NULL,
Timestamp REAL NOT NULL
);"""
print(create_test)
curs.execute(create_test)
for x in self.data.keys():
created_insert = (
'INSERT INTO '+table_name+' (Number, Guess, Correct, Timestamp) ' +
'Values ('+test_num+', '+str(x)+', '+self.data[x][0]+', '+self.data[x][1]+');'
)
print(created_insert)
curs.execute(created_insert)
db.commit()
curs.close()
db.close()
if __name__ == '__main__':
pass