diff --git a/aprendizations/knowledge.py b/aprendizations/knowledge.py index 538cd86..8b2d17b 100644 --- a/aprendizations/knowledge.py +++ b/aprendizations/knowledge.py @@ -70,7 +70,6 @@ class StudentKnowledge(object): # questions: list of generated questions to do in the topic # current_question: the current question to be presented # ------------------------------------------------------------------------ - # FIXME async mas nao tem awaits... do not allow restart same topic async def start_topic(self, topic): logger.debug('StudentKnowledge.start_topic()') if self.current_topic == topic: diff --git a/aprendizations/learnapp.py b/aprendizations/learnapp.py index 76f0e99..c3be9b7 100644 --- a/aprendizations/learnapp.py +++ b/aprendizations/learnapp.py @@ -8,7 +8,7 @@ from datetime import datetime # user installed libraries import bcrypt -from sqlalchemy import create_engine +from sqlalchemy import create_engine, func from sqlalchemy.orm import sessionmaker import networkx as nx @@ -381,32 +381,36 @@ class LearnApp(object): # ------------------------------------------------------------------------ def get_rankings(self, uid): - logger.info(f'User {uid} get rankings') + logger.info(f'User "{uid}" get rankings') with self.db_session() as s: students = s.query(Student.id, Student.name).all() + # topic progress student_topics = s.query(StudentTopic.student_id, StudentTopic.topic_id, StudentTopic.level, StudentTopic.date).all() total_topics = s.query(Topic).count() - rankings = {s[0]: 0.0 for s in students} + # answer performance + totalans = dict(s.query(Answer.student_id, func.count(Answer.ref)). + group_by(Answer.student_id). + all()) + rightans = dict(s.query(Answer.student_id, func.count(Answer.ref)). + filter(Answer.grade == 1.0). + group_by(Answer.student_id). + all()) + + # compute percentage of right answers + perf = {uid: rightans.get(uid, 0.0)/totalans[uid] for uid in totalans} + + # compute topic progress + prog = {s[0]: 0.0 for s in students} now = datetime.now() for uid, topic, level, date in student_topics: date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S.%f") - rankings[uid] += level**(now - date).days / total_topics + prog[uid] += level**(now - date).days / total_topics - rankings = [(uid, name, rankings[uid]) + rankings = [(uid, name, prog[uid], perf.get(uid, 0.0)) for uid, name in students if uid != '0'] - return sorted(rankings, key=lambda x: x[2], reverse=True) - def get_performance(self): - perf = {} - with self.db_session() as s: - students = s.query(Student.id).all() - for uid, in students: - ans = s.query(Answer).filter_by(student_id=uid) - total = ans.count() - right = ans.filter_by(grade=1.0).count() - perf[uid] = right / total if total > 0 else 0.0 - return perf + return sorted(rankings, key=lambda x: x[2], reverse=True) diff --git a/aprendizations/serve.py b/aprendizations/serve.py index b943703..4e78f93 100644 --- a/aprendizations/serve.py +++ b/aprendizations/serve.py @@ -88,21 +88,24 @@ class BaseHandler(tornado.web.RequestHandler): return uid +# ---------------------------------------------------------------------------- +# /rankings +# ---------------------------------------------------------------------------- class RankingsHandler(BaseHandler): @tornado.web.authenticated def get(self): uid = self.current_user rankings = self.learn.get_rankings(uid) - performance = self.learn.get_performance() + # performance = self.learn.get_performance() self.render('rankings.html', uid=uid, name=self.learn.get_student_name(uid), - rankings=rankings, - performance=performance) + rankings=rankings) + # performance=performance) # ---------------------------------------------------------------------------- -# /auth/login and /auth/logout +# /auth/login # ---------------------------------------------------------------------------- class LoginHandler(BaseHandler): def get(self): @@ -124,6 +127,8 @@ class LoginHandler(BaseHandler): # ---------------------------------------------------------------------------- +# /auth/logout +# ---------------------------------------------------------------------------- class LogoutHandler(BaseHandler): @tornado.web.authenticated def get(self): @@ -157,7 +162,7 @@ class ChangePasswordHandler(BaseHandler): # ---------------------------------------------------------------------------- -# Main page: / +# / (main page) # Shows a list of topics and proficiency (stars, locked). # ---------------------------------------------------------------------------- class RootHandler(BaseHandler): @@ -173,7 +178,9 @@ class RootHandler(BaseHandler): # ---------------------------------------------------------------------------- -# Start a given topic: /topic/... +# /topic/... +# Start a given topic +# FIXME should not change state... # ---------------------------------------------------------------------------- class TopicHandler(BaseHandler): SUPPORTED_METHODS = ['GET'] diff --git a/aprendizations/templates/rankings.html b/aprendizations/templates/rankings.html index ab938e5..8b07707 100644 --- a/aprendizations/templates/rankings.html +++ b/aprendizations/templates/rankings.html @@ -87,8 +87,8 @@ {{ ' '.join(r[1].split()[n] for n in (0,-1)) }}   - {{ '' if performance[r[0]] > 0.75 else '' }} - {{ '' if 0.0 < performance[r[0]] < 0.5 else '' }} + {{ '' if r[3] > 0.75 else '' }} + {{ '' if 0.0 < r[3] < 0.5 else '' }}
-- libgit2 0.21.2