diff --git a/demo/demo.yaml b/demo/demo.yaml index 1f87bc8..1d04519 100644 --- a/demo/demo.yaml +++ b/demo/demo.yaml @@ -1,6 +1,6 @@ title: Example database: students.db -path: ./demo +# path: ./demo # values applie to each topic, if undefined there # default values are: file=question.yaml, shuffle=True, choose: all @@ -17,7 +17,6 @@ forgetting_factor: 0.99 # - B # - C topics: - # topic without dependencies math: name: Matemática diff --git a/demo/solar_system/questions.yaml b/demo/solar_system/questions.yaml index 2164fa2..ac57804 100644 --- a/demo/solar_system/questions.yaml +++ b/demo/solar_system/questions.yaml @@ -38,13 +38,13 @@ # correct: !regex '[Ss]aturno' # --------------------------------------------------------------------------- -- ref: first_3_planets - type: textarea - title: Sistema solar - text: Escreva o nome dos três planetas mais próximos do Sol. (Exemplo `A, B e C`) - correct: correct-first_3_planets.py - # correct: correct-timeout.py - # opcional - answer: Vulcano, Krypton, Plutão - lines: 3 - timeout: 50 +# - ref: first_3_planets +# type: textarea +# title: Sistema solar +# text: Escreva o nome dos três planetas mais próximos do Sol. (Exemplo `A, B e C`) +# correct: correct-first_3_planets.py +# # correct: correct-timeout.py +# # opcional +# answer: Vulcano, Krypton, Plutão +# lines: 3 +# timeout: 50 diff --git a/knowledge.py b/knowledge.py index e2cb796..8dbf560 100644 --- a/knowledge.py +++ b/knowledge.py @@ -70,7 +70,7 @@ class StudentKnowledge(object): # questions: list of generated questions to do in the topic # current_question: the current question to be presented # ------------------------------------------------------------------------ - def init_topic(self, topic): + async def init_topic(self, topic): logger.debug(f'StudentKnowledge.init_topic({topic})') # do not allow locked topics @@ -88,7 +88,7 @@ class StudentKnowledge(object): self.wrong_answers = 0 # select a random set of questions for this topic - size = min(self.MAX_QUESTIONS, len(questionlist)) # number of questions + size = len(questionlist) # number of questions FIXME get from topic config questionlist = random.sample(questionlist, k=size) logger.debug(f'Questions: {", ".join(questionlist)}') diff --git a/learnapp.py b/learnapp.py index 8e17b6e..8979ed4 100644 --- a/learnapp.py +++ b/learnapp.py @@ -22,8 +22,8 @@ from tools import load_yaml logger = logging.getLogger(__name__) # ============================================================================ -class LearnAppException(Exception): - pass +# class LearnAppException(Exception): +# pass # ============================================================================ @@ -61,11 +61,11 @@ class LearnApp(object): session.close() # ------------------------------------------------------------------------ - def __init__(self, config_files): + def __init__(self, config_files, prefix): self.db_setup() # setup database and check students self.online = dict() # online students - self.deps = nx.DiGraph() + self.deps = nx.DiGraph(prefix=prefix) for c in config_files: self.populate_graph(c) @@ -192,9 +192,9 @@ class LearnApp(object): # Start new topic # ------------------------------------------------------------------------ async def start_topic(self, uid, topic): - loop = asyncio.get_running_loop() + student = self.online[uid]['state'] try: - await loop.run_in_executor(None, self.online[uid]['state'].init_topic, topic) + await student.init_topic(topic) except KeyError as e: logger.warning(f'User "{uid}" tried to open nonexistent topic: "{topic}"') raise e @@ -277,9 +277,9 @@ class LearnApp(object): # ------------------------------------------------------------------------ def get_current_public_dir(self, uid): topic = self.online[uid]['state'].get_current_topic() - p = self.deps.graph['path'] - return path.join(p, topic, 'public') + p = self.deps.graph['prefix'] # FIXME not defined!!! + return path.join(p, topic, 'public') # ============================================================================ @@ -304,21 +304,12 @@ class LearnApp(object): g = self.deps # the graph config = load_yaml(conffile) # course configuration - # set attributes of the graph - prefix = path.expanduser(config.get('path', '.')) - # title = config.get('title', '') - # database = config.get('database', 'students.db') - # default attributes that apply to the topics default_file = config.get('file', 'questions.yaml') default_shuffle = config.get('shuffle', True) default_choose = config.get('choose', 9999) default_forgetting_factor = config.get('forgetting_factor', 1.0) - # create graph - # g = nx.DiGraph(path=prefix, title=title, database=database, config=config) - - # iterate over topics and populate graph topics = config.get('topics', {}) tcount = qcount = 0 # topic and question counters @@ -331,12 +322,12 @@ class LearnApp(object): g.add_node(tref) t = g.node[tref] # current topic node - topicpath = path.join(prefix, tref) + topicpath = path.join(g.graph['prefix'], tref) t['type'] = attr.get('type', 'topic') t['name'] = attr.get('name', tref) - t['path'] = topicpath - t['file'] = attr.get('file', default_file) + t['path'] = topicpath # prefix/topic + t['file'] = attr.get('file', default_file) # questions.yaml t['shuffle'] = attr.get('shuffle', default_shuffle) t['forgetting_factor'] = attr.get('forgetting_factor', default_forgetting_factor) g.add_edges_from((d,tref) for d in attr.get('deps', [])) diff --git a/questions.py b/questions.py index 038a8ff..2d37fe4 100644 --- a/questions.py +++ b/questions.py @@ -154,7 +154,7 @@ class QuestionCheckbox(Question): # set defaults if missing self.set_defaults({ 'text': '', - 'correct': [0.0] * n, # useful for questionaries + 'correct': [1.0] * n, # Using 0.0 breaks the (right, wrong) options 'shuffle': True, 'discount': True, 'choose': n, # number of options diff --git a/serve.py b/serve.py index dcd93ed..273beab 100755 --- a/serve.py +++ b/serve.py @@ -304,9 +304,11 @@ def main(): # --- Commandline argument parsing argparser = argparse.ArgumentParser(description='Server for online learning. Enrolled students and topics have to be previously configured. Please read the documentation included with this software before running the server.') argparser.add_argument('conffile', type=str, nargs='+', - help='Topics configuration file in YAML format.') # FIXME only one + help='Topics configuration file in YAML format.') + argparser.add_argument('--prefix', type=str, default='demo', + help='Path prefix under which the topic directories can be found, e.g. ~/topics') argparser.add_argument('--port', type=int, default=8443, - help='Port to be used by the HTTPS server') + help='Port to be used by the HTTPS server, e.g. 8443') argparser.add_argument('--debug', action='store_true', help='Enable debug messages') arg = argparser.parse_args() @@ -327,7 +329,7 @@ def main(): # --- start application logging.info('Starting App') try: - learnapp = LearnApp(arg.conffile) + learnapp = LearnApp(arg.conffile, prefix=arg.prefix) except Exception as e: logging.critical('Failed to start backend application') raise e -- libgit2 0.21.2