-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCVSimulationGUI.py
1272 lines (944 loc) · 52.9 KB
/
CVSimulationGUI.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
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
#DSA1002 -- CoronaVirus Simulation
#CVSimulationGUI.py -- GUI Codebase
#Shae Sullivan -- 90016419
#Curtin Campus
import sys
import csv
import time
import tkinter as tk
import matplotlib
import matplotlib.animation as animation
import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
import random
from tkinter import *
from tkinter import messagebox
from tkinter.messagebox import showinfo
from tkinter import ttk
from PIL import ImageTk, Image
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
from matplotlib import style
from DSANetwork import Network
from DSALinkL import Node, LinkL
from DSAHashT import DSA_Hash_Table
""" Creating Social Network """
""" Calling on Network SuperClass [all methods in chain are of NetworkClass] """
""" Network Top Level Class Associates: DSA_Linked_List, DSA_Hash_Table """
""" network setter --> MAIN DRIVER for social network"""
"""Interactive menu Main"""
"""GUI build"""
matplotlib.use('TkAgg')
style.use("fivethirtyeight")
LARGE_FONT = ("Blacklisted", 16)
QUICK_FONT = ("Blacklisted", 12)
TITLE_FONT = ("Blacklisted", 20)
HEIGHT = 25
WIDTH = 60
"""declaring network variable"""
graph = Network()
class interactive_menu(tk.Tk, Network):
global HEIGHT
global WIDTH
"""Interactive menu class"""
"""Inherits from Network class"""
def __init__(self, *args, **kwargs):
self.graph = Network()
tk.Tk.__init__(self, *args, **kwargs)
self.title('SNDSS')
self.geometry("800x650")
self.resizable(0,0)
self.list = tk.Listbox(self)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for f in (LaunchPage, StartPage, PageOne, PageTwo, PageThree):
frame = f(container, self)
self.frames[f] = frame
frame.grid(row = 0, column = 0, sticky="nsew")
self.show_frame(LaunchPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class LaunchPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.image = Image.open("CVBGUI.gif")
self.img_cp = self.image.copy()
self.background_image = ImageTk.PhotoImage(self.image)
self.background = Label(self, image = self.background_image)
self.background.pack(fill = BOTH, expand = YES)
label = tk.Label(self, text= "CoronaVirus Social Network Spread Simulator", font= TITLE_FONT, fg = "green")
label.place(x = 140, y = 250)
filename_input = tk.Text(self, height = 2, width = 35, bg= "light pink")
open_command = tk.Button(self, text= "Open", command=lambda: self.load_network(filename_input, controller), fg= "black", bg= "green", height= 2, width = 10)
button1 = ttk.Button(self, text="Load Network", command=lambda: self.load_network_prompt(filename_input, open_command))
button1.place(x = 350, y = 335)
button2 = ttk.Button(self, text= "Use Demo Network", command=lambda: self.demo_network(controller))
button2.place(x = 335, y = 400)
def load_network_prompt(self, filename_input, open_command):
filename_input.place(x = 245, y = 500)
open_command.place(x = 345, y = 580)
def load_network(self, filename_input, controller):
filename = str(filename_input.get("1.0", "end-1c"))
try:
graph.network_loader(filename)
controller.show_frame(StartPage)
return
except FileNotFoundError:
print("This file was not found in the current search path")
return
def demo_network(self, controller):
try:
graph.add_person('mary', [58, 'female'])
graph.add_person('john', [87, 'male'])
graph.add_person('susan', [55, 'female'])
graph.add_person('bob', [40, 'male'])
graph.add_person('len', [19, 'male'])
graph.add_person('mike', [45, 'male'])
graph.add_person('don', [22, 'male'])
graph.add_person('harold', [16, 'male'])
graph.add_person('michelle', [43, 'female'])
graph.add_person('logan', [24, 'male'])
graph.add_person('julie', [44, 'female'])
graph.add_person('harry', [67, 'male'])
graph.add_person('isla', [66, 'female'])
graph.add_person('sam', [8, 'male'])
graph.add_connection({'john', 'susan'})
graph.add_connection({'mary', 'bob'})
graph.add_connection({'john', 'mary'})
graph.add_connection({'susan', 'john'})
graph.add_connection({'bob', 'mary'})
graph.add_connection({'susan', 'bob'})
graph.add_connection({'susan', 'mary'})
graph.add_connection({'mary', 'john'})
graph.add_connection({'john', 'bob'})
graph.add_connection({'bob', 'susan'})
graph.add_connection({'bob', 'john'})
graph.add_connection({'mary', 'susan'})
graph.add_connection({'john', 'susan'})
graph.add_connection({'mary', 'bob'})
graph.add_connection({'john', 'mary'})
graph.add_connection({'susan', 'john'})
graph.add_connection({'bob', 'mary'})
graph.add_connection({'susan', 'bob'})
graph.add_connection({'susan', 'mary'})
graph.add_connection({'mary', 'john'})
graph.add_connection({'john', 'bob'})
graph.add_connection({'len', 'mary'})
graph.add_connection({'harold', 'len'})
graph.add_connection({'len', 'john'})
graph.add_connection({'susan', 'len'})
graph.add_connection({'mike', 'len'})
graph.add_connection({'mike', 'mary'})
graph.add_connection({'don', 'john'})
graph.add_connection({'don', 'harold'})
graph.add_connection({'len', 'mike'})
graph.add_connection({'mary', 'don'})
graph.add_connection({'susan', 'mike'})
graph.add_connection({'john','harold'})
graph.add_connection({'harold', 'bob'})
graph.add_connection({'harold', 'mary'})
graph.add_connection({'harold', 'susan'})
graph.add_connection({'mary', 'michelle'})
graph.add_connection({'michelle', 'mary'})
graph.add_connection({'bob', 'michelle'})
graph.add_connection({'susan', 'michelle'})
graph.add_connection({'michelle', 'bob'})
graph.add_connection({'michelle', 'susan'})
graph.add_connection({'mary', 'logan'})
graph.add_connection({'john', 'logan'})
graph.add_connection({'susan', 'logan'})
graph.add_connection({'logan', 'mary'})
graph.add_connection({'logan', 'harold'})
graph.add_connection({'julie', 'mary'})
graph.add_connection({'bob', 'sam'})
graph.add_connection({'sam', 'michelle'})
graph.add_connection({'isla', 'bob'})
graph.add_connection({'michelle', 'isla'})
graph.add_connection({'mary', 'harry'})
graph.add_connection({'harry', 'logan'})
graph.add_connection({'susan', 'harry'})
graph.add_connection({'julie', 'mary'})
graph.add_connection({'logan', 'sam'})
controller.show_frame(StartPage)
return
except ValueError:
print("An Error Occured :( ")
return
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.image = Image.open("CVBGUI.gif")
self.img_cp = self.image.copy()
self.background_image = ImageTk.PhotoImage(self.image)
self.background = Label(self, image = self.background_image)
self.background.pack(fill = BOTH, expand = YES)
label = tk.Label(self, text="Main Menu", font=LARGE_FONT)
label.place(x = 350, y = 50)
button1 = ttk.Button(self, text="Person Add/Deletion Support", command=lambda: controller.show_frame(PageOne))
button1.place(x = 320, y = 100)
button2 = ttk.Button(self, text="Statistics", command=lambda: controller.show_frame(PageTwo))
button2.place(x = 360, y = 150)
button3 = ttk.Button(self, text="Simulate Support", command=lambda: controller.show_frame(PageThree))
button3.place(x = 348, y = 200)
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.image = Image.open("CVBGUI.gif")
self.img_cp = self.image.copy()
self.background_image = ImageTk.PhotoImage(self.image)
self.background = Label(self, image = self.background_image)
self.background.pack(fill = BOTH, expand = YES)
label = tk.Label(self, text="Person Add/Deletion Support", font=LARGE_FONT)
label.place(x=250, y=50)
self.pr = tk.Listbox(self, height = 20, width = 35, font = QUICK_FONT)
pr_text = tk.Label(self, text="Personal Records", font = LARGE_FONT)
person_input = tk.Text(self, height = 2, width = 35, bg= 'light green')
age_input = tk.Text(self, height = 2, width = 15, bg = 'light green')
person1_connection = tk.Text(self, height = 2, width = 35, bg = 'light green')
person2_connection = tk.Text(self, height = 2, width = 35, bg = 'light green')
button1 = ttk.Button(self, text="Back to Main Menu", command=lambda: controller.show_frame(StartPage))
button1.place(x = 345, y = 75)
button2 = ttk.Button(self, text="Statistics", command=lambda: controller.show_frame(PageTwo))
button2.place(x = 360, y = 100)
button3 = ttk.Button(self, text="Add Person", command=lambda: self.addition_person(person_input, age_input, add_commmand, delete_command, find_command, person1_connection, person2_connection, add_connection_command, del_connection_command))
button3.place(x = 360, y = 125)
button7 = ttk.Button(self, text="Find Person", command=lambda: self.find_person(person_input, find_command, age_input, add_commmand, delete_command, person1_connection, person2_connection, add_connection_command, del_connection_command))
button7.place(x = 360, y = 150)
button4 = ttk.Button(self, text="Delete Person", command=lambda: self.deletion_person(person_input, delete_command, add_commmand, age_input, find_command, person1_connection, person2_connection, add_connection_command, del_connection_command))
button4.place(x = 357, y = 175)
button5 = ttk.Button(self, text="Add Connection Between 2 People", command=lambda: self.add_connection(person1_connection, person2_connection, add_connection_command, person_input, find_command, age_input, add_commmand, delete_command, del_connection_command))
button5.place(x = 320, y = 200)
button6 = ttk.Button(self, text="Delete Connection Between 2 People", command=lambda: self.del_connection(person1_connection, person2_connection, del_connection_command, add_connection_command, person_input, find_command, age_input, add_commmand, delete_command))
button6.place(x = 315, y = 225)
button7 = ttk.Button(self, text="Print Personal Records", command=lambda: self.personal_rec_print(pr_text, person1_connection, person2_connection, del_connection_command, add_connection_command, person_input, find_command, age_input, add_commmand, delete_command, button8))
button7.place(x = 340, y = 250)
csv_download = tk.Label(self, text = "Enter File Name", font = LARGE_FONT)
csv_input = tk.Text(self, height = 1, width = 15, bg = 'light pink')
save_csv_command = ttk.Button(self, text= "Save", command=lambda: self.save_record_process(csv_input))
button8 = ttk.Button(self, text="Save CSV", command=lambda: self.save_record(csv_download, csv_input, save_csv_command))
add_commmand = tk.Button(self, text="Add", fg= 'black', bg= 'green', command=lambda: self.addition_process(person_input, age_input), height = 3, width = 25)
delete_command = tk.Button(self, text="Delete", fg= 'black', bg= 'red', command=lambda: self.deletion_process(person_input), height = 3, width = 25)
add_connection_command = tk.Button(self, text="Add Connection", fg= 'black', bg= 'green', command=lambda: self.connection_add_process(person1_connection, person2_connection), height = 3, width = 25)
del_connection_command = tk.Button(self, text="Delete Connection", fg= 'black', bg= 'red', command=lambda: self.connection_del_process(person1_connection, person2_connection), height = 3, width = 25)
find_command = tk.Button(self, text="Find", fg= 'black', bg= 'purple', command=lambda: self.finding_process(person_input))
def addition_person(self, person_input, age_input, add_commmand, delete_command, find_command, person1_connection, person2_connection, add_connection_command, del_connection_command):
find_command.place_forget()
delete_command.place_forget()
person1_connection.place_forget()
person2_connection.place_forget()
add_connection_command.place_forget()
del_connection_command.place_forget()
person_input.place(x = 250, y = 300)
age_input.place(x = 330, y = 350)
add_commmand.place(x = 300, y = 400)
def addition_process(self, person_input, age_input):
person = person_input.get("1.0", "end-1c")
info = age_input.get("1.0", "end-1c")
graph.add_person(str(person), info)
added_finish = tk.Label(self, text = "Added Complete!", font = QUICK_FONT)
added_finish.place(x = 300, y = 600)
return
def deletion_person(self, person_input, delete_command, add_commmand, age_input, find_command, person1_connection, person2_connection, add_connection_command, del_connection_command):
add_commmand.place_forget()
find_command.place_forget()
age_input.place_forget()
person1_connection.place_forget()
person2_connection.place_forget()
add_connection_command.place_forget()
del_connection_command.place_forget()
person_input.place(x = 250, y = 350)
delete_command.place(x = 300, y = 400)
def deletion_process(self, person_input):
person = person_input.get("1.0", "end-1c")
graph.delete_person(str(person))
delete_finish = tk.Label(self, text = "Deletion Complete", font = QUICK_FONT)
delete_finish.place(x = 300, y = 600)
return
def find_person(self, person_input, find_command, age_input, add_commmand, delete_command, person1_connection, person2_connection, add_connection_command, del_connection_command):
age_input.place_forget()
add_commmand.place_forget()
delete_command.place_forget()
person1_connection.place_forget()
person2_connection.place_forget()
add_connection_command.place_forget()
del_connection_command.place_forget()
person_input.place(x = 250, y = 350)
find_command.place(x = 375, y = 400)
def finding_process(self, person_input):
person = person_input.get("1.0", "end-1c")
if graph.get_person(person):
found_person = tk.Label(self, text = "This Person is Within Social Network :)", font = QUICK_FONT)
found_person.place(x = 300, y = 600)
return
else:
found_person = tk.Label(self, text = "This Person is not Within Social Network :(", font = QUICK_FONT)
found_person.place(x = 300, y = 600)
return
def add_connection(self, person1_connection, person2_connection, add_connection_command, person_input, find_command, age_input, add_commmand, delete_command, del_connection_command):
person_input.place_forget()
find_command.place_forget()
age_input.place_forget()
add_commmand.place_forget()
delete_command.place_forget()
del_connection_command.place_forget()
person1_connection.place(x = 260, y = 300)
person2_connection.place(x = 260, y = 350)
add_connection_command.place(x = 310, y = 400)
def connection_add_process(self, person1_connection, person2_connection):
person1 = person1_connection.get("1.0", "end-1c")
person2 = person2_connection.get("1.0", "end-1c")
try:
graph.add_connection({str(person1), str(person2)})
connectionadd_finish = tk.Label(self, text = "Connection Added!", font = QUICK_FONT)
connectionadd_finish.place(x = 300, y = 600)
return
except ValueError:
print("one or both people don't exits within the social network")
return
def del_connection(self, person1_connection, person2_connection, del_connection_command, add_connection_command, person_input, find_command, age_input, add_commmand, delete_command):
person_input.place_forget()
find_command.place_forget()
age_input.place_forget()
add_commmand.place_forget()
delete_command.place_forget()
add_connection_command.place_forget()
person1_connection.place(x = 260, y = 300)
person2_connection.place(x = 260, y = 350)
del_connection_command.place(x = 310, y = 400)
def connection_del_process(self, person1_connection, person2_connection):
person1 = person1_connection.get("1.0", "end-1c")
person2 = person2_connection.get("1.0", "end-1c")
try:
graph.delete_connection(str(person1), str(person2))
connectiondel_finish = tk.Label(self, text = "Connection Deleted!", font = QUICK_FONT)
connectiondel_finish.place(x = 300, y = 600)
return
except ValueError:
print("one or both people don't exist within the social network")
return
def personal_rec_print(self, pr_text, person1_connection, person2_connection, del_connection_command, add_connection_command, person_input, find_command, age_input, add_commmand, delete_command, button8):
person_input.place_forget()
find_command.place_forget()
age_input.place_forget()
add_commmand.place_forget()
delete_command.place_forget()
add_connection_command.place_forget()
del_connection_command.place_forget()
person1_connection.place_forget()
person2_connection.place_forget()
pr = self.pr
for record in graph.personal_record.export():
pr.insert(0, str(record))
pr_text.place(x = 305, y = 350)
pr.place(x = 400, y = 375, anchor = 'n')
button8.place(x = 450, y = 475)
return
def save_record(self, csv_download, csv_input, save_csv_command):
csv_download.place(x = 450, y = 650)
csv_input.place(x = 475, y = 700)
save_csv_command.place(x = 500, y = 750)
def save_record_process(self, csv_input):
filename = csv_input.get("1.0", "end-1c")
try:
with open(str(filename), 'w', newline = '') as f:
writer = csv.writer(f, quoting = csv.QUOTE_ALL)
writer.writerow(["PERSONAL RECORD"])
for item in graph.personal_record.export():
writer.writerow(item)
return
except FileNotFoundError:
print("Sorry, this file can't be found in current path")
return
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.image = Image.open("CVBGUI.gif")
self.img_cp = self.image.copy()
self.background_image = ImageTk.PhotoImage(self.image)
self.background = Label(self, image = self.background_image)
self.background.pack(fill = BOTH, expand = YES)
label = tk.Label(self, text="Statistics", font=LARGE_FONT)
label.place(x= 340, y = 25)
self.list1 = tk.Listbox(self, height = 15, width = 20, font= QUICK_FONT)
self.list2 = tk.Listbox(self, height = 15, width = 20, font = QUICK_FONT)
self.list3 = tk.Listbox(self, height = 15, width = 20, font = QUICK_FONT)
self.list4 = tk.Listbox(self, height = 15, width = 20, font = QUICK_FONT)
s_header = tk.Label(self, text= "** Suspectables **", font = QUICK_FONT)
i_header = tk.Label(self, text= "** Infected **", font= QUICK_FONT)
r_header = tk.Label(self, text= "** Recovered **", font= QUICK_FONT)
d_header = tk.Label(self, text = "** Dead **", font = QUICK_FONT)
csv_download = tk.Label(self, text = "Enter File Name **(filename.csv)** to download as csv", font = LARGE_FONT)
csv_input = tk.Text(self, height = 2, width = 35, bg = 'light pink')
save_csv_command = ttk.Button(self, text= "Save", command=lambda: self.download_csv_command(csv_input))
button1 = ttk.Button(self, text="Back to Main Menu", command=lambda: controller.show_frame(StartPage))
button1.place(x = 340, y = 55)
button2 = ttk.Button(self, text="To Person Add/Deletion Support", command=lambda: controller.show_frame(PageOne))
button2.place(x = 310, y = 80)
button3 = tk.Button(self, text="Print Suspects", command=lambda: self.suspectable_current(s_header), fg='yellow', bg= 'black', height = 2, width = 25)
button3.place(x = 310, y = 105)
button4 = tk.Button(self, text="Print Infected", command=lambda: self.infected_current(i_header), fg='green', bg= 'black', height = 2, width = 25)
button4.place(x = 310, y = 145)
button5 = tk.Button(self, text="Print Recovered", command=lambda: self.recovered_current(r_header), fg='blue', bg= 'black', height = 2, width = 25)
button5.place(x = 310, y = 185)
button6 = tk.Button(self, text="Print Dead", command=lambda: self.dead_current(d_header), fg = 'grey', bg = 'black', height = 2, width = 25)
button6.place(x = 310, y = 225)
button7 = ttk.Button(self, text="Save CSV", command=lambda: self.download_csv(csv_download, csv_input, save_csv_command))
button7.place(x = 360, y = 265)
def suspectable_current(self, s_header):
suspects_box = self.list1
for person in graph.suspectable.export():
suspects_box.insert(0, str(person))
s_header.place(x = 60, y = 315)
suspects_box.place(x = 120, y=345, anchor= 'n')
return
def infected_current(self, i_header):
infected_box = self.list2
for person in graph.infected.export():
infected_box.insert(0, str(person))
i_header.place(x = 255, y = 315)
infected_box.place(x = 300, y = 345, anchor= 'n')
return
def recovered_current(self, r_header):
recovered_box = self.list3
for person in graph.recovered.export():
recovered_box.insert(0, str(person))
r_header.place(x = 445, y = 315)
recovered_box.place(x = 500, y = 345, anchor= 'n')
return
def dead_current(self, d_header):
dead_box = self.list4
for person in graph.dead.export():
dead_box.insert(0, str(person))
d_header.place(x = 640, y = 315)
dead_box.place(x = 680, y = 345, anchor= 'n')
return
def download_csv(self, csv_download, csv_input, save_csv_command):
csv_download.place(x = 125, y = 655)
csv_input.place(x = 250, y = 705)
save_csv_command.place(x = 350, y = 755)
def download_csv_command(self, csv_input):
filename = csv_input.get("1.0", "end-1c")
try:
with open(str(filename), 'w', newline = '') as f:
writer = csv.writer(f, quoting = csv.QUOTE_ALL)
writer.writerow(["SUSPECTS"])
writer.writerow(graph.suspectable.export())
writer.writerow(["INFECTED"])
writer.writerow(graph.infected.export())
writer.writerow(["RECOVERED"])
writer.writerow(graph.recovered.export())
writer.writerow(["DEAD"])
writer.writerow(graph.dead.export())
return
except FileNotFoundError:
print("Sorry, this file can't be found in current path")
return
class PageThree(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.image = Image.open("CVBGUI.gif")
self.img_cp = self.image.copy()
self.background_image = ImageTk.PhotoImage(self.image)
self.background = Label(self, image = self.background_image)
self.background.pack(fill = BOTH, expand = YES)
label = tk.Label(self, text="Simulation Support", font=LARGE_FONT)
label.place(x = 300, y = 25)
self.result_array = np.zeros((10+1,4))
self.results = tk.Listbox(self, height = 15, width = 20, font= QUICK_FONT)
"""Simulation Value Widgets"""
trans_text = tk.Label(self, text="Transmission Rate", font = QUICK_FONT)
trans_input = tk.Scale(self, orient = "horizontal", from_ = 0, to = 100, bg = "light green")
trans_text.place(x = 180, y = 125)
trans_input.place(x = 200, y = 150)
recov_text = tk.Label(self, text="Recovery Rate", font = QUICK_FONT)
recov_input = tk.Scale(self, orient = "horizontal", from_ = 0, to = 100, bg = "light blue")
recov_text.place(x = 350, y = 125)
recov_input.place(x = 360, y = 150)
death_text = tk.Label(self, text="Death Rate", font = QUICK_FONT)
death_input = tk.Scale(self, orient = "horizontal", from_ = 0, to = 100, bg = "light grey")
death_text.place(x = 520, y = 125)
death_input.place(x = 525, y = 150)
days_text = tk.Label(self, text="Days", font = QUICK_FONT)
days_input = tk.Text(self, height = 2, width = 6, bg = "azure")
days_text.place(x = 375, y = 200)
days_input.place(x = 370, y = 225)
"""Intervention Menu Prompt Button"""
interventions_text = ttk.Button(self, text="Interventions Menu", command=lambda: self.intervention_menu(inf_int_title, inf_int_rate, inf_int_time, inf_int_title2, death_int_title, death_int_title2, death_int_time, death_int_rate, rec_int_title, rec_int_title2, rec_int_time, rec_int_rate, interventions_text, intervention_command, trans_input, recov_input, death_input, button5, button3, button4, trans_text, recov_text, death_text, initial_infect, initial_infect_title, days_input, days_text, ex_slow, slow, reg_speed, fast, ex_fast, intervention_exit_button))
interventions_text.place(x = 340, y = 425)
"""Intervention Layout Widgets"""
death_int_title = tk.Label(self, text = "Start Day", font = QUICK_FONT)
death_int_title2 = tk.Label(self, text = "Death Rate", font = QUICK_FONT)
death_int_time = tk.Text(self, height = 2, width = 8, bg = "light grey")
death_int_rate = tk.Scale(self, orient = "horizontal", from_ = 0, to = 100, bg = "light grey")
inf_int_title = tk.Label(self, text="Start Day", font = QUICK_FONT)
inf_int_title2 = tk.Label(self, text="Transmission Rate", font = QUICK_FONT)
inf_int_time = tk.Text(self, height = 2, width = 8, bg= "light green")
inf_int_rate = tk.Scale(self, orient = "horizontal", from_= 0, to = 100, bg = "light green")
rec_int_title = tk.Label(self, text = "Start Day", font = QUICK_FONT)
rec_int_title2 = tk.Label(self, text = "Recovery Rate", font = QUICK_FONT)
rec_int_time = tk.Text(self, height = 2, width = 8, bg = "light blue")
rec_int_rate = tk.Scale(self, orient = "horizontal", from_ = 0, to = 100, bg = "light blue")
"""Initial Infect Widgets"""
initial_infect_title = tk.Label(self, text= "Enter Name Of Initial Infected Person", font = QUICK_FONT)
initial_infect = tk.Text(self, height = 2, width = 15, bg = "azure")
initial_infect_title.place(x = 280, y = 300)
initial_infect.place(x = 335, y = 350)
"""Results SIRD Title"""
sird_title = tk.Label(self, text= "S, I, R, D", font = LARGE_FONT)
"""Main Simulation Widgets"""
button1 = ttk.Button(self, text="Back to Main Menu", command=lambda: controller.show_frame(StartPage))
button1.place(x = 345, y = 50)
button2 = ttk.Button(self, text="To Statistics", command=lambda: controller.show_frame(PageTwo))
button2.place(x = 362.5, y = 75)
intervention_command = ttk.Button(self, text="Run With Intervention", command=lambda: self.activate_intervention(inf_int_time, inf_int_rate, death_int_rate, death_int_time, rec_int_rate, rec_int_time))
intervention_exit_button = ttk.Button(self, text="Return", command=lambda: self.intervention_exit(inf_int_title, inf_int_rate, inf_int_time, inf_int_title2, death_int_title, death_int_title2, death_int_time, death_int_rate, rec_int_title, rec_int_title2, rec_int_time, rec_int_rate, interventions_text, intervention_command, trans_input, recov_input, death_input, button5, button3, button4, button1, button2, trans_text, recov_text, death_text, initial_infect, initial_infect_title, days_input, days_text, ex_slow, slow, reg_speed, fast, ex_fast, intervention_exit_button))
button3 = ttk.Button(self, text="Run Simulation", command=lambda: self.plot(initial_infect, trans_input, recov_input, death_input, days_input))
button3.place(x = 350, y = 700)
button4 = ttk.Button(self, text="See Results Of Past Simulation", command=lambda: self.result_run(trans_input, recov_input, death_input, button5, button3, button4, intervention_command, trans_text, recov_text, death_text, interventions_text, inf_int_title, inf_int_title2, inf_int_time, inf_int_rate, initial_infect, initial_infect_title, days_input, days_text, sird_title))
button4.place(x = 310, y = 750)
button5 = ttk.Button(self, text="Reset", command=lambda: self.reset_sim(trans_input, recov_input, death_input, button5, button3, button4, intervention_command, trans_text, recov_text, death_text, interventions_text, inf_int_title, inf_int_title2, inf_int_time, inf_int_rate, initial_infect, initial_infect_title, days_input, days_text, sird_title))
"""Intervention Support Extra Widgets"""
self.g_trans_rate = 0
self.g_recov_rate = 0
self.g_death_rate = 0
self.g_days = 0
self.g_initial_infect = ""
"""Slow/Fast Motion Support Extra Widgets"""
self.ex_slow_set = True
self.slow_set = True
self.reg_speed_set = True
self.fast_set = True
self.ex_fast_set = True
"""Slow/Fast Motion Support Widgets"""
ex_slow = ttk.Button(self, text = "Extreme SlowMotion", command=lambda: self.ex_slow_method())
slow = ttk.Button(self, text = "SlowMotion", command=lambda: self.slow_method())
reg_speed = ttk.Button(self, text = "Normal Speed", command=lambda: self.reg_speed_method())
fast = ttk.Button(self, text = "FastMotion", command=lambda: self.fast_method())
ex_fast = ttk.Button(self, text = "Extreme FastMotion", command=lambda: self.ex_fast_method())
def ex_slow_method(self):
"""Activates Extreme Slow Motion"""
self.ex_slow_set = True
self.slow_set = False
self.reg_speed_set = False
self.fast_set = False
self.ex_fast_set = False
messagebox.showwarning("Motion Active", "Simulation Is Now Set To Extreme SlowMotion")
return
def slow_method(self):
"""Activates Extreme Slow Motion"""
self.slow_set = True
self.ex_slow_set = False
self.reg_speed_set = False
self.fast_set = False
self.ex_fast_set = False
messagebox.showwarning("Motion Active", "Simulation Is Now Set To SlowMotion")
return
def reg_speed_method(self):
"""Activates Extreme Slow Motion"""
self.reg_speed_set = True
self.ex_slow_set = False
self.slow_set = False
self.fast_set = False
self.ex_fast_set = False
messagebox.showwarning("Motion Active", "Simulation Is Now Set To Regular Speed")
return
def fast_method(self):
"""Activates Extreme Slow Motion"""
self.fast_set = True
self.ex_slow_set = False
self.slow_set = False
self.reg_speed_set = False
self.ex_fast_set = False
messagebox.showwarning("Motion Active", "Simulation Is Now Set To FastMotion")
return
def ex_fast_method(self):
"""Activates Extreme Slow Motion"""
self.ex_fast_set = True
self.ex_slow_set = False
self.slow_set = False
self.reg_speed_set = False
self.fast_set = False
messagebox.showwarning("Motion Active", "Simulation Is Now Set To Extreme FastMotion")
return
def intervention_menu(self, inf_int_title, inf_int_rate, inf_int_time, inf_int_title2, death_int_title, death_int_title2, death_int_time, death_int_rate, rec_int_title, rec_int_title2, rec_int_time, rec_int_rate, interventions_text, intervention_command, trans_input, recov_input, death_input, button5, button3, button4, trans_text, recov_text, death_text, initial_infect, initial_infect_title, days_input, days_text, ex_slow, slow, reg_speed, fast, ex_fast, intervention_exit_button):
try:
"""Holding Original Rates From Simulation Main Page"""
self.g_trans_rate = float( (trans_input.get()) / 100 )
self.g_death_rate = float( (death_input.get()) / 100 )
self.g_recov_rate = float( (recov_input.get()) / 100 )
self.g_days = int(days_input.get("1.0", "end-1c"))
self.g_initial_infect = str(initial_infect.get("1.0", "end-1c"))
"""Clear Home Page Simulation Buttons"""
trans_input.place_forget()
recov_input.place_forget()
death_input.place_forget()
button3.place_forget()
button4.place_forget()
intervention_command.place_forget()
trans_text.place_forget()
recov_text.place_forget()
death_text.place_forget()
interventions_text.place_forget()
inf_int_title.place_forget()
inf_int_title2.place_forget()
inf_int_time.place_forget()
inf_int_rate.place_forget()
initial_infect.place_forget()
initial_infect_title.place_forget()
days_input.place_forget()
days_text.place_forget()
inf_int_rate.place(x = 420, y = 200)
inf_int_time.place(x = 300, y = 200)
inf_int_title.place(x = 300, y = 150)
inf_int_title2.place(x = 400, y = 150)
intervention_command.place(x = 325, y = 600)
intervention_exit_button.place(x = 350, y = 500)
death_int_title.place(x = 300, y = 250)
death_int_title2.place(x = 415, y = 250)
death_int_time.place(x = 300, y = 300)
death_int_rate.place(x = 420, y = 300)
rec_int_title.place(x = 300, y = 350)
rec_int_title2.place(x = 407.5, y = 350)
rec_int_time.place(x = 300, y = 400)
rec_int_rate.place(x = 420, y = 400)
ex_slow.place(x = 145, y = 450)
slow.place(x = 270, y = 450)
reg_speed.place(x = 350, y = 450)
fast.place(x = 440, y = 450)
ex_fast.place(x = 520, y = 450)
except ValueError:
messagebox.showerror("Values Missing", "One Or More Rate Values Are Missing")
finally:
return
def activate_intervention(self, inf_int_time, inf_int_rate, death_int_rate, death_int_time, rec_int_rate, rec_int_time):
"""Added Intervention Support"""
"""Intervention Settings Obtainer"""
"""Infected Intervention"""
if inf_int_time.index("end") != 0:
inf_intervention_day = int(inf_int_time.get("1.0", "end-1c"))
inf_intervention_rate = float( (inf_int_rate.get()) / 100 )
pass
else:
pass
"""Death Interention"""
if death_int_time.index("end") != 0:
death_intervention_day = int(death_int_time.get("1.0", "end-1c"))
death_intervention_rate = float( (death_int_rate.get()) / 100 )
pass
else:
pass
"""Recovery Intervention"""
if rec_int_time.index("end") != 0:
rec_intervention_day = int(rec_int_time.get("1.0", "end-1c"))
rec_intervention_rate = float( (rec_int_rate.get()) / 100 )
pass
else:
pass
"""Original Simulation Rates and Settings"""
person = self.g_initial_infect
recov_rate = self.g_recov_rate
trans_const = self.g_trans_rate
death_rate = self.g_death_rate
days = self.g_days
"""SIRD Simulation Results Array"""
self.result_array = np.zeros((days+1, 4))
graph.add_initial(person)
for tt in range(1, days+1):
"""Intervention Activation"""
"""Transmission Rate Intervention Driver"""
if inf_intervention_day:
while tt >= inf_intervention_day:
trans_const = graph.inf_intervention(inf_intervention_rate, trans_const)
break
pass
"""Death Rate Intervention Driver"""
if death_intervention_day:
while tt >= death_intervention_day:
death_rate = graph.death_intervention(death_intervention_rate, death_rate)
break
pass
"""Recovery Rate Intervention Driver"""
if rec_intervention_day:
while tt >= rec_intervention_day:
recov_rate = graph.recov_intervention(rec_intervention_rate, recov_rate)
break
pass
graph.interact(person, tt, trans_const, recov_rate, death_rate)
"""SIRD Values For Each Iteration"""
S = graph.suspectable.size()
I = graph.infected.size()
R = graph.recovered.size()
D = graph.dead.size()
self.result_array[tt,:] = S, I, R, D
while tt == 1:
plt.figure(figsize=(20,10))
break
"""Pause Support For MatPlotLib"""
if self.ex_slow_set == True:
plt.pause(1.5)
pass
if self.slow_set == True:
plt.pause(1)
pass
if self.reg_speed_set == True:
plt.pause(0.5)
pass
if self.fast_set == True:
plt.pause(0.25)
pass
if self.ex_fast_set == True:
plt.pause(0.15)
pass
plt.subplot(1, 3, 1)
if inf_intervention_day:
while tt == inf_intervention_day:
plt.text(tt, 4, s = "--> INTERVENTION ACTIVE", color = 'green')
break
pass
if death_intervention_day:
while tt == death_intervention_day:
plt.text(tt, 6, s = "--> INTERVENTION ACTIVE", color = 'grey')
break
pass
if rec_intervention_day:
while tt == rec_intervention_day:
plt.text(tt, 8, s = "--> INTERVENTION ACTIVE", color = 'blue')
break
pass
"""Main Line Graph Support"""
plt.title("STATS GRAPH")
plt.xlabel("DAYS")
plt.ylabel("PEOPLE")
plt.plot(tt, self.result_array[tt, 0], 'yo', label = "SUSPECTS")
plt.plot(tt, self.result_array[tt, 1], 'go', label = "INFECTED")
plt.plot(tt, self.result_array[tt, 2], 'bo', label = "RECOVERED")
plt.plot(tt, self.result_array[tt, 3], 'ko', label = "DIED")
plt.subplots_adjust(wspace = 0.75)
while tt <= 1:
plt.legend(bbox_to_anchor = [0.5, 0.85], bbox_transform = plt.gcf().transFigure, fontsize = "x-small", loc = 'center', ncol = 4)
death_text = plt.text(0.45, 0.75, "DEATH RATE: " + str(death_rate * 100) + "%", transform = plt.gcf().transFigure, fontsize = 10)
inf_text = plt.text(0.45, 0.725, "INF RATE: " + str(trans_const * 100) + "%", transform = plt.gcf().transFigure, fontsize = 10)
recov_text = plt.text(0.45, 0.70, "RECOV RATE: " + str(recov_rate * 100) + "%", transform = plt.gcf().transFigure, fontsize = 10)
break
if inf_intervention_day:
while tt >= inf_intervention_day:
if tt == inf_intervention_day:
inf_prompt = plt.text(0.45, 0.25, "INFECTION RATE UPDATED", transform = plt.gcf().transFigure, fontsize = 20, color = 'green', fontname = "Blacklisted")