Skip to content

Commit afd40c8

Browse files
committed
Update buzzer, add README, add question files to gitignore
1 parent 1e472cb commit afd40c8

File tree

3 files changed

+55
-21
lines changed

3 files changed

+55
-21
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
*do_not_upload
2+
qanta/expo/questions_do_not_upload
13
*.swp
24
*.pyc
35
.idea

qanta/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Running the buzzer expo interface
2+
3+
## Setup
4+
Data files go in the folder `qanta/expo/questions_do_not_upload`.
5+
- Download and unzip the folder `questions_do_not_upload` from this Drive folder: https://drive.google.com/drive/u/0/folders/1SZWePX1PNjOZ8A_bbwwLZrp_ZVsykl61 (request access if needed).
6+
- Place it in `qanta/expo`. **Do not upload questions to GitHub. Questions should stay in questions_do_not_upload or the Drive.**
7+
- Download Tom in VoiceOver Utility: https://discussions.apple.com/thread/254892791. If you can't (e.g. don't have a Mac), comment out these lines in answer():
8+
`os.system("afplay /System/Library/Sounds/Glass.aiff")
9+
os.system("say -v Tom %s" % ans.replace("'", "").split("(")[0])``
10+
11+
## Commands
12+
- From inside `qanta/expo`, run the buzzer system:
13+
`python3 buzzer.py --questions [QUESTION FILE] --model_directory [MODEL FOLDER] --model [MODEL] --answer_equivalents [EQUIVALENTS FILE]`
14+
15+
Example:
16+
`python3 buzzer.py --questions questions_do_not_upload/packet_1.csv --model_directory questions_do_not_upload/2024_gpr_co --model packet_1 --answer_equivalents questions_do_not_upload/2024_gpr_co/equivalents_new.json --skip 1 --human 10 --computer 20`
17+
18+
- Buzzer check:
19+
When "Player 1, please buzz in" appears, press `1` on the keyboard.
20+
When "QANTA says" appears, press `Ctrl + X` on the keyboard.
21+
22+
- Press any key to print the next word of the question and to reveal the answer once the model has buzzed.
23+
24+
- Skipping ahead or correcting the score: use `skip [NUMBER OF QUESTIONS] --human [HUMAN SCORE] --computer [COMPUTER SCORE]`, e.g.:
25+
`python3 buzzer.py --questions questions_do_not_upload/2024_co/packet_1.csv --model_directory questions_do_not_upload/2024_gpr_co --model packet_1 --answer_equivalents questions_do_not_upload/2024_co/2024_gpr_co/equivalents_new.json --skip 1 --human 10 --computer 20`

qanta/expo/buzzer.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import sys
1414
import os
1515
import json
16-
16+
import pdb
1717
kSHOW_RIGHT = False
1818
kPAUSE = 0.25
1919

@@ -238,7 +238,7 @@ def print(text, color="RED", end="\n"):
238238
start = getattr(kCOLORS, color)
239239
print(start + text + kCOLORS.ENDC, end=end)
240240

241-
241+
242242
def parse_final(final_string):
243243
"""
244244
We have a string to show if we're at the end of the question, this code makes it more robust.
@@ -249,7 +249,7 @@ def parse_final(final_string):
249249
return 1
250250
else:
251251
return int(final_string)
252-
252+
253253

254254
def write_readable(filename, ids, questions):
255255
question_num = 0
@@ -274,8 +274,8 @@ def write_readable(filename, ids, questions):
274274

275275

276276
def clear_screen():
277-
print("Clearing")
278-
os.system("cls" if os.name == "nt" else "clear")
277+
# print("Clearing")
278+
os.system("cls" if os.name == "nt" else "clear") # TEMP
279279

280280

281281
class PowerPositions:
@@ -439,8 +439,9 @@ def add_guess(self, question, sent, word, system, guess, evidence, final, weight
439439
def add_system(self, file_path):
440440
buzzfile = DictReader(open("%s.buzz.csv" % file_path, "r"))
441441
system = file_path.replace("CMSC723_", "").split("/")[-1]
442-
system = system.split(".")[0]
443-
system = system.split("_")[0]
442+
#system = system.split(".")[0]
443+
#system = system.split("_")[0]
444+
system = system.replace("_"," ")
444445

445446
for ii in buzzfile:
446447
question, sent, word = (
@@ -473,6 +474,7 @@ def current_guesses(self, question, sent, word):
473474
for x in self._buzzes[question]
474475
if x[0] < sent or (x[0] == sent and x[1] <= max(0, word))
475476
)
477+
476478
except ValueError:
477479
return {}
478480

@@ -497,9 +499,9 @@ def answer_check(self, reference, guess):
497499
"""
498500
Check an answer for correctness
499501
"""
500-
502+
501503
return guess==reference or guess in self._equivalents.get(reference, [])
502-
504+
503505
def debug(self):
504506
self._questions[0] = {
505507
0: "His aliases include: Pastor Hansford of Free Will Baptist in Coushatta, Louisianna; Viktor with a K St. Claire, a South African who just inherited money from his uncle; Charlie Hustle, a mailboy in the HHM mailroom; and Gene Takavic, a Cinnabon manager in Omaha.",
@@ -538,8 +540,8 @@ def load_equivalents(self, equivalent_file):
538540

539541
for orig, replace in normalized:
540542
self.equivalents[replace] = self.equivalents[orig]
543+
print(self.equivalents)
541544

542-
543545
def load_power(self, power_file):
544546
self._power = PowerPositions(power_file)
545547

@@ -594,7 +596,8 @@ def format_display(
594596
current_guesses, key=lambda x: current_guesses[x].weight, reverse=True
595597
)[:guess_limit]:
596598
guess = current_guesses[gg]
597-
if answer.strip() == guess.page.strip():
599+
#print("answer:", answer.casefold().strip(), "guess", guess.page.casefold().strip())
600+
if answer.casefold().strip() == guess.page.casefold().strip():
598601
report += "%-18s\t%-50s\t%0.2f\t%s\n" % (
599602
guess.system,
600603
"***CORRECT***",
@@ -640,7 +643,7 @@ def answer(ans, system):
640643
os.system("afplay /System/Library/Sounds/Glass.aiff")
641644
os.system("say -v Tom %s" % ans.replace("'", "").split("(")[0])
642645
sleep(kPAUSE)
643-
print(ans)
646+
#print(ans)
644647

645648

646649
def present_question_hc(
@@ -660,7 +663,7 @@ def present_question_hc(
660663
human_delta = 0
661664
computer_delta = 0
662665
question_value = 15
663-
for ss in sorted(question_text):
666+
for ss in question_text:
664667
words = question_text[ss].split()
665668
for ii, ww in enumerate(words):
666669
# if we've reached the end of the question
@@ -671,7 +674,7 @@ def present_question_hc(
671674
system = random.choice(list(final.keys()))
672675
answer(final[system].split("(")[0], system)
673676
final = final[system]
674-
if correct == final:
677+
if correct.casefold().strip() == final.casefold().strip():
675678
return Score(human=human_delta, computer=10)
676679
else:
677680
print("Incorrect answer: %s" % final)
@@ -683,6 +686,8 @@ def present_question_hc(
683686
press = interpret_keypress()
684687
current_guesses = buzzes.current_guesses(question_id, ss, ii - 1)
685688
buzz_now = [x for x in current_guesses.values() if x.final]
689+
690+
#print(buzz_now)
686691
# Removing this assertion now that we can have multiple systems playing
687692
# assert len(buzz_now) < 2, "Cannot buzz on more than one thing"
688693
if isinstance(press, int):
@@ -720,13 +725,14 @@ def present_question_hc(
720725
)
721726
)
722727
answer(buzz_now[0].page.split("(")[0], buzz_now[0].system)
723-
if correct == buzz_now[0].page:
728+
if correct.casefold().strip() == buzz_now[0].page.casefold().strip():
729+
#pdb.set_trace()
724730
print("Computer guesses: %s (correct)" % buzz_now[0].page)
725-
sleep(1)
731+
sleep(5)
726732
return Score(human=human_delta, computer=question_value)
727733
else:
728734
print("Computer guesses: %s (wrong)" % buzz_now[0].page)
729-
sleep(1)
735+
sleep(5)
730736
computer_delta = -5
731737
show_score(
732738
score.human + human_delta,
@@ -812,7 +818,7 @@ def load_data(flags):
812818
questions.debug()
813819

814820
buzzes = Buzzes(flags.model_directory, questions)
815-
821+
816822
if flags.model_directory != "":
817823
for ii in glob("%s/*" % flags.model_directory):
818824
if ii.endswith(".buzz.csv"):
@@ -867,9 +873,10 @@ def question_loop(flags, questions, buzzes, present_question, check_tie):
867873
computer=flags.computer_start,
868874
)
869875
question_num = 0
870-
question_ids = sorted(questions._questions.keys(), key=lambda x: x % 10)
871-
#print(question_ids)
872-
#print(list(buzzes))
876+
#question_ids = sorted(questions._questions.keys(), key=lambda x: x % 10)
877+
question_ids = questions._questions.keys()
878+
# print(question_ids)
879+
# print(list(buzzes))
873880
question_ids = [x for x in question_ids if x in buzzes]
874881
#print(question_ids)
875882

0 commit comments

Comments
 (0)