From cb72fdb87030152b6abfb1b2fdb67f2d35b61a01 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Fri, 1 Nov 2019 18:53:42 +0100 Subject: [PATCH 1/2] Fixes --- sorteerhoed/central_management.py | 46 +++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/sorteerhoed/central_management.py b/sorteerhoed/central_management.py index 435515e..670a8f9 100644 --- a/sorteerhoed/central_management.py +++ b/sorteerhoed/central_management.py @@ -15,6 +15,7 @@ from sorteerhoed.Signal import Signal import io from PIL import Image import datetime +from shutil import copyfile class CentralManagement(): @@ -99,6 +100,7 @@ class CentralManagement(): time.sleep(.5) finally: + self.logger.warning("Stopping Central Managment") self.isRunning.clear() self.server.stop() @@ -183,7 +185,11 @@ class CentralManagement(): #{'event': {'HITGroupId': '301G7MYOAJ85NEW128ZDGF5DSBW53S', 'EventType': 'AssignmentAbandoned', 'EventTimestamp': '2019-10-23T20:23:06Z', 'HITId': '3JHB4BPSFKKFQ263K4EFULI3LC79QJ', 'AssignmentId': '3U088ZLJVL450PB6MJZUIIUCB6VW0Y', 'WorkerId': 'A1CK46PK9VEUH5', 'HITTypeId': '3EYXOXDEN7RX0YSMN4UMVN01AYKZJ0'}} sqsHit.accept_time = None sqsHit.open_page_at = None - self.reset() + if self.currentHit.id == sqsHit.id: + if not sqsHit.submit_page_at: + self.reset() + else: + sqsHit.submit_hit_at = datetime.datetime.utcnow() # fake submit if updateStatus: self.setLight(False) @@ -191,7 +197,11 @@ class CentralManagement(): self.logger.info(f'Set status progress to returned') sqsHit.accept_time = None sqsHit.open_page_at = None - self.reset() + if self.currentHit.id == sqsHit.id: + if not sqsHit.submit_page_at: + self.reset() + else: + sqsHit.submit_hit_at = datetime.datetime.utcnow() # fake submit if updateStatus: self.setLight(False) # {'event': {'HITGroupId': '301G7MYOAJ85NEW128ZDGF5DSBW53S', 'EventType': 'AssignmentReturned', 'EventTimestamp': '2019-10-23T20:16:47Z', 'HITId': '3IH9TRB0FBAKKZFP3JUD6D9YWQ1I1F', 'AssignmentId': '3BF51CHDTWLN3ZGHRKDUHFKPWIJ0H3', 'WorkerId': 'A1CK46PK9VEUH5', 'HITTypeId': '3EYXOXDEN7RX0YSMN4UMVN01AYKZJ0'}} @@ -308,26 +318,34 @@ class CentralManagement(): """ Run scanimage on scaner and returns a string with the filename """ + + cmd = [ + 'sudo', 'scanimage', '-d', 'epkowa', '--format', 'jpeg', + '--resolution=100', '-l','20','-t','30','-x',str(255), + '-y',str(185) + ] + self.logger.info(f"{cmd}") + filename = self.currentHit.getImagePath() + with self.scanLock: self.eventQueue.put(Signal('scan.start')) - cmd = [ - 'sudo', 'scanimage', '-d', 'epkowa', '--format', 'jpeg', - '--resolution=100', '-l','20','-t','30','-x',str(255), - '-y',str(185) - ] - self.logger.info(f"{cmd}") - filename = self.currentHit.getImagePath() proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # opens connection to scanner, but only starts scanning when output becomes ready: o, e = proc.communicate(80) if e: self.logger.critical(f"Scanner caused: {e.decode()}") #TODO: should clear self.isRunning.clear() ? - - f = io.BytesIO(o) - img = Image.open(f) - img = img.transpose(Image.ROTATE_90) - img.save(filename) + + try: + f = io.BytesIO(o) + img = Image.open(f) + img = img.transpose(Image.ROTATE_90) + img.save(filename) + except Exception as e: + self.logger.critical("Cannot create image from scan. Did scanner work?") + self.logger.exception(e) + # TODO: create + copyfile('www/basic.svg', filename) self.eventQueue.put(Signal('hit.scanned', {'hit_id':self.currentHit.id})) self.eventQueue.put(Signal('scan.finished')) From 9a1aa0312ad2300119363648b888dcdfcfc2c640 Mon Sep 17 00:00:00 2001 From: merijn Date: Fri, 1 Nov 2019 18:56:00 +0100 Subject: [PATCH 2/2] worker_specs --- www/worker_specs/script.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/www/worker_specs/script.js b/www/worker_specs/script.js index 4cd6701..ce775dd 100644 --- a/www/worker_specs/script.js +++ b/www/worker_specs/script.js @@ -27,6 +27,7 @@ spec_names.forEach(function(name){ let request_time = timeStamp(), + hit_started = false, elapsed_time, hit_finished = false @@ -36,15 +37,6 @@ let request_time = timeStamp(), let ws = new ReconnectingWebSocket('ws://localhost:8888/status/ws') -let test = `{"property": "os", "value": "213.127.20.197"}` - -// fakeWs(test) -// -// function fakeWs(json){ -// -// -// } - ws.addEventListener('open', () => { // ws.send('hi server') @@ -56,14 +48,21 @@ ws.addEventListener('message', (event) => { let data = JSON.parse(event.data) if(data.property === 'hit_opened') { - hit_finished = false - request_time = timeStamp() - divs[data.property].innerHTML = `${request_time.format('dd mmm HH:MM:ss')}` + if(data.value != null){ + hit_started = true + hit_finished = false + request_time = timeStamp() + divs[data.property].innerHTML = `${request_time.format('dd mmm HH:MM:ss')}` + }else{ + hit_started = false + } } else if(data.property === 'hit_submitted'){ hit_finished = true; } - else if(divs[data.property]) divs[data.property].innerHTML = `${data.value}` + else if(divs[data.property]){ + data.value === null ? divs[data.property].innerHTML = `—` : divs[data.property].innerHTML = `${data.value}` + } }) @@ -103,8 +102,11 @@ function makeAnimation(){ function update(step){ if(!hit_finished) elapsed_time = `${new Date((Date.now() - request_time)).format('MM"m "ss"s"')}` - - divs['elapsed_time'].innerHTML = elapsed_time + if(hit_started){ + divs['elapsed_time'].innerHTML = elapsed_time + }else{ + divs['elapsed_time'].innerHTML = `—` + } } @@ -112,3 +114,4 @@ makeAnimation() function timeStamp(){return window.performance && window.performance.now ? window.performance.now() : new Date().getTime()} +