From 2ed48b705dc5fdb067b6d46d94f078999c3e4f26 Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Wed, 13 Jul 2016 20:44:12 +0100 Subject: [PATCH] - added two new fields to the test table in the database: state, comment - the test state indicates if the test was corrected normally, the student quit, or the test is null because of cheating. - tests are always stored in the database, even if the student quits. - added support to review quit tests --- app.py | 30 ++++++++++++++++++++++++------ models.py | 4 +++- templates/grade.html | 12 ++++++++++-- templates/review.html | 13 +++++++++++-- test.py | 6 +++++- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/app.py b/app.py index da99666..733c975 100644 --- a/app.py +++ b/app.py @@ -144,7 +144,9 @@ class App(object): starttime=str(t['start_time']), finishtime=str(t['finish_time']), filename=fpath, - student_id=t['student']['number'])) + student_id=t['student']['number'], + state=t['state'], + comment='')) s.add_all([Question( ref=q['ref'], grade=q['grade'], @@ -159,13 +161,29 @@ class App(object): # ----------------------------------------------------------------------- def giveup_test(self, uid): - logger.info('Student {0}: gave up.'.format(uid)) t = self.online[uid]['test'] grade = t.giveup() - if t['save_answers']: - fname = ' -- '.join((t['student']['number'], t['ref'], str(t['finish_time']))) + '.json' - fpath = path.abspath(path.join(t['answers_dir'], fname)) - t.save_json(fpath) + + # save JSON with the test + fname = ' -- '.join((t['student']['number'], t['ref'], str(t['finish_time']))) + '.json' + fpath = path.abspath(path.join(t['answers_dir'], fname)) + t.save_json(fpath) + + # insert test into database + with self.db_session() as s: + s.add(Test( + ref=t['ref'], + title=t['title'], + grade=t['grade'], + starttime=str(t['start_time']), + finishtime=str(t['finish_time']), + filename=fpath, + student_id=t['student']['number'], + state=t['state'], + comment='')) + s.commit() + + logger.info('Student {0}: gave up.'.format(uid)) return t # ----------------------------------------------------------------------- diff --git a/models.py b/models.py index a8cb15d..6449dea 100644 --- a/models.py +++ b/models.py @@ -29,8 +29,10 @@ class Test(Base): __tablename__ = 'tests' id = Column(Integer, primary_key=True) # auto_increment ref = Column(String) - title = Column(String) + title = Column(String) # FIXME depends on ref and should come from another table... grade = Column(Float) + state = Column(String) # ONGOING, FINISHED, QUIT, NULL + comment = Column(String) starttime = Column(String) finishtime = Column(String) filename = Column(String) diff --git a/templates/grade.html b/templates/grade.html index 92e74bd..c2c442f 100644 --- a/templates/grade.html +++ b/templates/grade.html @@ -50,8 +50,16 @@

Resultado

-

Teve ${t['grade']} valores na escala de 0 a 20.

-

A prova está terminada, pode fechar o browser e desligar o computador.

+ + % if t['state'] == 'FINISHED': +

Teve ${t['grade']} valores na escala de 0 a 20.

+ + % elif t['state'] == 'QUIT': +

Foi registada a sua desistência da prova.

+ + % endif + +

Pode fechar o browser e desligar o computador.

diff --git a/templates/review.html b/templates/review.html index 9a8eced..bb1d0c1 100644 --- a/templates/review.html +++ b/templates/review.html @@ -62,7 +62,13 @@ % else: ${t['grade']} valores % endif + % if t['state'] == 'QUIT': + (DESISTÊNCIA) + % endif + % if t['comment'] != '': +
Comentário:
${t['comment']}
+ % endif @@ -116,7 +122,6 @@ ${md_to_html_review(q['text'], q)}

- % else:
@@ -224,6 +229,8 @@ % endif
+ + % if t['state'] == 'FINISHED': + % endif +
- % endif + % endif # question type
% endfor diff --git a/test.py b/test.py index 9073b0e..6157e1a 100644 --- a/test.py +++ b/test.py @@ -202,6 +202,8 @@ class Test(dict): super().__init__(d) self['start_time'] = datetime.now() self['finish_time'] = None + self['state'] = 'ONGOING' + self['comment'] = '' logger.info('Student {}: starting test.'.format(self['student']['number'])) # ----------------------------------------------------------------------- @@ -224,6 +226,7 @@ class Test(dict): # Corrects all the answers and computes the final grade def correct(self): self['finish_time'] = datetime.now() + self['state'] = 'FINISHED' grade = 0.0 total_points = 0.0 @@ -237,7 +240,8 @@ class Test(dict): # ----------------------------------------------------------------------- def giveup(self): - self['comments'] = 'DESISTIU' + self['finish_time'] = datetime.now() + self['state'] = 'QUIT' self['grade'] = 0.0 logger.info('Student {}: gave up.'.format(self['student']['number'])) return self['grade'] -- libgit2 0.21.2