mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-29 12:50:55 +02:00
Tests
This commit is contained in:
@ -128,6 +128,7 @@ class WEISurveyAlgorithm:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class WEISurvey:
|
||||
"""
|
||||
Survey associated to a first year WEI registration.
|
||||
|
@ -58,20 +58,23 @@ class WEISurveyForm2025(forms.Form):
|
||||
buses = WEISurveyAlgorithm2025.get_buses()
|
||||
informations = {bus: WEIBusInformation2025(bus) for bus in buses}
|
||||
scores = sum((list(informations[bus].scores.values()) for bus in buses), [])
|
||||
average_score = sum(scores) / len(scores)
|
||||
if scores:
|
||||
average_score = sum(scores) / len(scores)
|
||||
else:
|
||||
average_score = 0
|
||||
|
||||
preferred_words = {bus: [word for word in WORDS
|
||||
if informations[bus].scores[word] >= average_score]
|
||||
for bus in buses}
|
||||
|
||||
# Correction : proposer plusieurs mots différents à chaque étape
|
||||
N_CHOICES = 4 # Nombre de mots à proposer à chaque étape
|
||||
n_choices = 4 # Nombre de mots à proposer à chaque étape
|
||||
all_preferred_words = set()
|
||||
for bus_words in preferred_words.values():
|
||||
all_preferred_words.update(bus_words)
|
||||
all_preferred_words = list(all_preferred_words)
|
||||
rng.shuffle(all_preferred_words)
|
||||
words = all_preferred_words[:N_CHOICES]
|
||||
words = all_preferred_words[:n_choices]
|
||||
self.fields["word"].choices = [(w, w) for w in words]
|
||||
|
||||
|
||||
@ -96,7 +99,7 @@ class BusInformationForm2025(forms.ModelForm):
|
||||
|
||||
def __init__(self, *args, words=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
initial_scores = {}
|
||||
if self.instance and self.instance.information_json:
|
||||
try:
|
||||
@ -106,13 +109,13 @@ class BusInformationForm2025(forms.ModelForm):
|
||||
initial_scores = {}
|
||||
if words is None:
|
||||
words = WORDS
|
||||
self.words = words
|
||||
self.words = words
|
||||
|
||||
CHOICES = [(i, str(i)) for i in range(6)] # [(0, '0'), (1, '1'), ..., (5, '5')]
|
||||
choices = [(i, str(i)) for i in range(6)] # [(0, '0'), (1, '1'), ..., (5, '5')]
|
||||
for word in words:
|
||||
self.fields[word] = forms.TypedChoiceField(
|
||||
label=word,
|
||||
choices=CHOICES,
|
||||
choices=choices,
|
||||
coerce=int,
|
||||
initial=initial_scores.get(word, 0),
|
||||
required=True,
|
||||
@ -239,6 +242,7 @@ class WEISurveyAlgorithm2025(WEISurveyAlgorithm):
|
||||
@classmethod
|
||||
def get_bus_information_form(cls):
|
||||
return BusInformationForm2025
|
||||
|
||||
def run_algorithm(self, display_tqdm=False):
|
||||
"""
|
||||
Gale-Shapley algorithm implementation.
|
||||
|
Reference in New Issue
Block a user