From 2344493c8ee5af273f3a1eb9933cc22c0085d1c0 Mon Sep 17 00:00:00 2001 From: Fabrice Laurens Date: Sat, 17 Jul 2021 14:49:22 +0200 Subject: [PATCH] nabsurprised: change frequency computation, to match original Nabaztag scale. --- .../locale/fr_FR/LC_MESSAGES/django.po | 21 ++++++++++++------- nabsurprised/nabsurprised.py | 13 +++++++++++- .../templates/nabsurprised/settings.html | 3 ++- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/nabsurprised/locale/fr_FR/LC_MESSAGES/django.po b/nabsurprised/locale/fr_FR/LC_MESSAGES/django.po index e3803be9..a7566e7b 100644 --- a/nabsurprised/locale/fr_FR/LC_MESSAGES/django.po +++ b/nabsurprised/locale/fr_FR/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-02-12 14:21+0100\n" +"POT-Creation-Date: 2021-07-17 15:01+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -84,32 +84,37 @@ msgstr "Fréquence des humeurs" #: templates/nabsurprised/settings.html:13 msgctxt "Surprise frequency" +msgid "Rarely" +msgstr "Rarement" + +#: templates/nabsurprised/settings.html:14 +msgctxt "Surprise frequency" msgid "Sometimes" msgstr "De temps en temps" -#: templates/nabsurprised/settings.html:14 +#: templates/nabsurprised/settings.html:15 msgctxt "Surprise frequency" msgid "Often" msgstr "Souvent" -#: templates/nabsurprised/settings.html:15 +#: templates/nabsurprised/settings.html:16 msgctxt "Surprise frequency" msgid "Very often" msgstr "Très souvent" -#: templates/nabsurprised/settings.html:16 +#: templates/nabsurprised/settings.html:17 msgctxt "Surprise frequency" -msgid "Disabled" +msgid "Never" msgstr "Jamais" -#: templates/nabsurprised/settings.html:22 +#: templates/nabsurprised/settings.html:23 msgid "Surprise me now!" msgstr "Chatouille" -#: templates/nabsurprised/settings.html:29 +#: templates/nabsurprised/settings.html:30 msgid "Save" msgstr "Enregistrer" -#: templates/nabsurprised/settings.html:30 +#: templates/nabsurprised/settings.html:31 msgid "Reset" msgstr "Annuler" diff --git a/nabsurprised/nabsurprised.py b/nabsurprised/nabsurprised.py index 8c65aa9a..396910ce 100644 --- a/nabsurprised/nabsurprised.py +++ b/nabsurprised/nabsurprised.py @@ -8,6 +8,14 @@ class NabSurprised(NabRandomService): + RARELY, SOMETIMES, OFTEN, VERY_OFTEN = 30, 50, 125, 250 + FREQUENCY_SECONDS = { + RARELY: 10800, + SOMETIMES: 7200, + OFTEN: 3600, + VERY_OFTEN: 1200, + } + NLU_INTENTS = [ "nabsurprised/surprise", "nabsurprised/carrot", @@ -61,7 +69,10 @@ async def _do_perform(self, expiration, lang, type): await self.writer.drain() def compute_random_delta(self, frequency): - return (256 - frequency) * 60 * (random.uniform(0, 255) + 64) / 128 + key = frequency + if key not in NabSurprised.FREQUENCY_SECONDS: + key = NabSurprised.RARELY + return random.uniform(0, NabSurprised.FREQUENCY_SECONDS[key]) async def process_nabd_packet(self, packet): if packet["type"] == "asr_event": diff --git a/nabsurprised/templates/nabsurprised/settings.html b/nabsurprised/templates/nabsurprised/settings.html index be2bb1a7..397712e7 100644 --- a/nabsurprised/templates/nabsurprised/settings.html +++ b/nabsurprised/templates/nabsurprised/settings.html @@ -10,10 +10,11 @@
{% trans "Surprise" %}