[WEI] Optimizations in survey load

Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
Yohann D'ANELLO 2021-09-05 18:49:34 +02:00
parent d888d5863a
commit 6d2b7054e2
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 19 additions and 18 deletions

View File

@ -43,28 +43,29 @@ class WEISurveyForm2021(forms.Form):
registration._force_save = True registration._force_save = True
registration.save() registration.save()
rng = Random(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), [])
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()]
rng.shuffle(words)
words = [(w, w) for w in words]
if self.data: if self.data:
self.fields["word"].choices = [(w, w) for w in WORDS] self.fields["word"].choices = [(w, w) for w in WORDS]
if self.is_valid(): if self.is_valid():
return return
rng = Random((information.step + 1) * information.seed)
words = None
buses = WEISurveyAlgorithm2021.get_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 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]
self.fields["word"].choices = words self.fields["word"].choices = words