mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-08-03 14:16:54 +02:00
More robust algorithm
This commit is contained in:
@@ -365,7 +365,7 @@ class WEISurvey2025(WEISurvey):
|
||||
return sum([cls.get_algorithm_class().get_bus_information(bus).scores[word] for bus in buses]) / buses.count()
|
||||
|
||||
@lru_cache()
|
||||
def score(self, bus):
|
||||
def score_questions(self, bus):
|
||||
"""
|
||||
The score given by the answers to the questions
|
||||
"""
|
||||
@@ -391,7 +391,7 @@ class WEISurvey2025(WEISurvey):
|
||||
|
||||
@lru_cache()
|
||||
def scores_per_bus(self):
|
||||
return {bus: (self.score(bus), self.score_words(bus)) for bus in self.get_algorithm_class().get_buses()}
|
||||
return {bus: (self.score_questions(bus), self.score_words(bus)) for bus in self.get_algorithm_class().get_buses()}
|
||||
|
||||
@lru_cache()
|
||||
def ordered_buses(self):
|
||||
@@ -400,7 +400,6 @@ class WEISurvey2025(WEISurvey):
|
||||
"""
|
||||
values = list(self.scores_per_bus().items())
|
||||
values.sort(key=lambda item: -item[1][1])
|
||||
values = values[:3]
|
||||
return values
|
||||
|
||||
@classmethod
|
||||
@@ -509,17 +508,17 @@ class WEISurveyAlgorithm2025(WEISurveyAlgorithm):
|
||||
else:
|
||||
# Current bus has not enough places. Remove the least preferred student from the bus if existing
|
||||
least_preferred_survey = None
|
||||
least_scores = (-1, -1)
|
||||
least_score = -1
|
||||
# Find the least student in the bus that has a lower score than the current student
|
||||
for survey2 in surveys:
|
||||
if not survey2.information.valid or survey2.information.get_selected_bus() != bus:
|
||||
continue
|
||||
scores2 = survey2.score(bus), survey2.score_words(bus)
|
||||
if current_scores <= scores2: # Ignore better students
|
||||
score2 = survey2.score_questions(bus)
|
||||
if current_scores[0] <= score2: # Ignore better students
|
||||
continue
|
||||
if least_preferred_survey is None or scores2 < least_scores:
|
||||
if least_preferred_survey is None or score2 < least_score:
|
||||
least_preferred_survey = survey2
|
||||
least_scores = scores2
|
||||
least_score = score2
|
||||
|
||||
if least_preferred_survey is not None:
|
||||
# Remove the least student from the bus and put the current student in.
|
||||
|
Reference in New Issue
Block a user