diff --git a/aprendizations/learnapp.py b/aprendizations/learnapp.py index 5f012ce..6295640 100644 --- a/aprendizations/learnapp.py +++ b/aprendizations/learnapp.py @@ -10,8 +10,7 @@ from typing import Dict # third party libraries import bcrypt -from sqlalchemy import create_engine, func -from sqlalchemy.orm import sessionmaker +import sqlalchemy as sa import networkx as nx # this project @@ -29,7 +28,7 @@ class LearnException(Exception): pass -class DatabaseUnusableException(LearnException): +class DatabaseUnusableError(LearnException): pass @@ -48,7 +47,7 @@ class LearnApp(object): yield session session.commit() except Exception: - logger.error('DB rollback!!!') + logger.error('!!! Database rollback !!!') session.rollback() raise finally: @@ -268,12 +267,12 @@ class LearnApp(object): f'database') # ------------------------------------------------------------------------ - # setup and check database + # setup and check database contents # ------------------------------------------------------------------------ def db_setup(self, db): logger.info(f'Checking database "{db}":') - engine = create_engine(f'sqlite:///{db}', echo=False) - self.Session = sessionmaker(bind=engine) + engine = sa.create_engine(f'sqlite:///{db}', echo=False) + self.Session = sa.orm.sessionmaker(bind=engine) try: with self.db_session() as s: n = s.query(Student).count() @@ -281,7 +280,7 @@ class LearnApp(object): q = s.query(Answer).count() except Exception: logger.error(f'Database "{db}" not usable!') - raise DatabaseUnusableException() + raise DatabaseUnusableError() else: logger.info(f'{n:6} students') logger.info(f'{m:6} topics') @@ -311,7 +310,7 @@ class LearnApp(object): # iterate over topics and populate graph topics = config.get('topics', {}) - g = self.deps # the dependency graph + g = self.deps # dependency graph g.add_nodes_from(topics.keys()) for tref, attr in topics.items(): @@ -442,10 +441,10 @@ class LearnApp(object): total_topics = s.query(Topic).count() # answer performance - totalans = dict(s.query(Answer.student_id, func.count(Answer.ref)). + totalans = dict(s.query(Answer.student_id, sa.func.count(Answer.ref)). group_by(Answer.student_id). all()) - rightans = dict(s.query(Answer.student_id, func.count(Answer.ref)). + rightans = dict(s.query(Answer.student_id, sa.func.count(Answer.ref)). filter(Answer.grade == 1.0). group_by(Answer.student_id). all()) diff --git a/aprendizations/main.py b/aprendizations/main.py index 5a415c2..a2ee135 100644 --- a/aprendizations/main.py +++ b/aprendizations/main.py @@ -12,7 +12,7 @@ import sys import tornado # this project -from .learnapp import LearnApp, DatabaseUnusableException +from .learnapp import LearnApp, DatabaseUnusableError from .serve import WebApplication from .tools import load_yaml from . import APP_NAME, APP_VERSION @@ -149,7 +149,7 @@ def main(): try: learnapp = LearnApp(arg.conffile, prefix=arg.prefix, db=arg.db, check=arg.check) - except DatabaseUnusableException: + except DatabaseUnusableError: logging.critical('Failed to start application.') print('--------------------------------------------------------------') print('Could not find a usable database. Use one of the follwing ') -- libgit2 0.21.2