From d888d5863a31ea224bfb0b8ce423dc099562f8fb Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 5 Sep 2021 18:39:03 +0200 Subject: [PATCH] [WEI] For each bus, choose a random word which score is higher than the mid score Signed-off-by: Yohann D'ANELLO --- apps/wei/forms/surveys/wei2021.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/wei/forms/surveys/wei2021.py b/apps/wei/forms/surveys/wei2021.py index 16a9961c..2ff8adcc 100644 --- a/apps/wei/forms/surveys/wei2021.py +++ b/apps/wei/forms/surveys/wei2021.py @@ -49,9 +49,13 @@ class WEISurveyForm2021(forms.Form): # Update seed rng.randint(0, information.step) - preferred_words = {bus: [word for word in WORDS if bus.size > 0 - and WEIBusInformation2021(bus).scores[word] >= 50] - for bus in WEISurveyAlgorithm2021.get_buses()} + buses = WEISurveyAlgorithm2021.get_buses() + scores = sum((list(WEIBusInformation2021(bus).scores.values()) for bus in buses), []) + average_score = sum(scores) / len(scores) + + preferred_words = {bus: [word for word in WORDS + if WEIBusInformation2021(bus).scores[word] >= average_score] + for bus in buses} while words is None or len(set(words)) != len(words): # Ensure that there is no the same word 2 times words = [rng.choice(words) for _ignored2, words in preferred_words.items()]