class Progress(Utilities, db.Model): RELATIONSHIPS_TO_DICT = True __tablename__ = 'progress' progress_id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'), nullable=False) lesson_id = db.Column(db.Integer, db.ForeignKey('lessons.lesson_id'), nullable=False) type = db.Column(db.String(50), nullable=True) isCompleted = db.Column(db.Boolean, nullable=True) def __init__(self, **args): self.user_id = args.get('user_id') self.lesson_id = args.get('lesson_id') self.type = args.get('type') self.isCompleted = args.get('isCompleted') @property def pk(self): return self.progress_id def create(self): db.session.add(self) db.session.commit() return self def update(self): db.session.add(self) db.session.commit() return self def delete(self): db.session.delete(self) db.session.commit() @staticmethod def getProgress(): return Progress.query.all() @staticmethod def getProgressById(pid): return Progress.query.filter_by(progress_id=pid).first() @staticmethod def getProgressByUserId(uid): return Progress.query.filter_by(user_id=uid).all() @staticmethod def getProgressByLessonIdAndUserId(lid, uid): return Progress.query.filter_by(lesson_id=lid, user_id=uid).all() @staticmethod def checkIfRepeated(lid, uid, tpe): return len( Progress.query.filter_by(lesson_id=lid, user_id=uid, type=tpe).all()) == 0
class Scores(Utilities, db.Model): RELATIONSHIPS_TO_DICT = True __tablename__ = 'scores' score_id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'), nullable=False) lesson_id = db.Column(db.Integer, db.ForeignKey('lessons.lesson_id'), nullable=False) numberOfQuestions = db.Column(db.Integer, nullable=True) numberOfCorrectAnswers = db.Column(db.Integer, nullable=True) numberOfIncorrectAnswers = db.Column(db.Integer, nullable=True) totalPoints = db.Column(db.Integer, nullable=True) correctPoints = db.Column(db.Integer, nullable=True) userInput = db.relationship("UserInputs", backref="scores", lazy=True) def __init__(self, **args): self.user_id = args.get('user_id') self.lesson_id = args.get('lesson_id') self.numberOfQuestions = args.get('numberOfQuestions') self.numberOfCorrectAnswers = args.get('numberOfCorrectAnswers') self.numberOfIncorrectAnswers = args.get('numberOfIncorrectAnswers') self.totalPoints = args.get('totalPoints') self.correctPoints = args.get('correctPoints') @property def pk(self): return self.score_id def create(self): db.session.add(self) db.session.commit() return self def update(self): db.session.add(self) db.session.commit() return self def delete(self): db.session.delete(self) db.session.commit() @staticmethod def getScores(): return Scores.query.all() @staticmethod def getScoresById(sid): return Scores.query.filter_by(score_id=sid).first() @staticmethod def getScoresByUserId(uid): return Scores.query.filter_by(user_id=uid).all() @staticmethod def getScoresByLessonIdAndUserId(lid, uid): return Scores.query.filter_by(lesson_id=lid, user_id=uid).all()
class Answers(Utilities, db.Model): RELATIONSHIPS_TO_DICT = True __tablename__ = 'answers' answer_id = db.Column(db.Integer, primary_key=True) question_id = db.Column(db.Integer, db.ForeignKey('questions.question_id'), nullable=False) answer = db.Column(db.String(500), nullable=False) def __init__(self, **args): self.question_id = args.get('question_id') self.answer = args.get('answer') @property def pk(self): return self.answer_id def create(self): db.session.add(self) db.session.commit() return self def update(self): db.session.add(self) db.session.commit() return self def delete(self): db.session.delete(self) db.session.commit() @staticmethod def getAnswers(): return Answers.query.all() @staticmethod def getAnswerById(aid): return Answers.query.filter_by(answer_id=aid).first() @staticmethod def getAnswerByQuestionId(qid): return Answers.query.filter_by(question_id=qid).all()
class Lessons(Utilities, db.Model): RELATIONSHIPS_TO_DICT = True __tablename__ = 'lessons' lesson_id = db.Column(db.Integer, primary_key=True) lname = db.Column(db.String(100), nullable=False) description = db.Column(db.String(500), nullable=False) level_id = db.Column(db.Integer, db.ForeignKey('levels.level_id'), nullable=False) video_url = db.Column(db.String(500), nullable=False) max_xp = db.Column(db.Integer, nullable=True) lesson_img = db.Column(db.String(500), nullable=True) quiz_url = db.Column(db.String(150), nullable=True) total_activities = db.Column(db.Integer, nullable=False) models = db.relationship("Models", backref=db.backref('lessons', lazy='subquery'), lazy=True) # questions = db.relationship("dao.questions.Questions", backref=db.backref('lessons', lazy='subquery'), lazy=True) def __init__(self, **args): self.lname = args.get('lname') self.description = args.get('description') self.level_id = args.get('level_id') self.video_url = args.get('video_url') self.max_xp = args.get('max_xp') self.lesson_img = args.get('lesson_img') self.quiz_url = args.get('quiz_url') self.total_activities = args.get('total_activities') @property def pk(self): return self.lesson_id @staticmethod def getAllLessons(): return Lessons.query.order_by(Lessons.lesson_id).all() @staticmethod def getLessonById(lid): return Lessons.query.filter_by(lesson_id=lid).first() @staticmethod def getLessonsByLevelId(levid): return Lessons.query.filter_by(level_id=levid).all()
class Models(Utilities, db.Model): RELATIONSHIPS_TO_DICT = True __tablename__ = 'models' model_id = db.Column(db.Integer, primary_key=True) lesson_id = db.Column(db.Integer, db.ForeignKey('lessons.lesson_id'), nullable=False) model_url = db.Column(db.String(500), nullable=True) question = db.Column(db.String(500), nullable=False) answer = db.Column(db.String(100), nullable=False) xp = db.Column(db.Integer, nullable=True) model_name = db.Column(db.String(50), nullable=True) boxes = db.Column(db.Integer, nullable=True) scores = db.Column(db.Integer, nullable=True) classes = db.Column(db.Integer, nullable=True) def __init__(self, **args): self.lesson_id = args.get('lesson_id') self.model_url = args.get('model_url') self.question = args.get('question') self.answer = args.get('answer') self.xp = args.get('xp') self.model_name = args.get('model_name') self.boxes = args.get('boxes') self.scores = args.get('scores') self.classes = args.get('classes') @property def pk(self): return self.model_id @staticmethod def getModels(): return Models.query.all() @staticmethod def getModelById(mid): return Models.query.filter_by(model_id=mid).first() @staticmethod def getModelsByLessonId(lid): return Models.query.filter_by(lesson_id=lid).all()
class UserInputs(Utilities, db.Model): RELATIONSHIPS_TO_DICT = True __tablename__ = 'userInput' userInput_id = db.Column(db.Integer, primary_key=True) score_id = db.Column(db.Integer, db.ForeignKey('scores.score_id'), nullable=False) input = db.Column(db.Integer, nullable=False) def __init__(self, **args): self.score_id = args.get('score_id') self.input = args.get('input') @property def pk(self): return self.userInput_id def create(self): db.session.add(self) db.session.commit() return self def update(self): db.session.add(self) db.session.commit() return self def delete(self): db.session.delete(self) db.session.commit() @staticmethod def getUserInputs(): return UserInputs.query.all() @staticmethod def getUserInputById(ui_id): return UserInputs.query.filter_by(userInput_id=ui_id).first() @staticmethod def getUserInputsByScoreId(sid): return UserInputs.query.filter_by(score_id=sid).all()
class Levels(Utilities, db.Model): RELATIONSHIPS_TO_DICT = True __tablename__ = 'levels' level_id = db.Column(db.Integer, primary_key=True) level_name = db.Column(db.String(100), nullable=False) def __init__(self, **args): self.level_name = args.get('level_name') @property def pk(self): return self.level_id @staticmethod def getLevels(): return Levels.query.all() @staticmethod def getLevelById(lid): return Levels.query.filter_by(level_id=lid).first()
class Users(Utilities, db.Model): RELATIONSHIPS_TO_DICT = True __tablename__ = 'users' user_id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) email = db.Column(db.String(100), nullable=False) password = db.Column(db.String(100), nullable=False) picture_url = db.Column(db.String(200), nullable=False) total_points = db.Column(db.Integer, nullable=True) progress = db.relationship("Progress", backref=db.backref('users', lazy='subquery'), lazy=True) def __init__(self, **args): self.name = args.get('name') self.email = args.get('email') self.password = args.get('password') self.picture_url = args.get('picture_url') self.total_points = args.get('total_points') @property def pk(self): return self.user_id def create(self): self.password = bcrypt.hashpw(self.password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8') db.session.add(self) db.session.commit() return self def update(self): db.session.add(self) db.session.commit() return self def delete(self): db.session.delete(self) db.session.commit() @staticmethod def getUsers(): return Users.query.order_by(Users.user_id).all() @staticmethod def getUserById(uid): return Users.query.filter_by(user_id=uid).first() @staticmethod def getUserByEmail(uemail): return Users.query.filter_by(email=uemail).first() @staticmethod def verifyEmail(uemail): return len(Users.query.filter_by(email=uemail).all()) != 0
class Questions(Utilities, db.Model): RELATIONSHIPS_TO_DICT = True __tablename__ = 'questions' question_id = db.Column(db.Integer, primary_key=True) lesson_id = db.Column(db.Integer, db.ForeignKey('lessons.lesson_id'), nullable=False) question = db.Column(db.String(500), nullable=True) questionType = db.Column(db.String(500), nullable=True) answerSelectionType = db.Column(db.String(50), nullable=True) correctAnswer = db.Column(db.String(10), nullable=True) messageForCorrectAnswer = db.Column(db.String(400), nullable=True) messageForIncorrectAnswer = db.Column(db.String(500), nullable=True) explanation = db.Column(db.String(400), nullable=True) point = db.Column(db.String(10), nullable=True) questionIndex = db.Column(db.Integer, nullable=True) questionPic = db.Column(db.String(500), nullable=True) answers = db.relationship("dao.answers.Answers", backref=db.backref('questions', lazy='subquery'), lazy=True) def __init__(self, **args): self.lesson_id = args.get('lesson_id') self.question = args.get('question') self.questionType = args.get('questionType') self.answerSelectionType = args.get('answerSelectionType') self.correctAnswer = args.get('correctAnswer') self.messageForCorrectAnswer = args.get('messageForCorrectAnswer') self.messageForIncorrectAnswer = args.get('messageForIncorrectAnswer') self.explanation = args.get('explanation') self.point = args.get('point') self.questionIndex = args.get('questionIndex') self.questionPic = args.get('questionPic') @property def pk(self): return self.question_id def create(self): db.session.add(self) db.session.commit() return self def update(self): db.session.add(self) db.session.commit() return self def delete(self): db.session.delete(self) db.session.commit() @staticmethod def getQuestions(): return Questions.query.all() @staticmethod def getQuestionsById(qid): return Questions.query.filter_by(question_id=qid).first() @staticmethod def getQuestionsByLessonId(lid): return Questions.query.filter_by(lesson_id=lid).all()