From e1ad9bc69057dd6428360b633f4627b4249b6ca6 Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Sun, 5 Mar 2017 22:06:31 +0000 Subject: [PATCH] - titulo da página configurado no ficheiro de configuração. - mostra o estado dos tópicos numa coluna do lado esquerdo. - adicionado type: information, para perguntas que são apenas informativas. --- BUGS.md | 8 +++++--- app.py | 13 +++++++++++-- knowledge.py | 8 ++++---- serve.py | 15 +++++++++++---- static/css/learn.css | 25 ++++++++++++++++++++++++- templates/learn.html | 32 ++++++++++++++++++++++++-------- templates/question-information.html | 5 +++++ templates/question.html | 3 +-- templates/topics.html | 21 +++++++++++++++++++++ 9 files changed, 106 insertions(+), 24 deletions(-) create mode 100644 templates/question-information.html create mode 100644 templates/topics.html diff --git a/BUGS.md b/BUGS.md index 31df91a..55fc9b3 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,6 +1,7 @@ BUGS: -- não entra à primeira +- guardar state cada vez que topico termina +- mostrar quantas perguntas faltam - logs mostram que está a gerar cada pergunta 2 vezes...?? - mostra tópicos do lado esquerdo, indicando quais estão feitos e quantas perguntas contêm. - se students.db não existe, rebenta. @@ -9,13 +10,14 @@ BUGS: TODO: +- usar codemirror - mostrar comments quando falha a resposta -- configuração e linha de comando. -- como gerar uma sequencia de perguntas? - generators not working: bcrypt (ver blog) SOLVED: +- não entra à primeira +- configuração e linha de comando. - o browser é redireccionado para /question em vez de fazer um post?? quando se pressiona enter numa caixa text edit. - load/save the knowledge state of the student - servir ficheiros de public temporariamente diff --git a/app.py b/app.py index 79630e6..21d80d6 100644 --- a/app.py +++ b/app.py @@ -102,6 +102,14 @@ class LearnApp(object): return self.online[uid].get('name', '') # ------------------------------------------------------------------------ + def get_student_state(self, uid): + return self.online[uid]['state'].get_knowledge_state() + + # ------------------------------------------------------------------------ + def get_title(self): + return self.depgraph.graph['title'] + + # ------------------------------------------------------------------------ def get_current_public_dir(self, uid): topic = self.online[uid]['state'].get_current_topic() p = self.depgraph.graph['path'] @@ -110,7 +118,7 @@ class LearnApp(object): # ------------------------------------------------------------------------ # check answer and if correct returns new question, otherise returns None def check_answer(self, uid, answer): - logger.debug(f'check_answer("{uid}", "{answer}")') + # logger.debug(f'check_answer("{uid}", "{answer}")') knowledge = self.online[uid]['state'] current_question = knowledge.check_answer(answer) @@ -159,7 +167,8 @@ class LearnApp(object): raise e prefix = config['path'] # FIXME default if does not exist? - g = nx.DiGraph(path=prefix) + title = config.get('title', '') + g = nx.DiGraph(path=prefix, title=title) # Build dependency graph deps = config.get('dependencies', {}) diff --git a/knowledge.py b/knowledge.py index 3493397..56025ca 100644 --- a/knowledge.py +++ b/knowledge.py @@ -28,8 +28,8 @@ class Knowledge(object): # ------------------------------------------------------------------------ def topic_generator(self): - topics = nx.topological_sort(self.depgraph) # FIXME for now... - for t in topics: + self.topic_sequence = nx.topological_sort(self.depgraph) # FIXME for now... + for t in self.topic_sequence: if self.state.get(t, 0.0) > 0.999: continue self.questions = self.generate_questions_for_topic(t) @@ -51,7 +51,7 @@ class Knowledge(object): # ------------------------------------------------------------------------ def get_knowledge_state(self): - return self.state + return [(t, self.state.get(t, 0.0)) for t in self.topic_sequence] # --- generates a new question given the current state ------------------- def new_question(self): @@ -76,7 +76,7 @@ class Knowledge(object): # --- checks answer ------------------------------------------------------ # returns current question with correction, time and comments updated def check_answer(self, answer): - logger.debug(f'check_answer("{answer}")') + logger.debug(f'check_answer {answer}') question = self.current_question if question is not None: question['finish_time'] = datetime.now() diff --git a/serve.py b/serve.py index 42a9da5..88b84ae 100755 --- a/serve.py +++ b/serve.py @@ -110,7 +110,8 @@ class LearnHandler(BaseHandler): uid = self.current_user self.render('learn.html', uid=uid, - name=self.learn.get_student_name(uid) + name=self.learn.get_student_name(uid), + title=self.learn.get_title(), ) # ---------------------------------------------------------------------------- @@ -129,6 +130,7 @@ class FileHandler(BaseHandler): # respond to AJAX to get a JSON question class QuestionHandler(BaseHandler): templates = { + 'information': 'question-information.html', 'checkbox': 'question-checkbox.html', 'radio': 'question-radio.html', 'text': 'question-text.html', @@ -146,16 +148,21 @@ class QuestionHandler(BaseHandler): # ref = self.get_body_arguments('question_ref') user = self.current_user answer = self.get_body_arguments('answer') - # logger.debug(f'Answer POST from "{user}"') next_question = self.learn.check_answer(user, answer) + state = self.learn.get_student_state(user) if next_question is not None: - html_out = self.render_string(self.templates[next_question['type']], + question_html = self.render_string(self.templates[next_question['type']], question=next_question, # dictionary with the question md=md, # function that renders markdown to html ) + topics_html = self.render_string('topics.html', state=state) + self.write({ - 'params': tornado.escape.to_unicode(html_out), + 'params': { + 'question': tornado.escape.to_unicode(question_html), + 'state': tornado.escape.to_unicode(topics_html), + }, 'method': 'new_question', }) else: diff --git a/static/css/learn.css b/static/css/learn.css index b54aac6..dd05cef 100644 --- a/static/css/learn.css +++ b/static/css/learn.css @@ -6,4 +6,27 @@ img { display: block; margin: auto; width: 80%; -} \ No newline at end of file +} + +/* progress bars have height of 4 pixels */ +.progress {height: 4px;} + +/* make markdown tables beautiful */ +table { + border-collapse: collapse; + margin-left: 50px; +} +thead, tbody, td, th { + padding: 5px; + border-bottom: 1px solid #ddd; +} + +textarea { + font-family: monospace !important; +} + +/* Hack to avoid name clash between pygments and mathjax */ +.MathJax .mo, +.MathJax .mi { + color: inherit; +} diff --git a/templates/learn.html b/templates/learn.html index e1ef4e5..4a2fac9 100644 --- a/templates/learn.html +++ b/templates/learn.html @@ -2,7 +2,11 @@ - Learn + + + + + iLearn @@ -31,7 +35,7 @@ -