mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 09:12:11 +01:00 
			
		
		
		
	Better test
This commit is contained in:
		@@ -386,7 +386,7 @@ class WEISurvey2025(WEISurvey):
 | 
			
		||||
        bus_info = self.get_algorithm_class().get_bus_information(bus)
 | 
			
		||||
        # 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, 1 + NB_WORDS))
 | 
			
		||||
                - self.word_mean(getattr(self.information, 'word' + str(i))) for i in range(1, 1 + NB_WORDS)) / self.get_algorithm_class().get_buses().count()
 | 
			
		||||
        return s
 | 
			
		||||
 | 
			
		||||
    @lru_cache()
 | 
			
		||||
@@ -399,7 +399,7 @@ class WEISurvey2025(WEISurvey):
 | 
			
		||||
        Force the choice of bus to be in the 3 preferred buses according to the words
 | 
			
		||||
        """
 | 
			
		||||
        values = list(self.scores_per_bus().items())
 | 
			
		||||
        values.sort(key=lambda item: -item[1][1])
 | 
			
		||||
        values.sort(key=lambda item: -item[1][0])
 | 
			
		||||
        return values
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
@@ -514,7 +514,7 @@ class WEISurveyAlgorithm2025(WEISurveyAlgorithm):
 | 
			
		||||
                        if not survey2.information.valid or survey2.information.get_selected_bus() != bus:
 | 
			
		||||
                            continue
 | 
			
		||||
                        score2 = survey2.score_questions(bus)
 | 
			
		||||
                        if current_scores[0] <= score2:  # Ignore better students
 | 
			
		||||
                        if current_scores[1] <= score2:  # Ignore better students
 | 
			
		||||
                            continue
 | 
			
		||||
                        if least_preferred_survey is None or score2 < least_score:
 | 
			
		||||
                            least_preferred_survey = survey2
 | 
			
		||||
 
 | 
			
		||||
@@ -105,11 +105,28 @@ class TestWEIAlgorithm(TestCase):
 | 
			
		||||
            survey = WEISurvey2025(r)
 | 
			
		||||
            chosen_bus = survey.information.get_selected_bus()
 | 
			
		||||
            buses = survey.ordered_buses()
 | 
			
		||||
            '''print(buses)
 | 
			
		||||
            print(chosen_bus)'''
 | 
			
		||||
            self.assertIn(chosen_bus, [x[0] for x in buses])
 | 
			
		||||
            score = min(v for bus, (v, __) in buses if bus == chosen_bus)
 | 
			
		||||
            max_score = buses[0][1][0]
 | 
			
		||||
            penalty += (max_score - score) ** 2
 | 
			
		||||
            score_questions, score_words = next(scores for bus, scores in buses if bus == chosen_bus)
 | 
			
		||||
            max_score_questions = max(buses[i][1][0] for i in range(len(buses)))
 | 
			
		||||
            max_score_words = max(buses[i][1][1] for i in range(len(buses)))
 | 
			
		||||
            penalty += (max_score_words - score_words) ** 2
 | 
			
		||||
            penalty += (max_score_questions - score_questions) ** 2
 | 
			
		||||
 | 
			
		||||
            self.assertLessEqual(max_score - score, 1)
 | 
			
		||||
            self.assertLessEqual(max_score_questions - score_questions, 3)
 | 
			
		||||
            self.assertLessEqual(max_score_words - score_words, 2.5)
 | 
			
		||||
 | 
			
		||||
        self.assertLessEqual(penalty / 100, 25)  # Tolerance of 5 %
 | 
			
		||||
 | 
			
		||||
        # There shouldn't be users who would prefer to switch buses
 | 
			
		||||
        for r1 in WEIRegistration.objects.filter(wei=self.wei).all():
 | 
			
		||||
            survey1 = WEISurvey2025(r1)
 | 
			
		||||
            bus1 = survey1.information.get_selected_bus()
 | 
			
		||||
            for r2 in WEIRegistration.objects.filter(wei=self.wei, pk__gt=r1.pk):
 | 
			
		||||
                survey2 = WEISurvey2025(r2)
 | 
			
		||||
                bus2 = survey2.information.get_selected_bus()
 | 
			
		||||
                
 | 
			
		||||
                prefer_switch_bus_words = survey1.score_words(bus2) > survey1.score_words(bus1) and survey2.score_words(bus1) > survey2.score_words(bus2)
 | 
			
		||||
                prefer_switch_bus_questions = survey1.score_questions(bus2) > survey1.score_questions(bus1) and survey2.score_questions(bus1) > survey2.score_questions(bus2)
 | 
			
		||||
                self.assertFalse(prefer_switch_bus_words and prefer_switch_bus_questions)
 | 
			
		||||
		Reference in New Issue
	
	Block a user