diff --git a/BUGS.md b/BUGS.md index 0034d6a..72ffa78 100644 --- a/BUGS.md +++ b/BUGS.md @@ -5,10 +5,6 @@ "file: questions.yaml" (default questions.yaml) "shuffle: True/False" (default False) "choose: 6" (default tudo) -- SQLAlchemy error (rollback em accao no final de um topico): - Users/mjsb/Library/Python/3.7/lib/python/site-packages/sqlalchemy/sql/crud.py:700: SAWarning: Column 'studenttopic.student_id' is marked as a member of the primary key for table 'studenttopic', but has no Python-side or server-side default generator indicated, nor does it indicate 'autoincrement=True' or 'nullable=True', and no explicit value is passed. Primary key columns typically may not store NULL. Note that as of SQLAlchemy 1.1, 'autoincrement=True' must be indicated explicitly for composite (e.g. multicolumn) primary keys if AUTO_INCREMENT/SERIAL/IDENTITY behavior is expected for one of the columns in the primary key. CREATE TABLE statements are impacted by this change as well on most backends. - util.warn(msg) - - quando a pergunta devolve comments, este é apresentado, mas fica persistente nas tentativas seguintes. devia ser limpo apos a segunda submissao. - a opcao max_tries na especificacao das perguntas é cumbersome... usar antes tries? - tabelas nas perguntas radio/checkbox não ocupam todo o espaço como em question. diff --git a/demo/demo.yaml b/demo/demo.yaml index 9e8158e..54a9455 100644 --- a/demo/demo.yaml +++ b/demo/demo.yaml @@ -1,6 +1,11 @@ title: Example database: students.db +# default global values +file: questions.yaml +shuffle: True +choose: 6 + # path prefix applied to the topics path: ./demo @@ -16,6 +21,9 @@ topics: # topic without dependencies math: name: Matemática + file: questions.yaml + choose: 6 + shuffle: True # topic with one dependency solar_system: diff --git a/knowledge.py b/knowledge.py index 2377576..021f326 100644 --- a/knowledge.py +++ b/knowledge.py @@ -32,8 +32,8 @@ class StudentKnowledge(object): self.topic_sequence = self.recommend_topic_sequence() # ['a', 'b', ...] self.unlock_topics() # whose dependencies have been done self.current_topic = None - - self.MAX_QUESTIONS = 6 # FIXME get from yaml configuration file?? + print(deps.graph) + self.MAX_QUESTIONS = deps.graph['config'].get('choose', 10) # ------------------------------------------------------------------------ # Updates the proficiency levels of the topics, with forgetting factor diff --git a/learnapp.py b/learnapp.py index 84b8b6b..fc01a1a 100644 --- a/learnapp.py +++ b/learnapp.py @@ -29,11 +29,9 @@ class LearnAppException(Exception): # ============================================================================ # helper functions # ============================================================================ -async def check_password(try_pw, password): - try_pw = try_pw.encode('utf-8') +async def check_password(try_pw, pw): loop = asyncio.get_running_loop() - hashed_pw = await loop.run_in_executor(None, bcrypt.hashpw, try_pw, password) - return password == hashed_pw + return pw == await loop.run_in_executor(None, bcrypt.hashpw, try_pw.encode('utf-8'), pw) def bcrypt_hash_gen(pw): return bcrypt.hashpw(pw.encode('utf-8'), bcrypt.gensalt()) @@ -62,16 +60,9 @@ class LearnApp(object): def __init__(self, config_file): # state of online students self.online = {} - - config = load_yaml(config_file) - - # connect to database and checks for registered students - self.db_setup(config['database']) - - # dependency graph shared by all students + config = load_yaml(config_file[0]) + self.db_setup(config['database']) # setup and check students self.deps = build_dependency_graph(config) - - # add topics from dependency graph to the database, if missing self.db_add_missing_topics(self.deps.nodes()) # ------------------------------------------------------------------------ @@ -98,8 +89,7 @@ class LearnApp(object): with self.db_session() as s: tt = s.query(StudentTopic).filter_by(student_id=uid) - state = {t.topic_id: - { + state = {t.topic_id: { 'level': t.level, 'date': datetime.strptime(t.date, "%Y-%m-%d %H:%M:%S.%f") } for t in tt} @@ -108,8 +98,7 @@ class LearnApp(object): 'number': uid, 'name': name, 'state': StudentKnowledge(self.deps, state=state), - # 'learning': None, # current topic learning - } + } else: logger.info(f'User "{uid}" wrong password!') @@ -209,23 +198,6 @@ class LearnApp(object): logger.info(f'User "{uid}" started "{topic}"') # ------------------------------------------------------------------------ - # Start new topic - # ------------------------------------------------------------------------ - # def start_learning(self, uid, topic): - # try: - # ok = self.online[uid]['state'].init_learning(topic) - # except KeyError as e: - # logger.warning( - # f'User "{uid}" tried to open nonexistent topic: "{topic}"') - # raise e - # else: - # if ok: - # logger.info(f'User "{uid}" started "{topic}"') - # else: - # logger.warning(f'User "{uid}" denied locked "{topic}"') - # return ok - - # ------------------------------------------------------------------------ # Fill db table 'Topic' with topics from the graph if not already there. # ------------------------------------------------------------------------ def db_add_missing_topics(self, nn): @@ -330,7 +302,7 @@ def build_dependency_graph(config={}): prefix = config.get('path', '.') title = config.get('title', '') database = config.get('database', 'students.db') - g = nx.DiGraph(path=prefix, title=title, database=database) + g = nx.DiGraph(path=prefix, title=title, database=database, config=config) # iterate over topics and build graph topics = config.get('topics', {}) diff --git a/serve.py b/serve.py index 44f8a8a..43ca9ca 100755 --- a/serve.py +++ b/serve.py @@ -356,7 +356,7 @@ def main(): # --- start application logging.info('Starting App') try: - learnapp = LearnApp(arg.conffile[0]) + learnapp = LearnApp(arg.conffile) except Exception as e: logging.critical('Failed to start backend application') raise e -- libgit2 0.21.2