From 6ea2a68bcde4bc7f63c82cfeaa8b7dec0e69f6d7 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Wed, 24 Apr 2019 16:50:34 +0200 Subject: [PATCH] Timeout Diversion improvements --- hugvey/story.py | 16 +++++++++++++--- www/js/hugvey_console.js | 10 ++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/hugvey/story.py b/hugvey/story.py index 507adab..c6e06a0 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -586,6 +586,16 @@ class Diversion(object): # not applicable a direction has been chosen return + if not story.lastMsgFinishTime: + # not during play back + return + + now = story.timer.getElapsed() + if now - story.lastMsgFinishTime < float(self.params['minTimeAfterMessage']): + # not less than x sec after it + return + + interval = float(self.params['interval']) if not self.params['fromLastMessage']: # (1) last spoken at all @@ -607,19 +617,19 @@ class Diversion(object): if story.stats['diversions']['timeout_last'] + 1 != self.params['timesOccured']: return - if story.lastMsgFinishTime is None or story.currentReply is not None: + if story.currentReply is not None: # still playing back # or somebody has spoken already (timeout only works on silences) return - if time.time() - story.lastMsgFinishTime < interval: + if now - story.lastMsgFinishTime < interval: return story.currentMessage.timeoutDiversionCount += 1 story.stats['diversions']['timeout_last'] += 1 # if we're still here, there's a match! - story.logger.info(f"Diverge: Timeout {self.id}") + story.logger.info(f"Diverge: Timeout {self.id} of {self.params['interval']}") story.stats['diversions']['timeout'] += 1 msg = story.get(self.params['msgId']) diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index ce8507f..99cf050 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -448,6 +448,7 @@ class Graph { else if(type == 'timeout') { div['params']['interval'] = 20; div['params']['timesOccured'] = 0; + div['params']['minTimeAfterMessage'] = 2.; div['params']['fromLastMessage'] = false; div['params']['returnAfterStrand'] = true; div['params']['msgId'] = ""; @@ -685,6 +686,15 @@ class Graph { } }) ), + crel('label', 'Minimum time after message', + crel('input', { + 'type': 'number', + 'value': div['params']['minTimeAfterMessage'], + 'on': { + 'change': (e) => div['params']['minTimeAfterMessage'] = parseFloat(e.target.value) + } + }) + ), crel('label', 'Return to point of departure afterwards', crel('input', returnAttrs) ),