From 7aad114b134aff19538497d5c7a9360114d8822b Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Thu, 25 Apr 2019 13:24:08 +0200 Subject: [PATCH] Track counts for all hugveys (not only selected) and show duration of playing --- hugvey/central_command.py | 4 +++- hugvey/story.py | 7 +++++++ www/images/icon-clock.svg | 2 ++ www/index.html | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 www/images/icon-clock.svg diff --git a/hugvey/central_command.py b/hugvey/central_command.py index 05f28b6..65d2da3 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -128,7 +128,9 @@ class CentralCommand(object): status['finished'] = hv.story.isFinished() status['history'] = {} if isSelected is False else hv.story.getLogSummary() # 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'] = {t: len(a) for t, a in status['history'].items() if t != 'directions' } + status['counts'] = hv.story.getLogCounts() + status['duration'] = hv.story.timer.getElapsed() return status diff --git a/hugvey/story.py b/hugvey/story.py index c7a9c17..be30742 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -482,6 +482,7 @@ class Diversion(object): r = await self.method(story, msgFrom, msgTo) if r: self.hasHit = True + story.addToLog(self) return r async def finalise(self, story): @@ -763,6 +764,12 @@ class Story(object): # print(self.log) return summary + def getLogCounts(self): + return { + 'messages': len([1 for e in self.log if isinstance(e[0], Message)]), + 'diversions': len([1 for e in self.log if isinstance(e[0], Diversion)]), + } + def registerVariable(self, variableName, message): if variableName not in self.variables: self.variables[variableName] = [message] diff --git a/www/images/icon-clock.svg b/www/images/icon-clock.svg new file mode 100644 index 0000000..2f102fa --- /dev/null +++ b/www/images/icon-clock.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/www/index.html b/www/index.html index 6385faf..668c95c 100644 --- a/www/index.html +++ b/www/index.html @@ -59,6 +59,10 @@ {{ hv.msg }} +
+ + {{ timer(hv, 'duration') }} +
Pause
Resume