diff --git a/perguntations/__init__.py b/perguntations/__init__.py index effaa33..15d671f 100644 --- a/perguntations/__init__.py +++ b/perguntations/__init__.py @@ -32,7 +32,7 @@ proof of submission and for review. ''' APP_NAME = 'perguntations' -APP_VERSION = '2020.05.dev5' +APP_VERSION = '2020.05.dev6' APP_DESCRIPTION = __doc__ __author__ = 'Miguel Barão' diff --git a/perguntations/app.py b/perguntations/app.py index ca6c868..5a96168 100644 --- a/perguntations/app.py +++ b/perguntations/app.py @@ -86,6 +86,8 @@ class App(): def __init__(self, conf): self.online = dict() # {uid: {'student':{...}, 'test': {...}}, ...} self.allowed = set() # '0' is hardcoded to allowed elsewhere + self.unfocus = set() # set of students that have no browser focus + self.area = dict() # {uid: percent_area} logger.info('Loading test configuration "%s".', conf["testfile"]) try: @@ -268,12 +270,12 @@ class App(): def event_test(self, uid, cmd, value): '''handles browser events the occur during the test''' if cmd == 'focus': - logger.info('"%s": focus %s', uid, value) + if value: + self.focus_student(uid) + else: + self.unfocus_student(uid) elif cmd == 'size': - scr_y, scr_x, win_y, win_x = value - area = win_x * win_y / (scr_x * scr_y) * 100 - logger.info('"%s": area=%g%%, window=%dx%d, screen=%dx%d', - uid, area, win_x, win_y, scr_x, scr_y) + self.set_screen_area(uid, value) # ------------------------------------------------------------------------ # --- GETTERS @@ -374,6 +376,8 @@ class App(): 'start_time': self.online.get(uid, {}).get('test', {}) .get('start_time', ''), 'password_defined': pw != '', + 'unfocus': uid in self.unfocus, + 'area': self.area.get(uid, None), 'grades': self.get_student_grades_from_test( uid, self.testfactory['ref']) } for uid, name, pw in self.get_all_students()] @@ -406,12 +410,30 @@ class App(): def allow_all_students(self): '''allow all students to login''' logger.info('Allowing all students...') - self.allowed = set(s[0] for s in self.get_all_students()) + self.allowed.update(s[0] for s in self.get_all_students()) def deny_all_students(self): '''deny all students to login''' logger.info('Denying all students...') - self.allowed = set() + self.allowed.clear() + + def focus_student(self, uid): + '''set student in focus state''' + self.unfocus.discard(uid) + logger.info('"%s" focus', uid) + + def unfocus_student(self, uid): + '''set student in unfocus state''' + self.unfocus.add(uid) + logger.info('"%s" unfocus', uid) + + def set_screen_area(self, uid, sizes): + '''set current browser area as detected in resize event''' + scr_y, scr_x, win_y, win_x = sizes + area = win_x * win_y / (scr_x * scr_y) * 100 + self.area[uid] = area + logger.info('"%s": area=%g%%, window=%dx%d, screen=%dx%d', + uid, area, win_x, win_y, scr_x, scr_y) async def update_student_password(self, uid, password=''): '''change password on the database''' diff --git a/perguntations/static/js/admin.js b/perguntations/static/js/admin.js index 88aa961..5cd23a8 100644 --- a/perguntations/static/js/admin.js +++ b/perguntations/static/js/admin.js @@ -16,11 +16,9 @@ $(document).ready(function() { // button handlers (runs once) $("#allow_all").click(function() { $.postJSON("/admin", {"cmd": "allow_all"}); - // $(":checkbox").prop("checked", true).trigger('change'); }); $("#deny_all").click(function() { $.postJSON("/admin", {"cmd": "deny_all"}); - // $(":checkbox").prop("checked", false).trigger('change'); }); $("#reset_password").click(function () { $.postJSON("/admin", { @@ -120,7 +118,15 @@ $(document).ready(function() { var uid = d['uid']; var checked = d['allowed'] ? 'checked' : ''; var password_defined = d['password_defined'] ? ' ' : ''; - var hora_inicio = d['start_time'] ? ' ' + d['start_time'].slice(11,19) + '': ''; + var hora_inicio = d['start_time'] ? ' ' + d['start_time'].slice(11,16) + '': ''; + var unfocus = d['unfocus']? ' unfocus' : ''; + var area = ''; + if (d['start_time'] ) { + if (d['area'] > 75) + area = ' ' + Math.round(d['area']) + '%'; + else + area = ' ' + Math.round(d['area']) + '%'; + }; var g = d['grades']; t[i] = []; @@ -128,7 +134,7 @@ $(document).ready(function() { t[i][1] = ' '; t[i][2] = uid; t[i][3] = d['name']; - t[i][4] = password_defined + hora_inicio; + t[i][4] = password_defined + hora_inicio + area + unfocus; var gbar = ''; for (var j=0; j < g.length; j++) diff --git a/perguntations/templates/review.html b/perguntations/templates/review.html index 60629fc..6d21d04 100644 --- a/perguntations/templates/review.html +++ b/perguntations/templates/review.html @@ -74,9 +74,9 @@