diff options
author | CRD716 <crd716@gmail.com> | 2023-04-28 11:13:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-28 19:13:33 +0300 |
commit | 5fba3c016bfd1d73a070e7c93dac14162ce118d0 (patch) | |
tree | cddf05d07766950f565f3b4bb644ba9466d240cc /examples/jeopardy/graph.py | |
parent | 1481a9cf25ea2e4abef6b13a57660a35f3e66af1 (diff) |
examples : add Jeopardy example (#1168)
* Basic Setup
* Prevent Results.txt from coming up
* Prefixes, Line separators, etc
* editorcheck
* introduction to give more consistent results
* Basic graph thing
* Grading, ready for testing!
* Y'all ready to get funky?
* fix column removal stuff
* missed a few
Diffstat (limited to 'examples/jeopardy/graph.py')
-rw-r--r-- | examples/jeopardy/graph.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/examples/jeopardy/graph.py b/examples/jeopardy/graph.py new file mode 100644 index 0000000..d00b286 --- /dev/null +++ b/examples/jeopardy/graph.py @@ -0,0 +1,56 @@ +import matplotlib.pyplot as plt +import sys, os +import csv + +labels = [] +numbers = [] +numEntries = 1 + +rows = [] + +def bar_chart(numbers, labels, pos): + plt.bar(pos, numbers, color='blue') + plt.xticks(ticks=pos, labels=labels) + plt.title("Jeopardy Results by Model") + plt.xlabel("Model") + plt.ylabel("Questions Correct") + plt.show() + +def calculatecorrect(): + directory = os.fsencode("./examples/jeopardy/results/") + csv_reader = csv.reader(open("./examples/jeopardy/qasheet.csv", 'rt'), delimiter=',') + for row in csv_reader: + global rows + rows.append(row) + for listing in os.listdir(directory): + filename = os.fsdecode(listing) + if filename.endswith(".txt"): + file = open("./examples/jeopardy/results/" + filename, "rt") + global labels + global numEntries + global numbers + labels.append(filename[:-4]) + numEntries += 1 + i = 1 + totalcorrect = 0 + for line in file.readlines(): + if line.strip() != "------": + print(line) + else: + print("Correct answer: " + rows[i][2] + "\n") + i+=1 + print("Did the AI get the question right? (y/n)") + if input() == "y": + totalcorrect += 1 + numbers.append(totalcorrect) + + + +if __name__ == '__main__': + calculatecorrect() + pos = list(range(numEntries)) + labels.append("Human") + numbers.append(48.11) + bar_chart(numbers, labels, pos) + print(labels) + print(numbers) |