Skip to content
Snippets Groups Projects
Verified Commit 6d2b7054 authored by ynerant's avatar ynerant
Browse files

[WEI] Optimizations in survey load


Signed-off-by: ynerant's avatarYohann D'ANELLO <ynerant@crans.org>
parent d888d586
No related branches found
No related tags found
1 merge request!175Amélirations questionnaire WEI
Pipeline #9041 failed with stages
in 14 minutes and 42 seconds
......@@ -43,28 +43,29 @@ class WEISurveyForm2021(forms.Form):
registration._force_save = True
registration.save()
rng = Random(information.seed)
if self.data:
self.fields["word"].choices = [(w, w) for w in WORDS]
if self.is_valid():
return
rng = Random((information.step + 1) * information.seed)
words = None
# Update seed
rng.randint(0, information.step)
buses = WEISurveyAlgorithm2021.get_buses()
scores = sum((list(WEIBusInformation2021(bus).scores.values()) for bus in buses), [])
informations = {bus: WEIBusInformation2021(bus) for bus in buses}
scores = sum((list(informations[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]
if informations[bus].scores[word] >= average_score]
for bus in buses}
while words is None or len(set(words)) != len(words):
print("toto")
# 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]
if self.is_valid():
return
self.fields["word"].choices = words
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment