class UserGeneratedAnswer(ORMBase): """Answers from students evaluating user-generated questions""" __tablename__ = 'userGeneratedAnswer' __table_args__ = dict( mysql_engine='InnoDB', mysql_charset='utf8', ) ugAnswerId = sqlalchemy.schema.Column( sqlalchemy.types.Integer(), primary_key=True, autoincrement=True, ) studentId = sqlalchemy.schema.Column( sqlalchemy.types.Integer(), sqlalchemy.schema.ForeignKey('student.studentId'), nullable=False, index=True, ) ugQuestionGuid = sqlalchemy.schema.Column( customtypes.GUID(), sqlalchemy.schema.ForeignKey('userGeneratedQuestions.ugQuestionGuid'), nullable=False, index=True, ) chosenAnswer = sqlalchemy.schema.Column( sqlalchemy.types.Integer(), nullable=True, ) questionRating = sqlalchemy.schema.Column( # -1 no sense 0 easy -- 50 -- 100 hard sqlalchemy.types.Integer(), nullable=True, ) comments = sqlalchemy.schema.Column( sqlalchemy.types.Text(), nullable=False, default='', ) studentGrade = sqlalchemy.schema.Column( sqlalchemy.types.Numeric(precision=4, scale=3, asdecimal=False), nullable=False, default=0, )
class Answer(ORMBase): """Answer table: List of all answers for questions""" __tablename__ = 'answer' __table_args__ = dict( mysql_engine='InnoDB', mysql_charset='utf8', ) answerId = sqlalchemy.schema.Column( sqlalchemy.types.Integer(), primary_key=True, autoincrement=True, ) lectureId = sqlalchemy.schema.Column( sqlalchemy.types.Integer(), sqlalchemy.schema.ForeignKey('lecture.lectureId'), ) lectureVersion = sqlalchemy.schema.Column( sqlalchemy.types.Integer(), sqlalchemy.schema.ForeignKey('lectureGlobalSetting.lectureVersion'), ) __table_args__ = ( ForeignKeyConstraint([lectureId, lectureVersion], [ LectureGlobalSetting.lectureId, LectureGlobalSetting.lectureVersion ]), __table_args__, ) studentId = sqlalchemy.schema.Column( sqlalchemy.types.Integer(), sqlalchemy.schema.ForeignKey('student.studentId'), nullable=False, ) questionId = sqlalchemy.schema.Column( sqlalchemy.types.Integer(), sqlalchemy.schema.ForeignKey('question.questionId'), nullable=False, index=True, ) chosenAnswer = sqlalchemy.schema.Column( sqlalchemy.types.Integer(), nullable=True, ) correct = sqlalchemy.schema.Column( sqlalchemy.types.Boolean(), nullable=True, ) timeStart = sqlalchemy.schema.Column( sqlalchemy.types.DateTime(), nullable=False, ) timeEnd = sqlalchemy.schema.Column( sqlalchemy.types.DateTime(), nullable=False, ) grade = sqlalchemy.schema.Column( sqlalchemy.types.Numeric(precision=4, scale=3, asdecimal=False), nullable=True, ) practice = sqlalchemy.schema.Column( sqlalchemy.types.Boolean(), nullable=False, default=False, ) coinsAwarded = sqlalchemy.schema.Column( sqlalchemy.types.Integer(), nullable=False, default=0, ) ugQuestionGuid = sqlalchemy.schema.Column( customtypes.GUID(), sqlalchemy.schema.ForeignKey('userGeneratedQuestions.ugQuestionGuid'), nullable=True, )
class UserGeneratedQuestion(ORMBase): """Table of questions submitted from question templates""" __tablename__ = 'userGeneratedQuestions' __table_args__ = dict( mysql_engine='InnoDB', mysql_charset='utf8', ) ugQuestionId = sqlalchemy.schema.Column( sqlalchemy.types.Integer(), primary_key=True, autoincrement=True, ) ugQuestionGuid = sqlalchemy.schema.Column( customtypes.GUID(), nullable=False, index=True, unique=True, default=uuid4, ) questionId = sqlalchemy.schema.Column( # i.e. the question template sqlalchemy.types.Integer(), sqlalchemy.schema.ForeignKey('question.questionId'), nullable=False, index=True, ) studentId = sqlalchemy.schema.Column( sqlalchemy.types.Integer(), sqlalchemy.schema.ForeignKey('student.studentId'), nullable=False, index=True, ) text = sqlalchemy.schema.Column( sqlalchemy.types.Text(), nullable=False, default='', ) choice_0_answer = sqlalchemy.schema.Column( sqlalchemy.types.String(1000), nullable=True, ) choice_0_correct = sqlalchemy.schema.Column( sqlalchemy.types.Boolean(), nullable=True, ) choice_1_answer = sqlalchemy.schema.Column( sqlalchemy.types.String(1000), nullable=True, ) choice_1_correct = sqlalchemy.schema.Column( sqlalchemy.types.Boolean(), nullable=True, ) choice_2_answer = sqlalchemy.schema.Column( sqlalchemy.types.String(1000), nullable=True, ) choice_2_correct = sqlalchemy.schema.Column( sqlalchemy.types.Boolean(), nullable=True, ) choice_3_answer = sqlalchemy.schema.Column( sqlalchemy.types.String(1000), nullable=True, ) choice_3_correct = sqlalchemy.schema.Column( sqlalchemy.types.Boolean(), nullable=True, ) choice_4_answer = sqlalchemy.schema.Column( sqlalchemy.types.String(1000), nullable=True, ) choice_4_correct = sqlalchemy.schema.Column( sqlalchemy.types.Boolean(), nullable=True, ) choice_5_answer = sqlalchemy.schema.Column( sqlalchemy.types.String(1000), nullable=True, ) choice_5_correct = sqlalchemy.schema.Column( sqlalchemy.types.Boolean(), nullable=True, ) choice_6_answer = sqlalchemy.schema.Column( sqlalchemy.types.String(1000), nullable=True, ) choice_6_correct = sqlalchemy.schema.Column( sqlalchemy.types.Boolean(), nullable=True, ) choice_7_answer = sqlalchemy.schema.Column( sqlalchemy.types.String(1000), nullable=True, ) choice_7_correct = sqlalchemy.schema.Column( sqlalchemy.types.Boolean(), nullable=True, ) choice_8_answer = sqlalchemy.schema.Column( sqlalchemy.types.String(1000), nullable=True, ) choice_8_correct = sqlalchemy.schema.Column( sqlalchemy.types.Boolean(), nullable=True, ) choice_9_answer = sqlalchemy.schema.Column( sqlalchemy.types.String(1000), nullable=True, ) choice_9_correct = sqlalchemy.schema.Column( sqlalchemy.types.Boolean(), nullable=True, ) explanation = sqlalchemy.schema.Column( sqlalchemy.types.Text(), nullable=False, default='', ) superseded = sqlalchemy.schema.Column( customtypes.GUID(), #TODO: MySQL is getting confused sqlalchemy.schema.ForeignKey('userGeneratedQuestions.ugQuestionGuid'), index=True, nullable=True, )
class ChatSession(ORMBase): """Previous / current chat sessions""" __tablename__ = 'chatSession' __table_args__ = dict( mysql_engine='InnoDB', mysql_charset='utf8', ) chatSessionGuid = sqlalchemy.schema.Column( # Sparse ID for chat room customtypes.GUID(), primary_key=True, default=uuid4, ) tutorId = sqlalchemy.schema.Column( # Student doing the teaching sqlalchemy.types.Integer(), sqlalchemy.schema.ForeignKey('tutor.tutorId'), nullable=False, ) tutorStudent = relationship( "Student", foreign_keys="ChatSession.tutorId", primaryjoin="ChatSession.tutorId==Student.studentId") pupilId = sqlalchemy.schema.Column( # Student being taught (or NULL, Tutor is waiting) sqlalchemy.types.Integer(), sqlalchemy.schema.ForeignKey('student.studentId'), nullable=True, ) pupilName = sqlalchemy.schema.Column( sqlalchemy.types.String(32), nullable=False, default=lambda: "pupil-%s" % random.randrange(1000, 9999), ) pupilStudent = relationship("Student", foreign_keys="ChatSession.pupilId") connectTime = sqlalchemy.schema.Column( # When (UTC) the tutor turned up sqlalchemy.types.DateTime(), nullable=False, default=datetime.utcnow, ) startTime = sqlalchemy.schema.Column( # When (UTC) the pupil decided to take up this offer sqlalchemy.types.DateTime(), nullable=True, ) endTime = sqlalchemy.schema.Column( # When (UTC) one of the party ended this session sqlalchemy.types.DateTime(), nullable=True, ) maxSeconds = sqlalchemy.schema.Column( # Maximum time (seconds) this chat session can last sqlalchemy.types.Integer(), nullable=True, ) coinsAwarded = sqlalchemy.schema.Column( # Coins awarded from pupilId to tutorId, mSMLY sqlalchemy.types.Integer(), nullable=False, default=0, )