[WEI] New score function that takes in account scores given by other buses

Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
Yohann D'ANELLO 2021-09-16 22:15:30 +02:00
parent 9583cec3ff
commit 8638c16b34
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 15 additions and 4 deletions

View File

@ -139,12 +139,25 @@ class WEISurvey2021(WEISurvey):
""" """
return self.information.step == 20 return self.information.step == 20
@classmethod
@lru_cache()
def word_mean(cls, word):
"""
Calculate the mid-score given by all buses.
"""
buses = cls.get_algorithm_class().get_buses()
return sum([cls.get_algorithm_class().get_bus_information(bus).scores[word] for bus in buses]) / buses.count()
@lru_cache() @lru_cache()
def score(self, bus): def score(self, bus):
if not self.is_complete(): if not self.is_complete():
raise ValueError("Survey is not ended, can't calculate score") raise ValueError("Survey is not ended, can't calculate score")
bus_info = self.get_algorithm_class().get_bus_information(bus) bus_info = self.get_algorithm_class().get_bus_information(bus)
return sum(bus_info.scores[getattr(self.information, 'word' + str(i))] for i in range(1, 21)) / 20 # Score is the given score by the bus subtracted to the mid-score of the buses.
s = sum(bus_info.scores[getattr(self.information, 'word' + str(i))]
- self.word_mean(getattr(self.information, 'word' + str(i))) for i in range(1, 21)) / 20
return s
@lru_cache() @lru_cache()
def scores_per_bus(self): def scores_per_bus(self):
@ -210,8 +223,6 @@ class WEISurveyAlgorithm2021(WEISurveyAlgorithm):
free_seats -= sum(1 for s in non_men if s.information.selected_bus_pk == bus.pk) free_seats -= sum(1 for s in non_men if s.information.selected_bus_pk == bus.pk)
quotas[bus] = free_seats quotas[bus] = free_seats
print(quotas)
if display_tqdm: if display_tqdm:
tqdm_obj.close() tqdm_obj.close()
@ -265,4 +276,4 @@ class WEISurveyAlgorithm2021(WEISurveyAlgorithm):
if tqdm_obj is not None: if tqdm_obj is not None:
tqdm_obj.n = len(surveys) - len(free_surveys) tqdm_obj.n = len(surveys) - len(free_surveys)
tqdm_obj.refresh() tqdm_obj.refresh()