-
Notifications
You must be signed in to change notification settings - Fork 0
/
seisen.py
721 lines (450 loc) · 29.6 KB
/
seisen.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
## built-in modules
import os
import time
import traceback
import threading
## custom modules
from handlers.local_handler import LocalHandler
from handlers.remote_handler import RemoteHandler
from handlers.file_handler import FileHandler
from handlers.settings_handler import SettingsHandler
from handlers.storage_settings_handler import StorageSettingsHandler
from modules.file_ensurer import FileEnsurer
from modules.score_rater import ScoreRater
from modules.toolkit import Toolkit
from modules.logger import Logger
class Seisen:
"""
Seisen is the main class for the Seisen project. Everything is handled by this class, directly or indirectly.
"""
## the current mode of seisen, "-1" is invalid and will force seisen to reprompt for a valid mode
current_mode:int = -1
## boolean that holds whether the user has a valid internet connection
has_valid_connection:bool = False
## the current question prompt
current_question_prompt:str = ""
## the current user guess
current_user_guess:str = ""
##--------------------start-of-handle_intensive_db_operations()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@staticmethod
def handle_intensive_db_operations() -> None:
"""
Handles intensive database operations. This is called in a separate thread to the main loop.
"""
## creates the daily local backup
LocalHandler.create_daily_local_backup()
## creates the daily remote backup
RemoteHandler.create_daily_remote_backup()
## overwrites remote with local
RemoteHandler.local_remote_overwrite()
##--------------------start-of-attempt_auto_repair()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@staticmethod
def attempt_auto_resolve() -> None:
"""
Attempts to auto repair local storage.
First will get confirmation from the user, if not given it will exit.
If given, it will attempt to reset local storage with remote storage, if that fails it will attempt to reset local and remote storage to default.
If even that fails, it will ask the user to contact the developer and exit.
"""
if(input("Error loading local storage, would you like Seisen to attempt to fix this? (data may be lost) (1 for yes, 2 for no) ") == "1"):
Logger.log_action("Error loading local storage, resetting local storage with remote storage.")
try:
StorageSettingsHandler.reset_local_with_remote(hard_reset=True)
LocalHandler.load_words_from_local_storage()
except Exception as e:
Logger.log_action("Error resetting local storage, resetting local and remote storage to default.",output=True, omit_timestamp=True)
traceback_str = traceback.format_exc()
Logger.log_action(traceback_str)
Logger.log_barrier()
try:
StorageSettingsHandler.reset_local_and_remote_to_default()
except Exception as e:
print("Cannot resolve automatically, please contact the developer. Check the log file for more information.")
traceback_str = traceback.format_exc()
Logger.log_action(traceback_str)
Logger.log_barrier()
Toolkit.pause_console()
Toolkit.exit_seisen()
Toolkit.pause_console()
else:
print("Please correct discrepancies in local storage yourself, or contact the developer.")
Toolkit.pause_console()
Toolkit.exit_seisen()
##--------------------start-of-bootup()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@staticmethod
def bootup() -> None:
"""
Bootup function for Seisen. This is called before the main loop.
"""
FileEnsurer.ensure_files()
Logger.clear_log_file()
Logger.log_barrier()
Logger.log_action("Bootup")
RemoteHandler.setup_connection_handler()
try:
## loads the words currently in local storage.
LocalHandler.load_words_from_local_storage()
except:
Seisen.attempt_auto_resolve()
os.system("title " + "Seisen")
Toolkit.maximize_window()
Seisen.has_valid_connection, update_prompt = Toolkit.check_update()
if(update_prompt != ""):
Toolkit.clear_console()
print(update_prompt)
Toolkit.pause_console()
Toolkit.clear_console()
##--------------------start-of-commence_main_loop()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@staticmethod
def commence_main_loop() -> None:
"""
The main loop for the Seisen project. Basically everything is done here.
"""
Logger.log_action("--------------------------------------------------------------")
Logger.log_action("Main Loop")
Logger.log_action("--------------------------------------------------------------")
## -1 is a code that forces the input to be changed
valid_modes = [1, 2, 3]
Toolkit.clear_console()
import random
while True:
if(Seisen.current_mode == 1):
Seisen.test_kana()
elif(Seisen.current_mode == 2):
choice = random.choice([1, 2])
if(choice == 1):
Seisen.test_vocab()
else:
Seisen.test_vocab_romaji()
elif(Seisen.current_mode == 3):
SettingsHandler.change_settings()
elif(Seisen.current_mode != -1): ## if invalid input, clear screen and print error
Toolkit.clear_console()
print("Invalid Input, please enter a valid number choice or 'q' to quit.\n")
if(Seisen.current_mode not in valid_modes): ## if invalid mode, change mode
Seisen.change_mode()
## modules outside seisen are forced to edit the mode in the loop data file when needed as they are unable to access the seisen object
Seisen.current_mode = int(FileHandler.read_seisen_line(FileEnsurer.loop_data_path, target_line=1,column=1))
##--------------------start-of-change_mode()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@staticmethod
def change_mode() -> None:
"""
Changes Seisen's active mode.
"""
main_menu_message = "Instructions:\nType q in select inputs to exit\nType v in select inputs to change the mode\nType z when entering in data to cancel\n\nPlease choose mode:\n\n1.Kana Practice\n2.Vocab Practice\n3.Settings\n"
print(main_menu_message)
old_mode = Seisen.current_mode
Seisen.current_mode = int(Toolkit.input_check("Number Choice No V", Toolkit.get_single_key(), 3, main_menu_message))
FileHandler.edit_seisen_line(FileEnsurer.loop_data_path, target_line=1, column_number=1, value_to_replace_to=str(Seisen.current_mode))
Logger.log_action("Current mode changed to " + str(Seisen.current_mode) + " was " + str(old_mode))
Toolkit.clear_console()
##--------------------start-of-test_kana()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@staticmethod
def test_kana() -> None:
"""
Tests the user on kana.
"""
Toolkit.clear_stream()
Toolkit.clear_console()
ROUND_COUNT_INDEX_LOCATION = 2
NUMBER_OF_CORRECT_ROUNDS_INDEX_LOCATION = 3
display_other = False
roma_triggered = False
## uses the word rater to get the kana we are gonna test, as well as the display list, but that is not used here
kana_to_test, _ = ScoreRater.get_kana_to_test(LocalHandler.kana)
## gets the total number of rounds and the number of correct rounds, then calculates the ratio
total_number_of_rounds = int(FileHandler.read_seisen_line(FileEnsurer.loop_data_path, 1, ROUND_COUNT_INDEX_LOCATION))
number_of_correct_rounds = int(FileHandler.read_seisen_line(FileEnsurer.loop_data_path, 1, NUMBER_OF_CORRECT_ROUNDS_INDEX_LOCATION))
round_ratio = str(round(number_of_correct_rounds / total_number_of_rounds, 2)) if total_number_of_rounds != 0 else "0.0"
Logger.log_action("Testing Kana... Round " + str(total_number_of_rounds))
Seisen.current_question_prompt = "You currently have " + str(number_of_correct_rounds) + " out of " + str(total_number_of_rounds) + " correct; Ratio : " + round_ratio + "\n"
Seisen.current_question_prompt += "Likelihood : " + str(kana_to_test.likelihood) + "%"
Seisen.current_question_prompt += "\n" + "-" * len(Seisen.current_question_prompt)
Seisen.current_question_prompt += "\nHow do you pronounce " + kana_to_test.main_testing_material.value + "?\n"
Seisen.current_user_guess = str(input(Seisen.current_question_prompt)).lower().strip()
all_testing_material = set([testing_material.value for testing_material in kana_to_test.testing_material])
all_furigana = set([reading.furigana for reading in kana_to_test.readings])
testing_material_string = '/'.join(all_testing_material)
furigana_string = '/'.join(all_furigana)
extended_prompt = testing_material_string + " (" + furigana_string + ")"
## if the user wants to change the mode do so
if(Seisen.current_user_guess == "v"):
Toolkit.clear_console()
Logger.log_action("--------------------------------------------------------------")
Logger.log_action("User chose to change mode")
Logger.log_action("--------------------------------------------------------------")
Seisen.change_mode()
return
elif(Seisen.current_user_guess == "b"): ## if the user wants to see the furigana do so
Toolkit.clear_console()
Seisen.current_question_prompt = Seisen.current_question_prompt.replace(kana_to_test.main_testing_material.value, extended_prompt)
Seisen.current_user_guess = str(input(Seisen.current_question_prompt)).lower()
roma_triggered = True
## if the user wants to change the mode do so
if(Seisen.current_user_guess == "v"):
Toolkit.clear_console()
Logger.log_action("--------------------------------------------------------------")
Logger.log_action("User chose to change mode")
Logger.log_action("--------------------------------------------------------------")
Seisen.change_mode()
return
total_number_of_rounds += 1
## checks if the users answer is correct
is_correct, Seisen.current_user_guess = ScoreRater.check_answers_word(kana_to_test, Seisen.current_user_guess, Seisen.current_question_prompt)
Logger.log_action("User guessed " + Seisen.current_user_guess + ", is_correct = " + str(is_correct))
Toolkit.clear_console()
if(roma_triggered == False):
Seisen.current_question_prompt = Seisen.current_question_prompt.replace(kana_to_test.main_testing_material.value, extended_prompt)
if(is_correct == True):
number_of_correct_rounds+=1
Seisen.current_question_prompt += "\n\nYou guessed " + Seisen.current_user_guess + ", which is correct.\n"
ScoreRater.log_correct_answer(kana_to_test)
elif(is_correct == False):
Seisen.current_question_prompt += "\n\nYou guessed " + Seisen.current_user_guess + ", which is incorrect, A correct answer was " + kana_to_test.main_answer.value + ".\n"
ScoreRater.log_incorrect_answer(kana_to_test)
else:
Seisen.current_question_prompt += "\n\nSkipped.\n"
ScoreRater.log_incorrect_answer(kana_to_test)
answers = [value.value for value in kana_to_test.answers]
for answer in answers: ## prints the other accepted answers
if(len(answers) == 1):
break
if(is_correct == None or is_correct == False and answer != Seisen.current_user_guess):
if(display_other == False):
Seisen.current_question_prompt += "\nOther Answers include:\n"
Seisen.current_question_prompt += "----------\n" + answer + "\n"
display_other = True
elif(is_correct == True and answer != Seisen.current_user_guess):
if(display_other == False):
Seisen.current_question_prompt += "\nOther Answers include:\n"
Seisen.current_question_prompt += "----------\n" + answer + "\n"
display_other = True
print(Seisen.current_question_prompt)
if(FileEnsurer.do_sleep_after_test == True):
time.sleep(2)
else:
Toolkit.pause_console()
Toolkit.clear_console()
FileHandler.edit_seisen_line(FileEnsurer.loop_data_path, 1, ROUND_COUNT_INDEX_LOCATION, str(total_number_of_rounds))
FileHandler.edit_seisen_line(FileEnsurer.loop_data_path, 1, NUMBER_OF_CORRECT_ROUNDS_INDEX_LOCATION, str(number_of_correct_rounds))
Logger.log_action("--------------------------------------------------------------")
##--------------------start-of-test_vocab()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@staticmethod
def test_vocab() -> None:
"""
Tests the user on vocab.
"""
Toolkit.clear_stream()
Toolkit.clear_console()
ROUND_COUNT_INDEX_LOCATION = 2
NUMBER_OF_CORRECT_ROUNDS_INDEX_LOCATION = 3
display_other = False
roma_triggered = False
## uses the word rater to get the vocab we are gonna test, as well as the display list, but that is not used here
vocab_to_test, _ = ScoreRater.get_vocab_to_test(LocalHandler.vocab)
all_testing_material = set([testing_material.value for testing_material in vocab_to_test.testing_material])
all_furigana = set([reading.furigana for reading in vocab_to_test.readings])
testing_material_string = '/'.join(all_testing_material)
furigana_string = '/'.join(all_furigana)
extended_prompt = testing_material_string + " (" + furigana_string + ")"
## gets the total number of rounds and the number of correct rounds, and calculates the ratio
total_number_of_rounds = int(FileHandler.read_seisen_line(FileEnsurer.loop_data_path, 1, ROUND_COUNT_INDEX_LOCATION))
number_of_correct_rounds = int(FileHandler.read_seisen_line(FileEnsurer.loop_data_path, 1, NUMBER_OF_CORRECT_ROUNDS_INDEX_LOCATION))
round_ratio = str(round(number_of_correct_rounds / total_number_of_rounds, 2)) if total_number_of_rounds != 0 else "0.0"
Logger.log_action("Testing Vocab... Round " + str(total_number_of_rounds))
Seisen.current_question_prompt = "You currently have " + str(number_of_correct_rounds) + " out of " + str(total_number_of_rounds) + " correct; Ratio : " + round_ratio + "\n"
Seisen.current_question_prompt += "Likelihood : " + str(vocab_to_test.likelihood) + "%"
Seisen.current_question_prompt += "\n" + "-" * len(Seisen.current_question_prompt)
Seisen.current_question_prompt += "\nWhat is the meaning of " + vocab_to_test.main_testing_material.value + "?\n"
## check if the main testing material has multiple occurrences, if so just display the extended prompt
for vocab in LocalHandler.vocab:
for testing_material in vocab.testing_material:
if(vocab_to_test.main_testing_material.value == testing_material.value and vocab_to_test.main_testing_material != testing_material):
Seisen.current_question_prompt = Seisen.current_question_prompt.replace(vocab_to_test.main_testing_material.value, extended_prompt)
break
Seisen.current_user_guess = str(input(Seisen.current_question_prompt)).lower().strip()
## if the user wants to change the mode do so
if(Seisen.current_user_guess == "v"):
Toolkit.clear_console()
Logger.log_action("--------------------------------------------------------------")
Logger.log_action("User chose to change mode")
Logger.log_action("--------------------------------------------------------------")
Seisen.change_mode()
return
## if the user wants to see the furigana do so
elif(Seisen.current_user_guess == "b"):
Toolkit.clear_console()
Seisen.current_question_prompt = Seisen.current_question_prompt.replace(vocab_to_test.main_testing_material.value, extended_prompt)
Seisen.current_user_guess = str(input(Seisen.current_question_prompt)).lower()
roma_triggered = True
## if the user wants to change the mode do so
if(Seisen.current_user_guess == "v"):
Toolkit.clear_console()
Logger.log_action("--------------------------------------------------------------")
Logger.log_action("User chose to change mode")
Logger.log_action("--------------------------------------------------------------")
Seisen.change_mode()
return
total_number_of_rounds += 1
## checks if the users answer is correct
is_correct, Seisen.current_user_guess = ScoreRater.check_answers_word(vocab_to_test, Seisen.current_user_guess, Seisen.current_question_prompt)
Logger.log_action("User guessed " + Seisen.current_user_guess + ", is_correct = " + str(is_correct))
Toolkit.clear_console()
if(roma_triggered == False):
Seisen.current_question_prompt = Seisen.current_question_prompt.replace(vocab_to_test.main_testing_material.value, extended_prompt)
if(is_correct == True):
number_of_correct_rounds+=1
your_guess = "You guessed " + Seisen.current_user_guess + ", which is correct.\n"
Seisen.current_question_prompt += "\n\n" + your_guess
ScoreRater.log_correct_answer(vocab_to_test)
elif(is_correct == False):
your_guess = "You guessed " + Seisen.current_user_guess + ", which is incorrect, a correct answer was " + vocab_to_test.main_answer.value + ".\n"
Seisen.current_question_prompt += "\n\n" + your_guess
ScoreRater.log_incorrect_answer(vocab_to_test)
else:
Seisen.current_question_prompt += "\n\nSkipped.\n"
ScoreRater.log_incorrect_answer(vocab_to_test)
answers = [value.value for value in vocab_to_test.answers]
for answer in answers: ## prints the other accepted answers
if(len(answers) == 1):
break
if(is_correct == None or is_correct == False and answer != Seisen.current_user_guess and answer != vocab_to_test.answers):
if(display_other == False):
Seisen.current_question_prompt += "\nOther Answers include:\n"
Seisen.current_question_prompt += "----------\n" + answer + "\n"
display_other = True
elif(is_correct == True and answer != Seisen.current_user_guess and answer != vocab_to_test.answers):
if(display_other == False):
Seisen.current_question_prompt += "\nOther Answers include:\n"
Seisen.current_question_prompt += "----------\n" + answer + "\n"
display_other = True
if(len(answers) >= 3):
print(Seisen.current_question_prompt + "\n" + your_guess)
else:
print(Seisen.current_question_prompt)
if(FileEnsurer.do_sleep_after_test == True):
time.sleep(Toolkit.long_sleep_constant)
else:
Toolkit.pause_console()
Toolkit.clear_console()
FileHandler.edit_seisen_line(FileEnsurer.loop_data_path, 1, ROUND_COUNT_INDEX_LOCATION, str(total_number_of_rounds))
FileHandler.edit_seisen_line(FileEnsurer.loop_data_path, 1, NUMBER_OF_CORRECT_ROUNDS_INDEX_LOCATION, str(number_of_correct_rounds))
Logger.log_action("--------------------------------------------------------------")
##--------------------start-of-test_vocab()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@staticmethod
def test_vocab_romaji() -> None:
"""
Tests the user on vocab in romaji.
"""
Toolkit.clear_stream()
Toolkit.clear_console()
ROUND_COUNT_INDEX_LOCATION = 2
NUMBER_OF_CORRECT_ROUNDS_INDEX_LOCATION = 3
display_other = False
roma_triggered = False
## uses the word rater to get the vocab we are gonna test, as well as the display list, but that is not used here
vocab_to_test, _ = ScoreRater.get_vocab_to_test(LocalHandler.vocab)
all_testing_material = set([testing_material.value for testing_material in vocab_to_test.testing_material])
first_5_answers = [value.value for value in vocab_to_test.answers[:5] if value.value not in [reading.romaji for reading in vocab_to_test.readings]]
testing_material_string = '/'.join(all_testing_material)
first_5_answers_string = '/'.join(first_5_answers)
extended_prompt = testing_material_string + " (" + first_5_answers_string + ")"
## gets the total number of rounds and the number of correct rounds, and calculates the ratio
total_number_of_rounds = int(FileHandler.read_seisen_line(FileEnsurer.loop_data_path, 1, ROUND_COUNT_INDEX_LOCATION))
number_of_correct_rounds = int(FileHandler.read_seisen_line(FileEnsurer.loop_data_path, 1, NUMBER_OF_CORRECT_ROUNDS_INDEX_LOCATION))
round_ratio = str(round(number_of_correct_rounds / total_number_of_rounds, 2)) if total_number_of_rounds != 0 else "0.0"
Logger.log_action("Testing Vocab... Round " + str(total_number_of_rounds))
Seisen.current_question_prompt = "You currently have " + str(number_of_correct_rounds) + " out of " + str(total_number_of_rounds) + " correct; Ratio : " + round_ratio + "\n"
Seisen.current_question_prompt += "Likelihood : " + str(vocab_to_test.likelihood) + "%"
Seisen.current_question_prompt += "\n" + "-" * len(Seisen.current_question_prompt)
Seisen.current_question_prompt += "\nHow do you pronounce " + vocab_to_test.main_testing_material.value + "?\n"
## check if the main testing material has multiple occurrences, if so just display the extended prompt
for vocab in LocalHandler.vocab:
for testing_material in vocab.testing_material:
if(vocab_to_test.main_testing_material.value == testing_material.value and vocab_to_test.main_testing_material != testing_material):
Seisen.current_question_prompt = Seisen.current_question_prompt.replace(vocab_to_test.main_testing_material.value, extended_prompt)
break
Seisen.current_user_guess = str(input(Seisen.current_question_prompt)).lower().strip()
## if the user wants to change the mode do so
if(Seisen.current_user_guess == "v"):
Toolkit.clear_console()
Logger.log_action("--------------------------------------------------------------")
Logger.log_action("User chose to change mode")
Logger.log_action("--------------------------------------------------------------")
Seisen.change_mode()
return
## if the user wants to see the furigana do so
elif(Seisen.current_user_guess == "b"):
Toolkit.clear_console()
Seisen.current_question_prompt = Seisen.current_question_prompt.replace(vocab_to_test.main_testing_material.value, extended_prompt)
Seisen.current_user_guess = str(input(Seisen.current_question_prompt)).lower()
roma_triggered = True
## if the user wants to change the mode do so
if(Seisen.current_user_guess == "v"):
Toolkit.clear_console()
Logger.log_action("--------------------------------------------------------------")
Logger.log_action("User chose to change mode")
Logger.log_action("--------------------------------------------------------------")
Seisen.change_mode()
return
total_number_of_rounds += 1
## checks if the users answer is correct
is_correct, Seisen.current_user_guess = ScoreRater.check_answers_word(vocab_to_test, Seisen.current_user_guess, Seisen.current_question_prompt, is_romaji_type=True)
Logger.log_action("User guessed " + Seisen.current_user_guess + ", is_correct = " + str(is_correct))
Toolkit.clear_console()
if(roma_triggered == False):
Seisen.current_question_prompt = Seisen.current_question_prompt.replace(vocab_to_test.main_testing_material.value, extended_prompt)
if(is_correct == True):
number_of_correct_rounds+=1
your_guess = "You guessed " + Seisen.current_user_guess + ", which is correct.\n"
Seisen.current_question_prompt += "\n\n" + your_guess
ScoreRater.log_correct_answer(vocab_to_test)
elif(is_correct == False):
your_guess = "You guessed " + Seisen.current_user_guess + ", which is incorrect, a correct answer was " + vocab_to_test.readings[0].romaji + ".\n"
Seisen.current_question_prompt += "\n\n" + your_guess
ScoreRater.log_incorrect_answer(vocab_to_test)
else:
Seisen.current_question_prompt += "\n\nSkipped.\n"
ScoreRater.log_incorrect_answer(vocab_to_test)
answers = [reading.romaji for reading in vocab_to_test.readings] + [reading.furigana for reading in vocab_to_test.readings]
for answer in answers: ## prints the other accepted answers
if(len(answers) == 1):
break
if(is_correct == None or is_correct == False and answer != Seisen.current_user_guess and answer != vocab_to_test.answers):
if(display_other == False):
Seisen.current_question_prompt += "\nOther Answers include:\n"
Seisen.current_question_prompt += "----------\n" + answer + "\n"
display_other = True
elif(is_correct == True and answer != Seisen.current_user_guess and answer != vocab_to_test.answers):
if(display_other == False):
Seisen.current_question_prompt += "\nOther Answers include:\n"
Seisen.current_question_prompt += "----------\n" + answer + "\n"
display_other = True
if(len(answers) >= 3):
print(Seisen.current_question_prompt + "\n" + your_guess)
else:
print(Seisen.current_question_prompt)
if(FileEnsurer.do_sleep_after_test == True):
time.sleep(Toolkit.long_sleep_constant)
else:
Toolkit.pause_console()
Toolkit.clear_console()
FileHandler.edit_seisen_line(FileEnsurer.loop_data_path, 1, ROUND_COUNT_INDEX_LOCATION, str(total_number_of_rounds))
FileHandler.edit_seisen_line(FileEnsurer.loop_data_path, 1, NUMBER_OF_CORRECT_ROUNDS_INDEX_LOCATION, str(number_of_correct_rounds))
Logger.log_action("--------------------------------------------------------------")
##--------------------start-of-main()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
try:
## run seisen
Seisen.bootup()
## Start the intensive DB operations in a separate thread after bootup
db_thread = threading.Thread(target=Seisen.handle_intensive_db_operations)
db_thread.start()
Seisen.commence_main_loop()
except Exception as e:
## if crash, catch and log, then throw
Logger.log_action("--------------------------------------------------------------")
Logger.log_action("Seisen has crashed")
traceback_str = traceback.format_exc()
Logger.log_action(traceback_str, output=True)
Logger.push_batch()
raise e