diff --git a/hugvey/central_command.py b/hugvey/central_command.py index b85c868..d9d0825 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -158,12 +158,14 @@ class CentralCommand(object): # status['history'] = hv.story.getLogSummary() # disabled as it is a bit slow. We now have eventLog # status['counts'] = {t: len(a) for t, a in status['history'].items() if t != 'directions' } status['counts'] = {} if not hv.story else hv.story.getLogCounts() - status['duration'] = 0 if not hv.story else hv.story.timer.getElapsed() + status['duration'] = 0 if not hv.story else (hv.story.timer.getElapsed('first_speech') if hv.story.timer.hasMark('first_speech') else hv.story.timer.getElapsed()) status['has_state'] = Story.hugveyHasSavedState(hv.lightId) status['variables'] = {} if not isSelected or not hv.story else hv.story.variableValues # evLogger = eventLogger.getChild(f"{hv_id}") - + status['time_since_hugvey_spoke_state'] = "" + status['time_since_visitor_spoke_state'] = "" + if not hv.story: status['time_since_hugvey_spoke'] = '-' status['time_since_visitor_spoke'] = '-' @@ -175,23 +177,21 @@ class CentralCommand(object): else: diff = datetime.timedelta(seconds=int(hv.story.timer.getElapsed() - hv.story.lastMsgFinishTime)) status['time_since_hugvey_spoke'] = str(diff) -# if diff > 300: -# evLogger.warning("Very long time since hugvey spoke") -# elif diff > 100: -# evLogger.warning("Long time since hugvey spoke") -# else: -# #clear warning -# pass + if diff > 300: + status['time_since_hugvey_spoke_state'] = 'critical' + elif diff > 100: + status['time_since_hugvey_spoke_state'] = 'warning' if not hv.story.timer.hasMark('last_speech'): status['time_since_visitor_spoke'] = 'never' else: diff = datetime.timedelta(seconds=int(hv.story.timer.getElapsed('last_speech'))) status['time_since_visitor_spoke'] = str(diff) -# if diff > 300: + if diff > 300: # evLogger.warning("Very long time since audience spoke") -# elif diff > 100: -# evLogger.warning("Long time since audience spoke") + status['time_since_visitor_spoke'] = 'critical' + elif diff > 100: + status['time_since_visitor_spoke'] = 'warning' # else: # #clear warning # pass @@ -535,6 +535,7 @@ class HugveyState(object): self.eventQueue = None self.language_code = 'en-GB' + self.future_language_code = None self.story = None self.streamer = None self.google = None @@ -695,8 +696,9 @@ class HugveyState(object): if event['event'] == 'change_language': self.setLanguage(event['lang_code']) if event['event'] == 'change_language_if_available': - if self.isAvailable() or self.status == self.STATE_BLOCKED: - self.setLanguage(event['lang_code']) + self.future_language_code = event['lang_code'] +# if self.isAvailable() or self.status == self.STATE_BLOCKED: +# self.setLanguage(event['lang_code']) if event['event'] == 'change_light': self.setLightId(event['light_id']) if event['event'] == 'change_light_status': @@ -860,6 +862,10 @@ class HugveyState(object): self.logger.info("Changing language") self.configureLanguage(self.story.language_code) else: + if self.future_language_code and self.future_language_code != self.language_code: + self.logger.info(f"Restart with other language: {self.language_code} -> {self.future_language_code}") + self.configureLanguage(self.future_language_code) + self.story = Story(self, port) self.story.setStoryData(copy.deepcopy(self.command.languages[self.language_code]), self.language_code) diff --git a/hugvey/panopticon.py b/hugvey/panopticon.py index f22b280..5afff98 100644 --- a/hugvey/panopticon.py +++ b/hugvey/panopticon.py @@ -140,6 +140,9 @@ def getWebSocketHandler(central_command): central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'change_language', 'lang_code': lang_code}) def msgChangeLanguageForAllAvailableHugveys(self, lang_code): + """ + Set language for all future hugvey runs (so after a 'finish') + """ for hv_id in central_command.hugveys: central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'change_language_if_available', 'lang_code': lang_code}) diff --git a/hugvey/story.py b/hugvey/story.py index b3858fd..bad27e8 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -277,7 +277,7 @@ class Reply(object): self.utterances.append(utterance) def getText(self) -> str: - return ". ".join([u.text for u in self.utterances]) + return ". ".join([u.text for u in self.utterances]).strip() def getActiveUtterance(self, currentTime) -> Utterance: """ @@ -1592,6 +1592,8 @@ class Story(object): utterance.setText(e['transcript'], now) self.hugvey.eventLogger.info("speaking: content {} \"{}\"".format(id(utterance), e['transcript'])) + if not self.timer.hasMark('first_speech'): + self.timer.setMark('first_speech') self.timer.setMark('last_speech') if e['is_final']: