From 8638c16b34100ef10165dfb648c00c845b32ec6a Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 16 Sep 2021 22:15:30 +0200 Subject: [PATCH] [WEI] New score function that takes in account scores given by other buses Signed-off-by: Yohann D'ANELLO --- apps/wei/forms/surveys/wei2021.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/wei/forms/surveys/wei2021.py b/apps/wei/forms/surveys/wei2021.py index 5b7d4530..380d8683 100644 --- a/apps/wei/forms/surveys/wei2021.py +++ b/apps/wei/forms/surveys/wei2021.py @@ -139,12 +139,25 @@ class WEISurvey2021(WEISurvey): """ 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() def score(self, bus): if not self.is_complete(): raise ValueError("Survey is not ended, can't calculate score") + 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() 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) quotas[bus] = free_seats - print(quotas) - if display_tqdm: tqdm_obj.close() @@ -265,4 +276,4 @@ class WEISurveyAlgorithm2021(WEISurveyAlgorithm): if tqdm_obj is not None: tqdm_obj.n = len(surveys) - len(free_surveys) - tqdm_obj.refresh() + tqdm_obj.refresh() \ No newline at end of file