Merge branch 'testing' of https://gitea.86thumbs.net/waldek/ccpq into testing
This commit is contained in:
commit
2b53ec62dc
112
poc_hugo.py
112
poc_hugo.py
|
@ -1,11 +1,8 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import pathlib
|
|
||||||
import time
|
|
||||||
import os
|
import os
|
||||||
import csv
|
import csv
|
||||||
import random
|
import random
|
||||||
from collections import Counter
|
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.markdown import Markdown
|
from rich.markdown import Markdown
|
||||||
|
|
||||||
|
@ -18,24 +15,11 @@ def _create_dictionary():
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
# Count the number of questions and generate a list of IDs
|
|
||||||
def _count_questions(dictionary):
|
|
||||||
questions_id = [0]
|
|
||||||
questions_counter = 0
|
|
||||||
for questions in dictionary:
|
|
||||||
questions_counter += 1
|
|
||||||
questions_id.append(questions_counter)
|
|
||||||
questions_id.pop()
|
|
||||||
return questions_id
|
|
||||||
|
|
||||||
|
|
||||||
def _get_question(dictionary, questions_id):
|
|
||||||
questions_numbers = questions_id
|
|
||||||
|
|
||||||
print(questions_numbers)
|
|
||||||
|
|
||||||
|
|
||||||
def _print_question(question_asked):
|
def _print_question(question_asked):
|
||||||
|
"""
|
||||||
|
:param question_asked:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
os.system("clear")
|
os.system("clear")
|
||||||
c = Console()
|
c = Console()
|
||||||
actual_question = "# {}".format(question_asked["QUESTION"])
|
actual_question = "# {}".format(question_asked["QUESTION"])
|
||||||
|
@ -51,15 +35,95 @@ def _print_question(question_asked):
|
||||||
answer = Markdown(answer)
|
answer = Markdown(answer)
|
||||||
c.print(answer)
|
c.print(answer)
|
||||||
|
|
||||||
def _test_question(question_asked)
|
|
||||||
|
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__":
|
if __name__ == "__main__":
|
||||||
path = "./data/list_book1.csv"
|
path = "./data/list_book1.csv"
|
||||||
|
counter = []
|
||||||
dictionary = _create_dictionary()
|
dictionary = _create_dictionary()
|
||||||
questions_id = _count_questions(dictionary)
|
|
||||||
random.shuffle(dictionary)
|
random.shuffle(dictionary)
|
||||||
for question in dictionary:
|
for question in dictionary:
|
||||||
_print_question(question)
|
_print_question(question)
|
||||||
result = _test_question(question)
|
result = _test_question(question)
|
||||||
|
counter.append(result)
|
||||||
#_get_question(dictionary, questions_id)
|
_print_success(result)
|
||||||
|
print_stats(counter)
|
||||||
|
|
Loading…
Reference in New Issue