Timeout Diversion improvements

This commit is contained in:
Ruben van de Ven 2019-04-24 16:50:34 +02:00
parent eeed9e3161
commit 6ea2a68bcd
2 changed files with 23 additions and 3 deletions

View file

@ -586,6 +586,16 @@ class Diversion(object):
# not applicable a direction has been chosen # not applicable a direction has been chosen
return 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']) interval = float(self.params['interval'])
if not self.params['fromLastMessage']: if not self.params['fromLastMessage']:
# (1) last spoken at all # (1) last spoken at all
@ -607,19 +617,19 @@ class Diversion(object):
if story.stats['diversions']['timeout_last'] + 1 != self.params['timesOccured']: if story.stats['diversions']['timeout_last'] + 1 != self.params['timesOccured']:
return return
if story.lastMsgFinishTime is None or story.currentReply is not None: if story.currentReply is not None:
# still playing back # still playing back
# or somebody has spoken already (timeout only works on silences) # or somebody has spoken already (timeout only works on silences)
return return
if time.time() - story.lastMsgFinishTime < interval: if now - story.lastMsgFinishTime < interval:
return return
story.currentMessage.timeoutDiversionCount += 1 story.currentMessage.timeoutDiversionCount += 1
story.stats['diversions']['timeout_last'] += 1 story.stats['diversions']['timeout_last'] += 1
# if we're still here, there's a match! # 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 story.stats['diversions']['timeout'] += 1
msg = story.get(self.params['msgId']) msg = story.get(self.params['msgId'])

View file

@ -448,6 +448,7 @@ class Graph {
else if(type == 'timeout') { else if(type == 'timeout') {
div['params']['interval'] = 20; div['params']['interval'] = 20;
div['params']['timesOccured'] = 0; div['params']['timesOccured'] = 0;
div['params']['minTimeAfterMessage'] = 2.;
div['params']['fromLastMessage'] = false; div['params']['fromLastMessage'] = false;
div['params']['returnAfterStrand'] = true; div['params']['returnAfterStrand'] = true;
div['params']['msgId'] = ""; 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('label', 'Return to point of departure afterwards',
crel('input', returnAttrs) crel('input', returnAttrs)
), ),