Compare commits

...

5 Commits

Author SHA1 Message Date
Ezekiel e0c9da1dff removed cheat mode 2021-06-03 14:50:53 +02:00
Ezekiel 40181480b6 poc_hugo finished 2021-06-03 14:47:26 +02:00
Ezekiel 4e18ce6911 Continued exec 2021-05-28 16:01:01 +02:00
Ezekiel b2de0e105a first push 2021-05-28 11:59:44 +02:00
waldek 263cd92a1e adds placeholders for issue 5 2021-05-27 21:28:04 +02:00
3 changed files with 141 additions and 1 deletions

View File

@ -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,6 +27,7 @@ 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()
@ -37,6 +38,7 @@ 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(),
@ -52,6 +54,10 @@ 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 Normal file
View File

@ -0,0 +1,129 @@
#!/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)

View File

@ -72,6 +72,10 @@ 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)
@ -111,6 +115,7 @@ 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()