Compare commits
No commits in common. "e0c9da1dffd252427cc7bb68be07cad158a38f87" and "6567adbe03294ad9f317fe38cc6269ad6fd34c34" have entirely different histories.
e0c9da1dff
...
6567adbe03
|
@ -11,12 +11,12 @@ from rich.markdown import Markdown
|
|||
LEVEL = "LEVEL"
|
||||
QUESTION = "QUESTION"
|
||||
ANSWER = "ANSWER"
|
||||
# EXPLANATION = ""
|
||||
|
||||
|
||||
class Question(object):
|
||||
"""
|
||||
class to hold the question data and methods
|
||||
TODO: needs to json methods for the REST API
|
||||
"""
|
||||
|
||||
def __init__(self, data):
|
||||
|
@ -27,7 +27,6 @@ class Question(object):
|
|||
def _clean_data(self):
|
||||
"""
|
||||
TODO needs quite bit of actual cleanup to make the parsing more robust
|
||||
TODO needs a 'private' variable for issue 5
|
||||
"""
|
||||
self._level = self._data[LEVEL].strip()
|
||||
self._question = self._data[QUESTION].strip()
|
||||
|
@ -38,7 +37,6 @@ class Question(object):
|
|||
def dump_json(self):
|
||||
"""
|
||||
dumps all data to JSON for the REST API
|
||||
TODO needs a key to include the date for issue 5
|
||||
"""
|
||||
data = {
|
||||
"UUID": self.get_uuid(),
|
||||
|
@ -54,10 +52,6 @@ class Question(object):
|
|||
def get_question(self):
|
||||
return self._question
|
||||
|
||||
def get_explanation(self):
|
||||
"""PLACEHOLDER for issue 5"""
|
||||
pass
|
||||
|
||||
def _create_list_of_possibilities(self):
|
||||
"""creates and cleans a list of all the possible answers"""
|
||||
possibilities = []
|
||||
|
|
129
poc_hugo.py
129
poc_hugo.py
|
@ -1,129 +0,0 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import csv
|
||||
import random
|
||||
from rich.console import Console
|
||||
from rich.markdown import Markdown
|
||||
|
||||
|
||||
# Open the CSV file and create a dictionary with all the questions
|
||||
def _create_dictionary():
|
||||
with open(path) as file:
|
||||
reader = csv.DictReader(file)
|
||||
data = list(reader)
|
||||
return data
|
||||
|
||||
|
||||
def _print_question(question_asked):
|
||||
"""
|
||||
:param question_asked:
|
||||
:return:
|
||||
"""
|
||||
os.system("clear")
|
||||
c = Console()
|
||||
actual_question = "# {}".format(question_asked["QUESTION"])
|
||||
actual_question = Markdown(actual_question)
|
||||
c.print(actual_question)
|
||||
answers = []
|
||||
for i in question_asked.keys():
|
||||
if i.isnumeric():
|
||||
answers.append(question_asked[i])
|
||||
answer = ""
|
||||
for i in answers:
|
||||
answer += "1. {} \n".format(i)
|
||||
answer = Markdown(answer)
|
||||
c.print(answer)
|
||||
|
||||
|
||||
def _has_multiple_answer(question_asked):
|
||||
"""
|
||||
:param question_asked:
|
||||
:return Boolean:
|
||||
"""
|
||||
answers = str(question_asked["ANSWER"]).split()
|
||||
try:
|
||||
if answers[1]:
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
def _one_digit_answer(question_asked):
|
||||
"""
|
||||
:param question_asked:
|
||||
:return Boolean:
|
||||
"""
|
||||
result = input("What's your answer? ")
|
||||
if result == question_asked["ANSWER"]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def _multiple_digit_answer(question_asked):
|
||||
"""
|
||||
:param question_asked:
|
||||
:return Boolean:
|
||||
"""
|
||||
answers = input("What's your answer? ").split(" ")
|
||||
right_answers = str(question_asked["ANSWER"]).split(" ")
|
||||
if len(answers) == 0:
|
||||
return False
|
||||
for answer in answers:
|
||||
try:
|
||||
test = right_answers.index(answer)
|
||||
right_answers.pop(test)
|
||||
except:
|
||||
return False
|
||||
if len(right_answers) == 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def _test_question(question_asked):
|
||||
"""
|
||||
:param question_asked:
|
||||
:return Boolean:
|
||||
"""
|
||||
if _has_multiple_answer(question_asked):
|
||||
return _multiple_digit_answer(question_asked)
|
||||
else:
|
||||
return _one_digit_answer(question_asked)
|
||||
|
||||
|
||||
def _print_success(result):
|
||||
"""
|
||||
:param result:
|
||||
"""
|
||||
c = Console()
|
||||
if result:
|
||||
msg = "## Good job!"
|
||||
else:
|
||||
msg = "## that's not the right answer..."
|
||||
md = Markdown(msg)
|
||||
c.print(md)
|
||||
|
||||
|
||||
def print_stats(counter):
|
||||
"""
|
||||
:param counter:
|
||||
"""
|
||||
success = counter.count(True)
|
||||
fail = counter.count(False)
|
||||
print("{} out of {} correct!".format(success, success + fail))
|
||||
input("press ENTER for a new question or CTRL-C to quit")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
path = "./data/list_book1.csv"
|
||||
counter = []
|
||||
dictionary = _create_dictionary()
|
||||
random.shuffle(dictionary)
|
||||
for question in dictionary:
|
||||
_print_question(question)
|
||||
result = _test_question(question)
|
||||
counter.append(result)
|
||||
_print_success(result)
|
||||
print_stats(counter)
|
|
@ -72,10 +72,6 @@ class Tui(object):
|
|||
md = Markdown(md)
|
||||
self._console.print(md)
|
||||
|
||||
def show_explanation(self, question):
|
||||
"""PLACEHOLDER for issue 5"""
|
||||
pass
|
||||
|
||||
def show_success(self, success):
|
||||
md = "# {}".format(random.choice(MSG[success]))
|
||||
md = Markdown(md)
|
||||
|
@ -115,7 +111,6 @@ class Application(object):
|
|||
self._session.update_stats(stat)
|
||||
self._interface.show_success(stat)
|
||||
self._interface.show_response(question)
|
||||
self._interface.show_explanation(question) # will work once issue 5 is addressed
|
||||
self._interface.show_stats(self._session.get_stats())
|
||||
self._number -= 1
|
||||
self.quit()
|
||||
|
|
Loading…
Reference in New Issue