mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 01:12:08 +01:00 
			
		
		
		
	Changed score calculation in survey
This commit is contained in:
		@@ -6,7 +6,7 @@ import random
 | 
			
		||||
from django.contrib.auth.models import User
 | 
			
		||||
from django.test import TestCase
 | 
			
		||||
 | 
			
		||||
from ..forms.surveys.wei2025 import WEIBusInformation2025, WEISurvey2025, WORDS, WEISurveyInformation2025
 | 
			
		||||
from ..forms.surveys.wei2025 import WEIBusInformation2025, WEISurvey2025, WORDS, NB_WORDS, WEISurveyInformation2025
 | 
			
		||||
from ..models import Bus, WEIClub, WEIRegistration
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -34,8 +34,8 @@ class TestWEIAlgorithm(TestCase):
 | 
			
		||||
            bus = Bus.objects.create(wei=self.wei, name=f"Bus {i}", size=10)
 | 
			
		||||
            self.buses.append(bus)
 | 
			
		||||
            information = WEIBusInformation2025(bus)
 | 
			
		||||
            for word in WORDS:
 | 
			
		||||
                information.scores[word] = random.randint(0, 101)
 | 
			
		||||
            for word in WORDS['list']:
 | 
			
		||||
                information.scores[word] = random.randint(0, 6)
 | 
			
		||||
            information.save()
 | 
			
		||||
            bus.save()
 | 
			
		||||
 | 
			
		||||
@@ -54,7 +54,7 @@ class TestWEIAlgorithm(TestCase):
 | 
			
		||||
            )
 | 
			
		||||
            information = WEISurveyInformation2025(registration)
 | 
			
		||||
            for j in range(1, 21):
 | 
			
		||||
                setattr(information, f'word{j}', random.choice(WORDS))
 | 
			
		||||
                setattr(information, f'word{j}', random.choice(WORDS['list']))
 | 
			
		||||
            information.step = 20
 | 
			
		||||
            information.save(registration)
 | 
			
		||||
            registration.save()
 | 
			
		||||
@@ -83,9 +83,11 @@ class TestWEIAlgorithm(TestCase):
 | 
			
		||||
                birth_date='2000-01-01',
 | 
			
		||||
            )
 | 
			
		||||
            information = WEISurveyInformation2025(registration)
 | 
			
		||||
            for j in range(1, 21):
 | 
			
		||||
                setattr(information, f'word{j}', random.choice(WORDS))
 | 
			
		||||
            information.step = 20
 | 
			
		||||
            for j in range(1, 1 + NB_WORDS):
 | 
			
		||||
                setattr(information, f'word{j}', random.choice(WORDS['list']))
 | 
			
		||||
            for q in WORDS['questions']:
 | 
			
		||||
                setattr(information, q, random.choice(list(WORDS['questions'][q][1].keys())))
 | 
			
		||||
            information.step = len(WORDS['questions']) + 1
 | 
			
		||||
            information.save(registration)
 | 
			
		||||
            registration.save()
 | 
			
		||||
 | 
			
		||||
@@ -106,6 +108,6 @@ class TestWEIAlgorithm(TestCase):
 | 
			
		||||
            max_score = buses[0][1]
 | 
			
		||||
            penalty += (max_score - score) ** 2
 | 
			
		||||
 | 
			
		||||
            self.assertLessEqual(max_score - score, 25)  # Always less than 25 % of tolerance
 | 
			
		||||
            self.assertLessEqual(max_score - score, 1)  # Always less than 25 % of tolerance
 | 
			
		||||
 | 
			
		||||
        self.assertLessEqual(penalty / 100, 25)  # Tolerance of 5 %
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user