Compare commits
No commits in common. "70b3ba7806868ddb18b2798ede8a629c747deebe" and "90befc0953ee9074d9a73b6d9937a478b6c25503" have entirely different histories.
70b3ba7806
...
90befc0953
|
@ -11,9 +11,7 @@ from rich.markdown import Markdown
|
||||||
LEVEL = "LEVEL"
|
LEVEL = "LEVEL"
|
||||||
QUESTION = "QUESTION"
|
QUESTION = "QUESTION"
|
||||||
ANSWER = "ANSWER"
|
ANSWER = "ANSWER"
|
||||||
EXPLICATION = "EXPLICATION"
|
# EXPLANATION = ""
|
||||||
POSSIBILITIES = "POSSIBILITIES"
|
|
||||||
UUID = "UUID"
|
|
||||||
|
|
||||||
|
|
||||||
class Question(object):
|
class Question(object):
|
||||||
|
@ -36,10 +34,6 @@ class Question(object):
|
||||||
self._answers = self._data[ANSWER].strip().split(" ")
|
self._answers = self._data[ANSWER].strip().split(" ")
|
||||||
self._answers = [x for x in self._answers if x]
|
self._answers = [x for x in self._answers if x]
|
||||||
self._create_list_of_possibilities()
|
self._create_list_of_possibilities()
|
||||||
try:
|
|
||||||
self._explication = self._data[EXPLICATION].strip()
|
|
||||||
except:
|
|
||||||
self._explication = "No explication available for this question"
|
|
||||||
|
|
||||||
def dump_json(self):
|
def dump_json(self):
|
||||||
"""
|
"""
|
||||||
|
@ -47,11 +41,10 @@ class Question(object):
|
||||||
TODO needs a key to include the date for issue 5
|
TODO needs a key to include the date for issue 5
|
||||||
"""
|
"""
|
||||||
data = {
|
data = {
|
||||||
UUID: self.get_uuid(),
|
"UUID": self.get_uuid(),
|
||||||
QUESTION: self.get_question(),
|
QUESTION: self.get_question(),
|
||||||
ANSWER: self.get_right_answers(),
|
ANSWER: self.get_right_answers(),
|
||||||
POSSIBILITIES: self.get_possibilities(),
|
"POSSIBILITIES": self.get_possibilities(),
|
||||||
EXPLICATION: self.get_explication()
|
|
||||||
}
|
}
|
||||||
return json.dumps(data)
|
return json.dumps(data)
|
||||||
|
|
||||||
|
@ -61,9 +54,9 @@ class Question(object):
|
||||||
def get_question(self):
|
def get_question(self):
|
||||||
return self._question
|
return self._question
|
||||||
|
|
||||||
def get_explication(self):
|
def get_explanation(self):
|
||||||
"""returns the explication as a string"""
|
"""PLACEHOLDER for issue 5"""
|
||||||
return self._explication
|
pass
|
||||||
|
|
||||||
def _create_list_of_possibilities(self):
|
def _create_list_of_possibilities(self):
|
||||||
"""creates and cleans a list of all the possible answers"""
|
"""creates and cleans a list of all the possible answers"""
|
||||||
|
@ -132,27 +125,6 @@ class Database(object):
|
||||||
|
|
||||||
|
|
||||||
class Game(object):
|
class Game(object):
|
||||||
def __init__(self, filepath):
|
|
||||||
self._filepath = pathlib.Path(filepath)
|
|
||||||
self._players = []
|
|
||||||
self.setup_players()
|
|
||||||
|
|
||||||
def setup_players(self):
|
|
||||||
with open(self._filepath, "r") as fp:
|
|
||||||
lines = fp.readlines()
|
|
||||||
for line in lines:
|
|
||||||
self.add_player(line.strip())
|
|
||||||
|
|
||||||
def get_random_player(self):
|
|
||||||
return random.choice(self._players)
|
|
||||||
|
|
||||||
def add_player(self, name):
|
|
||||||
player = Player(name)
|
|
||||||
self._players.append(player)
|
|
||||||
|
|
||||||
|
|
||||||
class Stats(object):
|
|
||||||
"""TODO placeholder for the stats class"""
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._stats = []
|
self._stats = []
|
||||||
|
|
||||||
|
@ -160,22 +132,20 @@ class Stats(object):
|
||||||
self._stats.append(stat)
|
self._stats.append(stat)
|
||||||
|
|
||||||
def get_stats(self):
|
def get_stats(self):
|
||||||
return self.get_right(), self.get_wrong(), len(self._stats)
|
right = self._stats.count(True)
|
||||||
|
wrong = self._stats.count(False)
|
||||||
|
total = len(self._stats)
|
||||||
|
return (right, wrong, total)
|
||||||
|
|
||||||
def get_wrong(self):
|
|
||||||
return self._stats.count(False)
|
|
||||||
|
|
||||||
def get_right(self):
|
class Stats(object):
|
||||||
return self._stats.count(True)
|
"""TODO placeholder for the stats class"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Player(object):
|
class Player(object):
|
||||||
def __init__(self, name):
|
"""TODO placeholder for the player class"""
|
||||||
self.name = name
|
pass
|
||||||
self.stats = Stats()
|
|
||||||
|
|
||||||
def get_stats(self):
|
|
||||||
return self.name, self.stats.get_right(), self.stats.get_wrong()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
10
players.list
10
players.list
|
@ -1,10 +0,0 @@
|
||||||
Abdellah
|
|
||||||
David
|
|
||||||
Sarah
|
|
||||||
Selçuk
|
|
||||||
Hawai
|
|
||||||
Hugo
|
|
||||||
Jonathan
|
|
||||||
Nicolas
|
|
||||||
Laurant
|
|
||||||
Wouter
|
|
|
@ -4,7 +4,6 @@ import pathlib
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import time
|
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.markdown import Markdown
|
from rich.markdown import Markdown
|
||||||
from ccpq.lib_ccpq import Question, Database, Game
|
from ccpq.lib_ccpq import Question, Database, Game
|
||||||
|
@ -61,14 +60,6 @@ class Tui(object):
|
||||||
self._console.print(md)
|
self._console.print(md)
|
||||||
return answers
|
return answers
|
||||||
|
|
||||||
def signal_player(self, player):
|
|
||||||
os.system("clear")
|
|
||||||
md = "# {}".format(player.name)
|
|
||||||
md = Markdown(md)
|
|
||||||
self._console.print(md)
|
|
||||||
time.sleep(2)
|
|
||||||
os.system("clear")
|
|
||||||
|
|
||||||
def show_response(self, question):
|
def show_response(self, question):
|
||||||
answers = question.get_right_answers()
|
answers = question.get_right_answers()
|
||||||
if len(answers) == 1:
|
if len(answers) == 1:
|
||||||
|
@ -82,9 +73,8 @@ class Tui(object):
|
||||||
self._console.print(md)
|
self._console.print(md)
|
||||||
|
|
||||||
def show_explanation(self, question):
|
def show_explanation(self, question):
|
||||||
md = "--- \n {} \n \n ---".format(question.get_explication())
|
"""PLACEHOLDER for issue 5"""
|
||||||
md = Markdown(md)
|
pass
|
||||||
self._console.print(md)
|
|
||||||
|
|
||||||
def show_success(self, success):
|
def show_success(self, success):
|
||||||
md = "# {}".format(random.choice(MSG[success]))
|
md = "# {}".format(random.choice(MSG[success]))
|
||||||
|
@ -92,7 +82,7 @@ class Tui(object):
|
||||||
self._console.print(md)
|
self._console.print(md)
|
||||||
|
|
||||||
def show_stats(self, stats):
|
def show_stats(self, stats):
|
||||||
md = "{}, you have {} out of {} right!\n".format(stats[0], stats[1], stats[1] + stats[2])
|
md = "### you have {} out of {} right!".format(stats[0], stats[2])
|
||||||
md = Markdown(md)
|
md = Markdown(md)
|
||||||
self._console.print(md)
|
self._console.print(md)
|
||||||
md = "### press **enter** to get a new question or **CTRL-C** to quit"
|
md = "### press **enter** to get a new question or **CTRL-C** to quit"
|
||||||
|
@ -106,10 +96,10 @@ class Tui(object):
|
||||||
|
|
||||||
|
|
||||||
class Application(object):
|
class Application(object):
|
||||||
def __init__(self, filepath_csv, filepath_players, interface, number):
|
def __init__(self, filepath, interface, number):
|
||||||
self._db = Database(filepath_csv)
|
self._db = Database(filepath)
|
||||||
self._number = number
|
self._number = number
|
||||||
self._session = Game(filepath_players)
|
self._session = Game()
|
||||||
self._interface = interface
|
self._interface = interface
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
@ -118,17 +108,15 @@ class Application(object):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self._number > 0:
|
while self._number > 0:
|
||||||
player = self._session.get_random_player()
|
|
||||||
self._interface.signal_player(player)
|
|
||||||
question = self._db.get_question()
|
question = self._db.get_question()
|
||||||
self._interface.ask_question(question)
|
self._interface.ask_question(question)
|
||||||
answer = self._interface.prompt_for_answer()
|
answer = self._interface.prompt_for_answer()
|
||||||
stat = question.verify(answer)
|
stat = question.verify(answer)
|
||||||
player.stats.update_stats(stat)
|
self._session.update_stats(stat)
|
||||||
self._interface.show_success(stat)
|
self._interface.show_success(stat)
|
||||||
self._interface.show_response(question)
|
self._interface.show_response(question)
|
||||||
self._interface.show_explanation(question)
|
self._interface.show_explanation(question) # will work once issue 5 is addressed
|
||||||
self._interface.show_stats(player.get_stats())
|
self._interface.show_stats(self._session.get_stats())
|
||||||
self._number -= 1
|
self._number -= 1
|
||||||
self.quit()
|
self.quit()
|
||||||
|
|
||||||
|
@ -139,16 +127,14 @@ class Application(object):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-f", "--file", required=True, help="file to use as database", action="store")
|
parser.add_argument("-f", "--file", required=True, help="file to use as database", action="store")
|
||||||
parser.add_argument("-p", "--players", required=True, help="list of players", action="store")
|
|
||||||
parser.add_argument("-n", "--number", default=10, help="number of questions to ask", type=int, action="store")
|
parser.add_argument("-n", "--number", default=10, help="number of questions to ask", type=int, action="store")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
filepath_csv = pathlib.Path(args.file)
|
filepath = pathlib.Path(args.file)
|
||||||
filepath_players = pathlib.Path(args.players)
|
if not filepath.exists():
|
||||||
if not filepath_csv.exists() or not filepath_players.exists():
|
|
||||||
print("no such file!")
|
print("no such file!")
|
||||||
exit(1)
|
exit(1)
|
||||||
interface = Tui()
|
interface = Tui()
|
||||||
app = Application(filepath_csv, filepath_players, interface, args.number)
|
app = Application(filepath, interface, args.number)
|
||||||
try:
|
try:
|
||||||
app.run()
|
app.run()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
Loading…
Reference in New Issue