-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchive.py
More file actions
1177 lines (904 loc) · 43.2 KB
/
Copy patharchive.py
File metadata and controls
1177 lines (904 loc) · 43.2 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Archived Code
"""game.py"""
# def update_data(self):
# if self.screen.button_states['btnB'] == 1:
# record_blue(self.screen.game_mode.Cursor, self.screen.game_mode.freqprof, self.screen.game_mode.timer, self.mode_label, self.screen.nameNtr.get(), self.screen.trialNtr.get())
# elif self.screen.button_states['btnR'] == 1:
# record_red(self.screen.game_mode.Cursor, self.screen.game_mode.freqprof, self.screen.game_mode.timer, self.mode_label, self.screen.nameNtr.get(), self.screen.trialNtr.get())
# elif self.screen.button_states['btnG'] == 1:
# record_green(self.screen.game_mode.Cursor, self.screen.game_mode.freqprof, self.screen.game_mode.timer, self.mode_label, self.screen.nameNtr.get(), self.screen.trialNtr.get())
# elif self.screen.button_states['btnY'] == 1:
# record_yellow(self.screen.game_mode.Cursor, self.screen.game_mode.freqprof, self.screen.game_mode.timer, self.mode_label, self.screen.nameNtr.get(), self.screen.trialNtr.get())
# else:
# record_none(self.screen.game_mode.Cursor, self.screen.game_mode.freqprof, self.screen.game_mode.timer, self.mode_label, self.screen.nameNtr.get(), self.screen.trialNtr.get())
# for button in self.screen.button_states:
# self.screen.button_states[button] = 0
# self.screen.after(100, self.update_data)
"""ui.R"""
# library(shiny)
# library(magrittr)
# ui <- shinyServer(fluidPage(
# plotOutput("first_column")
# ))
"""server.R"""
# library(shiny)
# library(magrittr)
# library(shiny)
# library(magrittr)
# ui <- shinyServer(fluidPage(
# plotOutput("first_column")
# ))
# full_data <<- read.csv("test20.csv", header = TRUE)
# x <- 1
# server <- shinyServer(function(input, output, session){
# # Function to get new observations
# get_new_data <- function(){
# data <- full_data[x:(x+4),] %>% rbind %>% data.frame
# return(data)
# }
# # Initialize my_data
# my_data <<- get_new_data()
# # Function to update my_data
# update_data <- function(){
# my_data <<- rbind(my_data, get_new_data())
# x <<- x + 5
# }
# # Plot the 30 most recent values
# output$first_column <- renderPlot({
# print("Render")
# invalidateLater(1000, session)
# update_data()
# print(my_data)
# plot(B1 ~ 1, data=my_data, ylim=c(-3, 3), las=1, type="l")
# })
# })
# # shinyApp(ui=ui, server=server)
"""chatGPTfreq.py"""
# import matplotlib.pyplot as plt
# import threading
# import time
# # Initialize lists to store button press frequencies
# colors = ['blue', 'red', 'green', 'yellow']
# button_presses = [[] for _ in colors]
# # Function to update the plot in real-time
# def update_plot():
# plt.ion() # Turn on interactive mode
# fig, ax = plt.subplots()
# lines = [ax.plot([], label=color)[0] for color in colors]
# ax.set_xlim(0, 10) # Adjust the x-axis limits as needed
# ax.set_ylim(0, 10) # Adjust the y-axis limits as needed
# ax.set_xlabel('Time (seconds)')
# ax.set_ylabel('Button Press Frequency')
# ax.legend()
# while True:
# for i, line in enumerate(lines):
# line.set_xdata(list(range(len(button_presses[i]))))
# line.set_ydata(button_presses[i])
# ax.relim()
# ax.autoscale_view()
# plt.pause(0.1) # Pause to update the plot
# # Function to simulate button presses and update the lists
# def simulate_button_presses():
# while True:
# try:
# button_index = int(input("Enter button index (0-blue, 1-red, 2-green, 3-yellow): "))
# if 0 <= button_index < len(colors):
# button_presses[button_index].append(len(button_presses[button_index]) + 1)
# except ValueError:
# print("Invalid input. Please enter a valid button index.")
# # Start the real-time plot update thread
# plot_thread = threading.Thread(target=update_plot)
# plot_thread.daemon = True # Allow the thread to exit when the main program exits
# plot_thread.start()
# # Start the button press simulation thread
# simulate_thread = threading.Thread(target=simulate_button_presses)
# simulate_thread.daemon = True
# simulate_thread.start()
# # Keep the main thread running
# while True:
# pass
"""convert.py"""
# Database
# import sqlite3
# # Read from and write to csv files
# import csv
# # Selects data for 1 game from SQLite database, then converts it to a CSV file that is ready to be turned into a frequency profile
# class Converter:
# # Creates database connection, stores game information: user name, game mode, and trial number
# def __init__(self, name, mode, trial):
# self.raw_data = sqlite3.connect('freqprof.db')
# self.Cursor = self.raw_data.cursor()
# self.name = name
# self.mode = mode
# self.trial = trial
# # Conversion function: inserts additional rows of all zeros such that the CSV file has 1 row for every .1 seconds of the trial
# def convert(self):
# # Select data from database that has the desired user name, game mode, and trial number
# self.Cursor.execute('SELECT * FROM FreqProf WHERE name = ? AND mode = ? AND trial = ?',
# (self.name, self.mode, self.trial))
# subset = self.Cursor.fetchall()
# # Print error message to terminal if sample is not continuous
# for n in range(len(subset) - 1):
# if subset[n][0] + 1 != subset[n + 1][0]:
# print("Error: sample is not continuous, may be a combination of multiple trials")
# # List to record how many additional data points need to be inserted after each row; 0th element stores row IDs and 1st element stores # of rows to add
# toAdd = [[], []]
# # Convert database subset to list
# subset_list = []
# for row in subset:
# subset_list.append(list(row))
# # Keep track of ID of first row of subset, to be subtracted from other IDs for indexing purposes
# starting_id = subset_list[0][0]
# # Round the 1st timestamp to the nearest 1/10 of a second
# subset_list[0][6] = (int(10 * subset_list[0][6])) / 10
# # For each row in the data, calculate how many rows we must add after this row
# for n in range(len(subset_list) - 1):
# # Round next timestamp to the nearest 1/10 of a second
# subset_list[n + 1][6] = (int(10 * subset_list[n + 1][6])) / 10
# # Calculate how many 1/10 second intervals are missing between this data point and the next
# interval = subset_list[n + 1][6] - subset_list[n][6]
# numMissing = round(interval * 10) - 1
# # print("n: " + str(subset_list[n][6]) + " n + 1: " + str(subset_list[n + 1][6]) + " numMissing: " + str(numMissing))
# # Store information about how many rows to add and where to add them
# toAdd[0].append(subset_list[n][0])
# toAdd[1].append(numMissing)
# new_row_counter = 0
# # Add rows after each row
# for i in range(len(toAdd[0])):
# # Index into data using the toAdd list, then add the correct number of rows filled with all zeros
# new_rows = []
# for j in range(toAdd[1][i]):
# new_rows.append([subset_list[toAdd[0][i] - starting_id + new_row_counter][0] + 0.5, 0, 0, 0, 0, 0, round((10 * (subset_list[toAdd[0][i] - starting_id + new_row_counter][6] + (j + 1)/10))) / 10, self.mode, self.name, self.trial])
# subset_list = subset_list[:toAdd[0][i] - starting_id + 1 + new_row_counter] + new_rows + subset_list[toAdd[0][i] - starting_id + 1 + new_row_counter:]
# # Keep track of how many rows were added, for indexing purposes
# new_row_counter += toAdd[1][i]
# # Export only the behavioral data, the labeling data will be stored in the title of the CSV file
# to_export = [row[1:5] for row in subset_list]
# # CSV file title with user name, game mode, and trial number
# test_file = f"Data/{self.name}_{self.mode}_{self.trial}.csv"
# # Write data to CSV file
# with open(test_file, 'w', newline='') as file:
# csv_writer = csv.writer(file)
# column_names = ['B1', 'B2', 'B3', 'B4']
# csv_writer.writerow(column_names)
# csv_writer.writerows(to_export)
# # Cursor.execute('SELECT * FROM FreqProf WHERE name = ? AND mode = ? AND trial = ? ORDER BY id ASC LIMIT 1',
# # ('RealSteven', 'B', 2))
# # first = Cursor.fetchall()
# # Cursor.execute('SELECT * FROM FreqProf WHERE name = ? AND mode = ? AND trial = ? ORDER BY id DESC LIMIT 1',
# # ('RealSteven', 'B', 2))
# # last = Cursor.fetchall()
# # Cursor.execute("CREATE TABLE test ")
# # print(first)
# # print(last)
# # print(last[0][6] - first[0][6])
"""full.py"""
# # touchscreen.py
# # # import modeA
# # # graphics library
# # from tkinter import *
# # # # data visualization
# # # import matplotlib as mpl
# # # import matplotlib.pyplot as plt
# # # import numpy as np
# # import random
# # random.seed(1965)
# from utilities import *
# from modeA import *
# class Game(Tk):
# def __init__(self):
# super().__init__()
# # for the easy version
# self.title("The Hard Easy Game")
# # set geometry (widthxheight)
# self.geometry('1360x710')
# self.resizable(width=False, height=False)
# # instructions
# subtitle = Label(self, text = "Choose game mode above, then click the buttons to get the dot to the right side of the screen. Have fun! :)")
# subtitle.place(anchor='nw')
# self.finish = Label(self, text="Finish Line")
# self.finish.place(x=1235, y=125)
# self.congrats = Label(self, text="Congratulations! You completed the game! Exit or try another mode.", bg='green')
# self.canvas = Canvas(self, bg="white", width=1250, height = 500)
# self.canvas.place(x=50, y=150)
# # self.canvas.pack(fill=BOTH, padx=50, pady=150, expand=True)
# # self.canvas.bind("<Configure>", self.on_resize)
# # initial position of dot
# dot_radius = 20
# self.init_x1 = 50 - dot_radius
# self.init_y1 = 250 - dot_radius
# self.init_x2 = 50 + dot_radius
# self.init_y2 = 250 + dot_radius
# # create dot
# self.dot = self.canvas.create_oval(self.init_x1, self.init_y1,
# self.init_x2, self.init_y2,
# outline='red', fill='red')
# self.line = self.canvas.create_line(1225, 0, 1225, 500)
# # self.update_dot_position("<Configure>")
# self.game_mode = None
# self.create_buttons()
# self.create_menu()
# self.move_B = ['g', 'y', 'r', 'b']
# self.move_C1 = ['g', 'g']
# self.move_C2 = ['r', 'y']
# self.input_seqB = []
# self.input_seqC = []
# self.blueCounter1 = 4
# self.blueDecrease1 = 1
# self.redCounter1 = 4
# self.redDecrease1 = 1
# self.yellowCounter1 = 4
# self.yellowDecrease1 = 1
# # self.bind("<Configure>", self.on_resize)
# # def on_resize(self, event):
# # # self.canvas_width = event.width
# # # self.canvas_height = event.height
# # # self.canvas.configure(width=self.canvas_width, height=self.canvas_height)
# # self.update_dot_position
# # def update_dot_position(self, event):
# # canvas_width = event.width
# # canvas_height = event.height
# # center_x = canvas_width // 2
# # center_y = canvas_height // 2
# # self.canvas.coords(self.dot, center_x - 10, center_y - 10,
# # center_x + 10, center_y + 10)
# def create_buttons(self):
# self.btnB = Button(self, width='14', height='6', bg='blue', command=self.move_blue)
# self.btnR = Button(self, width='14', height='6', bg='red', command=self.move_red)
# self.btnG = Button(self, width='14', height='6', bg='green', command=self.move_green)
# self.btnY = Button(self, width='14', height='6', bg='yellow', command=self.move_yellow)
# self.btnB.place(x='75', y='30')
# self.btnR.place(x='200', y='30')
# self.btnG.place(x='325', y='30')
# self.btnY.place(x='450', y='30')
# def create_menu(self):
# menubar = Menu(self)
# self.config(menu=menubar)
# game_menu = Menu(menubar, tearoff=0)
# game_menu.add_command(label='A', command=self.modeA)
# game_menu.add_command(label='B', command=self.modeB)
# game_menu.add_command(label='C', command=self.modeC)
# game_menu.add_command(label='1', command=self.mode1)
# menubar.add_cascade(label="Game Modes", menu=game_menu)
# # Mode A: simplest version, blue button moves dot right
# def modeA(self):
# gameA = ModeA()
# gameA.mainloop()
# # self.game_mode = "A"
# # self.congrats.place_forget()
# # Mode B: a specific sequence of 4 button presses moves dot right
# def modeB(self):
# self.game_mode = "B"
# self.congrats.place_forget()
# # Mode C: double-click green for 1st half, red-yellow for 2nd half
# def modeC(self):
# self.game_mode = "C"
# self.congrats.place_forget()
# def mode1(self):
# self.game_mode = "1"
# self.congrats.place_forget()
# def check_completion(self):
# if self.canvas.coords(self.dot)[2] >= 1225:
# self.game_mode = None
# self.congrats.place(x=50, y=675)
# x1, y1, x2, y2 = self.canvas.coords(self.dot)
# dx = self.init_x1 - x1
# dy = self.init_y1 - y1
# self.canvas.move(self.dot, dx, dy)
# def move_left(self):
# if self.canvas.coords(self.dot)[0] > 0:
# self.canvas.move(self.dot, -20, 0)
# def move_right(self):
# if self.canvas.coords(self.dot)[2] < 1250:
# self.canvas.move(self.dot, 20, 0)
# self.check_completion()
# def move_up(self):
# if self.canvas.coords(self.dot)[1] > 0:
# self.canvas.move(self.dot, 0, -20)
# def move_down(self):
# if self.canvas.coords(self.dot)[3] < 500:
# self.canvas.move(self.dot, 0, 20)
# # blue button
# def move_blue(self):
# if self.game_mode == "A":
# self.move_right()
# elif self.game_mode == "B":
# self.input_seqB.append('b')
# self.move_up()
# if self.input_seqB[-4:] == self.move_B:
# for num in range(4):
# self.move_right()
# elif self.game_mode == "C":
# self.input_seqC.append('b')
# elif self.game_mode == "1":
# randVal = random.randrange(1, self.blueCounter1)
# if randVal == 1 and self.blueCounter1 < 10:
# self.move_right()
# self.blueDecrease1 += 1
# if self.blueDecrease1 % 4 == 0:
# self.blueCounter1 += 1
# # red button
# def move_red(self):
# if self.game_mode == "A":
# self.move_left()
# elif self.game_mode == "B":
# self.input_seqB.append('r')
# self.move_down()
# elif self.game_mode == "C":
# self.input_seqC.append('r')
# elif self.game_mode == "1":
# randVal = random.randrange(1, self.redCounter1)
# if randVal == 1 and self.redCounter1 < 10:
# self.move_right()
# self.redDecrease1 += 1
# if self.redDecrease1 % 4 == 0:
# self.redCounter1 += 1
# # green button
# def move_green(self):
# if self.game_mode == "A":
# self.move_up()
# elif self.game_mode == "B":
# self.input_seqB.append('g')
# self.move_down()
# elif self.game_mode == "C":
# self.input_seqC.append('g')
# if self.input_seqC[-2:] == self.move_C1 and self.canvas.coords(self.dot)[0] <= 575:
# self.move_right()
# self.move_right()
# self.input_seqC = []
# elif self.game_mode == "1":
# randVal = random.randrange(1, 3)
# if randVal == 1:
# self.move_right()
# # yellow button
# def move_yellow(self):
# if self.game_mode == "A":
# self.move_down()
# elif self.game_mode == "B":
# self.input_seqB.append('y')
# self.move_up()
# elif self.game_mode == "C":
# self.input_seqC.append('y')
# if self.input_seqC[-2:] == self.move_C2 and self.canvas.coords(self.dot)[0] > 575:
# self.move_right()
# self.move_right()
# elif self.game_mode == "1":
# randVal = random.randrange(1, self.yellowCounter1)
# if randVal == 1 and self.yellowCounter1 < 10:
# self.move_right()
# self.yellowDecrease1 += 1
# if self.yellowDecrease1 % 4 == 0:
# self.yellowCounter1 += 1
# if __name__ == "__main__":
# game = Game()
# game.mainloop()
"""fakeFreq.py"""
# # Generate a sample frequency profile to inform the real-time generativity grapher
# from tkinter import *
# import matplotlib.pyplot as plt
# from random import *
# # fRoot = Tk()
# # fRoot.title("Frequency Profile")
# # fRoot.geometry('700x400')
# def genProf(b10, b20, b30, b40, epsilon, alpha, dataPoints):
# plt.ion()
# # store initial behavioral probabilities
# bvals = [[-2], [b10], [b20], [b30], [b40]]
# # recursively calculate subsequent probabilty data points for each behavior
# for num in range(dataPoints):
# # lambda matrix
# lm = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, -.2, 0, 0, 0], [0, 0, -.2, 0, 0], [0, 0, 0, -.1, 0]]
# # extinction matrix (quantity of decrease by extinction for each behavior)
# em = [0]
# # reinforcement matrix (quantity of increase by reinforcement for each behavior)
# am = [0]
# # interaction matrix (the interaction effects between each pair of behaviors, before summation)
# # encapsulates equations 3 (resurgence) and 4 (automatic chaining)
# im = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
# # populate matrices with values for this cycle
# for y in range(1, 5):
# em.append(-bvals[y][-1] * epsilon)
# am.append((1 - bvals[y][-1]) * alpha)
# for z in range(1, 5):
# if (y != z and len(bvals[z]) >= 2 and lm[y][z] >= -1 and lm[y][z] <= 1):
# if (lm[y][z] < 0 and bvals[z][-1] - bvals[z][-2] < 0):
# im[y][z] = (1 - bvals[y][-1]) * -lm[y][z] * bvals[z][-1]
# if (lm[y][z] > 0 and bvals[z][-1] - bvals[z][-2] > 0):
# im[y][z] = (1 - bvals[y][-1]) * lm[y][z] * bvals[z][-1]
# # print(im[y][z], end=" ")
# # print()
# for y in range(1, 5):
# epEffect = em[y]
# alphEffect = am[y]
# intEffect = 0
# for z in range(1, 5):
# intEffect += im[y][z]
# cur = bvals[y][-1]
# # add randomness
# wiggle = 0
# if cur > .01:
# wiggle = .005 * randrange(-1, 1)
# change = epEffect + alphEffect + intEffect + wiggle
# bNext = cur + change
# bvals[y].append(bNext)
# return bvals
# def makePlot():
# fvals = genProf(.15, .01, .01, .01, .06, 0, 100)
# plt.plot(range(len(fvals[1])), fvals[1], 'b', linestyle='dashed', label="Frequency 1")
# plt.plot(range(len(fvals[2])), fvals[2], 'r', linestyle='dashed', label="Frequency 2")
# plt.plot(range(len(fvals[3])), fvals[3], 'g', linestyle='dashed', label="Frequency 3")
# plt.plot(range(len(fvals[4])), fvals[4], 'y', linestyle='dashed', label="Frequency 4")
# plt.xlabel('Time')
# plt.ylabel('Probability of Behavior')
# plt.ylim(0, 1)
# plt.legend()
"""infrastructure.py"""
# x_data = np.arange(0, 10, 1)
# y_data = np.random.rand(len(x_data))
# line, = plt.plot(x_data, y_data, 'b', linestyle='solid', label="test")
# plt.show(block=False)
# while True:
# # Simulate gathering new data points
# new_data_point = np.random.rand()
# # Append the new data point to the existing data
# x_data = np.append(x_data, x_data[-1] + 1)
# y_data = np.append(y_data, new_data_point)
# # Update the data of the line
# line.set_data(x_data, y_data)
# # Update the plot
# plt.xlim(0, x_data[-1] + 1) # Adjust the x-axis limits
# plt.pause(1) # Pause for a short time to allow the plot to update
"""game.py"""
# timer = Timer()
# minigame = ModeA(game.screen.btnB, game.screen.btnR, game.screen.btnG, game.screen.btnY, game.screen.move_left, game.screen.move_right, game.screen.move_up, game.screen.move_down, game.screen, timer)
# ani = FuncAnimation(plt.gcf(), minigame.animate, interval=500)
# plt.show()
# testRoot.mainloop()
# def update_plot(self, frame):
# # Fetch new data from the database
# self.Cursor.execute("SELECT time, B1, B2, B3, B4 FROM FreqProf WHERE time > ?", (frame * 0.1,))
# new_data = self.Cursor.fetchall()
# # Update the plot data
# for row in new_data:
# self.x_data.append(row[6])
# self.y1_data.append(row[1])
# self.y2_data.append(row[2])
# self.y3_data.append(row[3])
# self.y4_data.append(row[4])
# # Update the line plot
# self.line1.set_data(self.x_data, self.y1_data)
# self.line2.set_data(self.x_data, self.y2_data)
# self.line3.set_data(self.x_data, self.y3_data)
# self.line4.set_data(self.x_data, self.y4_data)
# plt.legend()
# plt.show()
# def animate(self):
# """Notes to myself for next time:
# - this function should be present in each game mode, not the main game class, to run a separate animation for each"""
# # Create an animation that updates the plot every 0.1 seconds
# ani = FuncAnimation(self.fig, self.update_plot, repeat=False)
# # Display the plot
# plt.show()
# self.processing_thread = None
# self.processing_interval = 0.1 # seconds
# self.x_data = []
# self.y1_data = []
# self.y2_data = []
# self.y3_data = []
# self.y4_data = []
# self.fig, self.ax = plt.subplots()
# self.line1, = self.ax.plot(self.x_data, self.y1_data, 'b', linestyle='solid', label="Behavior 1")
# self.line2, = self.ax.plot(self.x_data, self.y2_data, 'r', linestyle='solid', label="Behavior 2")
# self.line3, = self.ax.plot(self.x_data, self.y3_data, 'g', linestyle='solid', label="Behavior 3")
# self.line4, = self.ax.plot(self.x_data, self.y4_data, linestyle='solid', label="Behavior 4")
# def process_data(self):
# while True:
# start_time = time()
# self.screen.event_generate("<<DataProcessed>>", when="tail")
# elapsed_time = time() - start_time
# if elapsed_time < self.processing_interval:
# sleep(self.processing_interval - elapsed_time)
# def update_data_table(self):
# if self.processing_thread is None:
# self.processing_thread = threading.Thread(target=self.process_data)
# self.processing_thread.start()
# self.screen.after(int(self.processing_interval * 1000), self.update_data_table)
# def handle_data(self, event):
# click = False
# if self.screen.button_states['btnB'] == 1 and self.screen.run == True:
# record_blue(self.Cursor, self.freqprof, self.screen.game_mode.timer, self.mode_label, self.screen.nameNtr.get(), self.screen.trialNtr.get())
# click = True
# if self.screen.button_states['btnR'] == 1 and self.screen.run == True:
# record_red(self.Cursor, self.freqprof, self.screen.game_mode.timer, self.mode_label, self.screen.nameNtr.get(), self.screen.trialNtr.get())
# click = True
# if self.screen.button_states['btnG'] == 1 and self.screen.run == True:
# record_green(self.Cursor, self.freqprof, self.screen.game_mode.timer, self.mode_label, self.screen.nameNtr.get(), self.screen.trialNtr.get())
# click = True
# if self.screen.button_states['btnY'] == 1 and self.screen.run == True:
# record_yellow(self.Cursor, self.freqprof, self.screen.game_mode.timer, self.mode_label, self.screen.nameNtr.get(), self.screen.trialNtr.get())
# click = True
# if click == False and self.screen.run == True:
# record_none(self.Cursor, self.freqprof, self.screen.game_mode.timer, self.mode_label, self.screen.nameNtr.get(), self.screen.trialNtr.get())
# for button in self.screen.button_states:
# self.screen.button_states[button] = 0
# self.Cursor.execute('SELECT * FROM FreqProf WHERE name = ? AND mode = ? AND trial = ?',
# (self.screen.nameNtr.get(), self.mode_label, self.screen.trialNtr.get()))
# self.subset = self.Cursor.fetchall()
# # Print error message to terminal if sample is not continuous
# for n in range(len(self.subset) - 1):
# if self.subset[n][0] + 1 != self.subset[n + 1][0]:
# print("Error: sample is not continuous, may be a combination of multiple trials")
"""modeTemplate.py"""
# def plot_data(self):
# plt.bar(self.button_clicks.keys(), self.button_clicks.values())
# plt.xlabel("Button")
# plt.ylabel("Click Count")
# plt.title("Button Click Count")
# plt.show
# def animate(self):
# self.current_time = time()
# while self.timestamps and self.current_time - self.timestamps[0] > 0.5:
# self.timestamp = self.timestamps.pop(0)
# for button, count in self.button_cloicks.items():
# print(f"{button}: {count}")
# self.plot_data()
# if self.timer.time_elapsed() > 10:
# window_start = round(self.timer.time_elapsed()) - 10
# index_start = 0
# for x in self.x_data:
# if x < window_start:
# index_start += 1
# else:
# break
# self.line1.set_data(self.x_data[index_start : -1], self.freq_data[0][index_start : -1])
# self.line2.set_data(self.x_data[index_start : -1], self.freq_data[1][index_start : -1])
# self.line3.set_data(self.x_data[index_start : -1], self.freq_data[2][index_start : -1])
# self.line4.set_data(self.x_data[index_start : -1], self.freq_data[3][index_start : -1])
"""grapher.py"""
# def fourClicked():
# prob = Label(lvl2, text = "Enter Initial Probabilities")
# prob.grid(column = 0, row = 0)
# behav1 = Label(lvl2, text = "Behavior 1: ")
# behav1.grid(column = 0, row = 1)
# behav1Ntr = Entry(lvl2, width = 10)
# behav1Ntr.grid(column = 1, row = 1)
# lbl.configure(text = prob + behav1 + behav1Ntr)
"""params.py"""
# # help button on menu
# def helpClicked():
# lbl.configure(text = "epsilon is the extinction rate," \
# " change this value and see how the graph changes")
# # menu: help + # of self.behaviors
# menu = Menu(self)
# lvl1 = Menu(menu)
# lvl2 = Menu(lvl1)
# menu.add_cascade(label='Menu', menu=lvl1)
# lvl1.add_command(label='Help', command=helpClicked)
# lvl1.add_cascade(label="# of self.behaviors", menu=lvl2)
# lvl2.add_command(label='4')
# lvl2.add_command(label='5')
# self.config(menu=menu)
"""modeTemplateThread.py"""
# # Base class for all game modes
# # Screen and utilities
# from infrastructure import *
# # from abc import ABC, abstractmethod
# # Game mode A: simplest version, blue button moves dot right
# class ModeTemplate:
# def __init__(self, screen, timer):
# self.screen = screen
# self.run = True
# # Get access to buttons on screen
# self.btnB = self.screen.btnB
# self.btnR = self.screen.btnR
# self.btnG = self.screen.btnG
# self.btnY = self.screen.btnY
# self.mode_char = self.screen.mode_char
# self.player_name = self.screen.nameNtr.get()
# self.trial_number = self.screen.trialNtr.get()
# # Get access to movement functions
# self.move_left = self.screen.move_left
# self.move_up = self.screen.move_up
# self.move_down = self.screen.move_down
# # Game stopwatch
# self.timer = timer
# # # Connect to database
# # self.freqprof = freqprof
# # self.Cursor = cursor
# self.button_clicks = {"blue": 0, "red": 0, "green": 0, "yellow": 0}
# # self.timestamps = []
# self.processing_thread = None
# self.processing_interval = 0.1 # seconds
# # self.data_queue = queue.Queue()
# self.x_data = []
# self.y1_data = []
# self.y2_data = []
# self.y3_data = []
# self.y4_data = []
# # self.animation_running = False
# def start(self):
# # Assign movement functions to buttons
# self.assign_btnB()
# self.assign_btnR()
# self.assign_btnG()
# self.assign_btnY()
# self.fig, self.ax = plt.subplots()
# self.line1, = self.ax.plot(self.x_data, self.y1_data, 'b', linestyle='solid', label="Behavior 1")
# self.line2, = self.ax.plot(self.x_data, self.y2_data, 'r', linestyle='solid', label="Behavior 2")
# self.line3, = self.ax.plot(self.x_data, self.y3_data, 'g', linestyle='solid', label="Behavior 3")
# self.line4, = self.ax.plot(self.x_data, self.y4_data, linestyle='solid', label="Behavior 4")
# self.update_data()
# self.animate()
# def update_clicks(self, button):
# self.button_clicks[button] = 1
# # self.timestamps.append(time())
# def process_data(self):
# # if self.animation_running == False:
# # self.animate()
# # self.animation_running = True
# # database connection
# self.freqprof = sqlite3.connect('freqprof.db')
# self.Cursor = self.freqprof.cursor()
# self.Cursor.execute("SELECT id FROM FreqProf ORDER BY id DESC LIMIT 1")
# self.last_id = self.Cursor.fetchone()
# while True:
# start_time = time()
# self.record_data()
# elapsed_time = time() - start_time
# if elapsed_time < self.processing_interval:
# sleep(self.processing_interval - elapsed_time)
# def update_data(self):
# if self.processing_thread is None:
# self.processing_thread = threading.Thread(target=self.process_data)
# self.processing_thread.start()
# self.screen.after(int(self.processing_interval * 1000), self.update_data)
# def record_data(self):
# print("hello")
# click = False
# if self.button_clicks['blue'] == 1 and self.run == True:
# record_blue(self.Cursor, self.freqprof, self.timer, self.mode_char, self.player_name, self.trial_number)
# click = True
# if self.button_clicks['red'] == 1 and self.run == True:
# record_red(self.Cursor, self.freqprof, self.timer, self.mode_char, self.player_name, self.trial_number)
# click = True
# if self.button_clicks['green'] == 1 and self.run == True:
# record_green(self.Cursor, self.freqprof, self.timer, self.mode_char, self.player_name, self.trial_number)
# click = True
# if self.button_clicks['yellow'] == 1 and self.run == True:
# record_yellow(self.Cursor, self.freqprof, self.timer, self.mode_char, self.player_name, self.trial_number)
# click = True
# if click == False and self.run == True:
# record_none(self.Cursor, self.freqprof, self.timer, self.mode_char, self.player_name, self.trial_number)
# for button in self.button_clicks:
# self.button_clicks[button] = 0
# # def handle_data(self, event):
# # self.record_data()
# # self.update_plot()
# def update_plot(self, frame):
# # Fetch new data from the database
# # self.Cursor.execute("SELECT time, B1, B2, B3, B4 FROM FreqProf WHERE name = ? AND mode = ? AND trial = ? AND time > ?",
# # (self.screen.nameNtr.get(), self.screen.mode_char, self.screen.trialNtr.get(), frame * 0.1))
# self.Cursor.execute("SELECT time, B1, B2, B3, B4 FROM FreqProf WHERE name = ? AND mode = ? AND trial = ? AND time > ?",
# (self.player_name, self.mode_char, self.trial_number, frame * 0.1))
# new_data = self.Cursor.fetchall()
# for row in new_data:
# print(row)
# # if new_data[0][0] != self.last_id + 1:
# # sys.exit("Error: sample is not continuous, may be a combination of multiple trials")
# # for n in range(len(new_data) - 1):
# # if new_data[n][0] + 1 != new_data[n + 1][0]:
# # sys.exit("Error: sample is not continuous, may be a combination of multiple trials")
# # Update the plot data
# for row in new_data:
# self.x_data.append(row[0])
# self.y1_data.append(row[1])
# self.y2_data.append(row[2])
# self.y3_data.append(row[3])
# self.y4_data.append(row[4])
# # Update the line plot
# self.line1.set_data(self.x_data, self.y1_data)
# self.line2.set_data(self.x_data, self.y2_data)
# self.line3.set_data(self.x_data, self.y3_data)
# self.line4.set_data(self.x_data, self.y4_data)
# def animate(self):
# # Create an animation that updates the plot every 0.1 seconds
# self.ani = FuncAnimation(self.fig, self.update_plot, frames=itertools.count(), repeat=False, save_count=MAX_FRAMES)
# # Display the plot
# plt.legend()
# plt.show()
# # Button assignment functions; same for all game modes
# def assign_btnB(self):
# self.btnB.config(command=self.move_blue)
# def assign_btnR(self):
# self.btnR.config(command=self.move_red)
# def assign_btnG(self):
# self.btnG.config(command=self.move_green)
# def assign_btnY(self):
# self.btnY.config(command=self.move_yellow)
# # Move right function that sets run = False
# def move_right(self):
# run = self.screen.move_right(self.ani, self.run)
# self.run = run
# # Button movement functions: different across game modes
# # Move dot right, then record blue button click
# def move_blue(self):
# self.update_clicks("blue")
# # Move dot left, then record red button click
# def move_red(self):
# self.update_clicks("red")
# # Move dot up, then record green button click
# def move_green(self):
# self.update_clicks("green")
# # Move dot down, then record yellow button click
# def move_yellow(self):
# self.update_clicks("yellow")
""" realTimeGrapher.correct() """
# prob_values = []
# freq_values = []
# diffs = []
# for n in range(4):
# prob_values.append(prob_data[n][-(1 + PREDICTION_TIME * 10)])
# freq_values.append(freq_data[n][-1])
# diffs.append(freq_values[n] - prob_values[n])
# mean_error = 0
# # If undershooting on average, increase alpha and decrease epsilon. If overshooting on average, increase epsilon and decrease alpha
# for i in range(4):
# mean_error += diffs[i]
# mean_error /= 4
# self.alph += mean_error / 50
# self.ep -= mean_error / 50
# if self.alph < 0:
# self.alph = 0
# if self.ep < 0:
# self.ep = 0
# if self.alph > 1:
# self.alph = 1
# if self.ep > 1:
# self.ep = 1