Skip to content

Commit

Permalink
Update buzzer, add README, add question files to gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
efleisig committed Sep 20, 2024
1 parent 1e472cb commit afd40c8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*do_not_upload
qanta/expo/questions_do_not_upload
*.swp
*.pyc
.idea
Expand Down
25 changes: 25 additions & 0 deletions qanta/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Running the buzzer expo interface

## Setup
Data files go in the folder `qanta/expo/questions_do_not_upload`.
- 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).
- Place it in `qanta/expo`. **Do not upload questions to GitHub. Questions should stay in questions_do_not_upload or the Drive.**
- 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():
`os.system("afplay /System/Library/Sounds/Glass.aiff")
os.system("say -v Tom %s" % ans.replace("'", "").split("(")[0])``

## Commands
- From inside `qanta/expo`, run the buzzer system:
`python3 buzzer.py --questions [QUESTION FILE] --model_directory [MODEL FOLDER] --model [MODEL] --answer_equivalents [EQUIVALENTS FILE]`

Example:
`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`

- Buzzer check:
When "Player 1, please buzz in" appears, press `1` on the keyboard.
When "QANTA says" appears, press `Ctrl + X` on the keyboard.

- Press any key to print the next word of the question and to reveal the answer once the model has buzzed.

- Skipping ahead or correcting the score: use `skip [NUMBER OF QUESTIONS] --human [HUMAN SCORE] --computer [COMPUTER SCORE]`, e.g.:
`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`
49 changes: 28 additions & 21 deletions qanta/expo/buzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import sys
import os
import json

import pdb
kSHOW_RIGHT = False
kPAUSE = 0.25

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


def parse_final(final_string):
"""
We have a string to show if we're at the end of the question, this code makes it more robust.
Expand All @@ -249,7 +249,7 @@ def parse_final(final_string):
return 1
else:
return int(final_string)


def write_readable(filename, ids, questions):
question_num = 0
Expand All @@ -274,8 +274,8 @@ def write_readable(filename, ids, questions):


def clear_screen():
print("Clearing")
os.system("cls" if os.name == "nt" else "clear")
# print("Clearing")
os.system("cls" if os.name == "nt" else "clear") # TEMP


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

for ii in buzzfile:
question, sent, word = (
Expand Down Expand Up @@ -473,6 +474,7 @@ def current_guesses(self, question, sent, word):
for x in self._buzzes[question]
if x[0] < sent or (x[0] == sent and x[1] <= max(0, word))
)

except ValueError:
return {}

Expand All @@ -497,9 +499,9 @@ def answer_check(self, reference, guess):
"""
Check an answer for correctness
"""

return guess==reference or guess in self._equivalents.get(reference, [])

def debug(self):
self._questions[0] = {
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.",
Expand Down Expand Up @@ -538,8 +540,8 @@ def load_equivalents(self, equivalent_file):

for orig, replace in normalized:
self.equivalents[replace] = self.equivalents[orig]
print(self.equivalents)


def load_power(self, power_file):
self._power = PowerPositions(power_file)

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


def present_question_hc(
Expand All @@ -660,7 +663,7 @@ def present_question_hc(
human_delta = 0
computer_delta = 0
question_value = 15
for ss in sorted(question_text):
for ss in question_text:
words = question_text[ss].split()
for ii, ww in enumerate(words):
# if we've reached the end of the question
Expand All @@ -671,7 +674,7 @@ def present_question_hc(
system = random.choice(list(final.keys()))
answer(final[system].split("(")[0], system)
final = final[system]
if correct == final:
if correct.casefold().strip() == final.casefold().strip():
return Score(human=human_delta, computer=10)
else:
print("Incorrect answer: %s" % final)
Expand All @@ -683,6 +686,8 @@ def present_question_hc(
press = interpret_keypress()
current_guesses = buzzes.current_guesses(question_id, ss, ii - 1)
buzz_now = [x for x in current_guesses.values() if x.final]

#print(buzz_now)
# Removing this assertion now that we can have multiple systems playing
# assert len(buzz_now) < 2, "Cannot buzz on more than one thing"
if isinstance(press, int):
Expand Down Expand Up @@ -720,13 +725,14 @@ def present_question_hc(
)
)
answer(buzz_now[0].page.split("(")[0], buzz_now[0].system)
if correct == buzz_now[0].page:
if correct.casefold().strip() == buzz_now[0].page.casefold().strip():
#pdb.set_trace()
print("Computer guesses: %s (correct)" % buzz_now[0].page)
sleep(1)
sleep(5)
return Score(human=human_delta, computer=question_value)
else:
print("Computer guesses: %s (wrong)" % buzz_now[0].page)
sleep(1)
sleep(5)
computer_delta = -5
show_score(
score.human + human_delta,
Expand Down Expand Up @@ -812,7 +818,7 @@ def load_data(flags):
questions.debug()

buzzes = Buzzes(flags.model_directory, questions)

if flags.model_directory != "":
for ii in glob("%s/*" % flags.model_directory):
if ii.endswith(".buzz.csv"):
Expand Down Expand Up @@ -867,9 +873,10 @@ def question_loop(flags, questions, buzzes, present_question, check_tie):
computer=flags.computer_start,
)
question_num = 0
question_ids = sorted(questions._questions.keys(), key=lambda x: x % 10)
#print(question_ids)
#print(list(buzzes))
#question_ids = sorted(questions._questions.keys(), key=lambda x: x % 10)
question_ids = questions._questions.keys()
# print(question_ids)
# print(list(buzzes))
question_ids = [x for x in question_ids if x in buzzes]
#print(question_ids)

Expand Down

0 comments on commit afd40c8

Please sign in to comment.