Skip to content

Commit

Permalink
Refactor metrics reporting for more useful logging
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Nov 16, 2023
1 parent d189c38 commit 03022dc
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions neon_audio/tts/neon.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ def get_requested_tts_languages(msg) -> list:
return tts_reqs


def _sort_timing_metrics(timings: dict) -> dict:
"""
Sort combined timing context into timestamps and durations
"""
to_return = {"timestamps": {}, "durations": {}}
for key, val in timings:
if val > 10000.0: # Arbitrary value that is > longest duration
to_return["timestamps"][key] = val
else:
to_return["durations"][key] = val
return to_return


class NeonPlaybackThread(PlaybackThread):
def __init__(self, queue, bus=None):
LOG.info("Initializing NeonPlaybackThread")
Expand Down Expand Up @@ -172,8 +185,8 @@ def _play(self):
message.context["timestamp"] = time()
self.bus.emit(message.forward("neon.metric",
{"name": "local_interaction",
"timestamp": time(),
"timing": message.context['timing']}))
**_sort_timing_metrics(
message.context['timing'])}))


class WrappedTTS(TTS):
Expand Down Expand Up @@ -369,8 +382,8 @@ def execute(self, sentence: str, ident: str = None, listen: bool = False,
message.context["timestamp"] = time()
self.bus.emit(message.forward("neon.metric",
{"name": "klat_interaction",
"timestamp": time(),
"timing": message.context['timing']}))
**_sort_timing_metrics(
message.context['timing'])}))
else:
# Local user has multiple configured languages (or genders)
for r in responses.values():
Expand Down

0 comments on commit 03022dc

Please sign in to comment.