diff --git a/app.py b/app.py index fb4c81f..8c2eb06 100644 --- a/app.py +++ b/app.py @@ -126,7 +126,6 @@ class LearnApp(object): s.commit() logger.debug('check_answer: saving done') - logger.debug('check_answer: will return knowledge.new_question') return knowledge.new_question() # ------------------------------------------------------------------------ diff --git a/knowledge.py b/knowledge.py index 2fd806d..1c6c18e 100644 --- a/knowledge.py +++ b/knowledge.py @@ -19,39 +19,56 @@ class Knowledge(object): def __init__(self, depgraph, state={}): self.depgraph = depgraph self.state = state # {node: level, node: level, ...} + + self.topic = self.topic_generator() + self.current_topic = next(self.topic) + + self.questions = self.generate_questions_for_topic(self.current_topic) self.current_question = None - self.seq = nx.topological_sort(self.depgraph) - self.topic = None + # ------------------------------------------------------------------------ + def topic_generator(self): + topics = nx.topological_sort(self.depgraph) # FIXME for now... + for t in topics: + self.questions = self.generate_questions_for_topic(t) + yield t + # ------------------------------------------------------------------------ + def generate_questions_for_topic(self, topic): + factory = self.depgraph.node[topic]['factory'] + return [q.generate() for q in factory] + # ------------------------------------------------------------------------ def get_current_question(self): return self.current_question + # ------------------------------------------------------------------------ def get_knowledge_state(self): return self.state - # --- generates a new question given the current state + # --- generates a new question given the current state ------------------- def new_question(self): logger.debug('new_question()') + if self.current_question is None or self.current_question.get('grade', 0.0) > 0.9999: - g = self.depgraph - # choose topic, ie, node of the graph - # print(g.nodes()) - self.topic = random.choice(g.nodes()) # FIXME - # print(topic) - # choose question from that topic - question = random.choice(g.node[self.topic]['factory']) - # print(question) - - self.current_question = question.generate() - # print(self.current_question) - - # self.current_question = g.node[topic]['factory'].generate(ref) + + while not self.questions: + self.state[self.current_topic] = 1.0 # finished topic! + try: + self.current_topic = next(self.topic) + except StopIteration: + self.topic = self.topic_generator() + self.current_topic = next(self.topic) + self.questions = self.generate_questions_for_topic(self.current_topic) + + print(self.current_topic) + print(self.current_question) + self.current_question = self.questions.pop(0) self.current_question['start_time'] = datetime.now() + return self.current_question - # --- checks answer and updates knowledge state + # --- checks answer ------------------------------------------------------ # returns current question with correction, time and comments updated def check_answer(self, answer): logger.debug(f'check_answer("{answer}")') -- libgit2 0.21.2