From 9523b5f05ff51915534835f8e981bac36baaeef8 Mon Sep 17 00:00:00 2001
From: Yohann D'ANELLO <ynerant@crans.org>
Date: Sat, 4 Sep 2021 12:37:29 +0200
Subject: [PATCH] [WEI] Choose one word per bus in the survey

Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
---
 apps/wei/forms/surveys/wei2021.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/apps/wei/forms/surveys/wei2021.py b/apps/wei/forms/surveys/wei2021.py
index 8d5adfad..ddb0fecb 100644
--- a/apps/wei/forms/surveys/wei2021.py
+++ b/apps/wei/forms/surveys/wei2021.py
@@ -47,7 +47,13 @@ class WEISurveyForm2021(forms.Form):
         words = []
         for _ignored in range(information.step + 1):
             # Generate N times words
-            words = [rng.choice(WORDS) for _ignored2 in range(10)]
+            words = None
+            preferred_words = {bus: [word for word in WORDS if WEIBusInformation2021(bus).scores[word] >= 50]
+                               for bus in WEISurveyAlgorithm2021.get_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()]
+            rng.shuffle(words)
         words = [(w, w) for w in words]
         if self.data:
             self.fields["word"].choices = [(w, w) for w in WORDS]
-- 
GitLab