From 178ce2b5791b9906c334751b6ce65808ff972661 Mon Sep 17 00:00:00 2001 From: mcngnt Date: Tue, 10 Sep 2024 19:37:12 +0200 Subject: [PATCH 1/2] update hardcoded --- apps/wei/forms/surveys/wei2024.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/apps/wei/forms/surveys/wei2024.py b/apps/wei/forms/surveys/wei2024.py index 13d619dc..9c418374 100644 --- a/apps/wei/forms/surveys/wei2024.py +++ b/apps/wei/forms/surveys/wei2024.py @@ -276,7 +276,7 @@ class WEISurveyAlgorithm2024(WEISurveyAlgorithm): surveys = list(self.get_survey_class()(r) for r in self.get_registrations()) # All surveys surveys = [s for s in surveys if s.is_complete()] # Don't consider invalid surveys # Don't manage hardcoded people - surveys = [s for s in surveys if not hasattr(s.information, 'hardcoded') or not s.information.hardcoded] + surveys = [s for s in surveys if s.registration.bus is not None] # Reset previous algorithm run for survey in surveys: @@ -290,10 +290,7 @@ class WEISurveyAlgorithm2024(WEISurveyAlgorithm): registrations = self.get_registrations() non_men_total = registrations.filter(~Q(gender='male')).count() for bus in self.get_buses(): - free_seats = bus.size - WEIMembership.objects.filter(bus=bus, registration__first_year=False).count() - # Remove hardcoded people - free_seats -= WEIMembership.objects.filter(bus=bus, registration__first_year=True, - registration__information_json__icontains="hardcoded").count() + free_seats = bus.size - WEIMembership.objects.filter(bus=bus).count() quotas[bus] = 4 + int(non_men_total / registrations.count() * free_seats) tqdm_obj = None @@ -306,11 +303,8 @@ class WEISurveyAlgorithm2024(WEISurveyAlgorithm): quotas = {} for bus in self.get_buses(): - free_seats = bus.size - WEIMembership.objects.filter(bus=bus, registration__first_year=False).count() + free_seats = bus.size - WEIMembership.objects.filter(bus=bus).count() free_seats -= sum(1 for s in non_men if s.information.selected_bus_pk == bus.pk) - # Remove hardcoded people - free_seats -= WEIMembership.objects.filter(bus=bus, registration__first_year=True, - registration__information_json__icontains="hardcoded").count() quotas[bus] = free_seats if display_tqdm: From c1a353963aa2aeb1bcb6e3073dc85cd0c01bd306 Mon Sep 17 00:00:00 2001 From: mcngnt Date: Thu, 12 Sep 2024 11:36:37 +0200 Subject: [PATCH 2/2] handle hardcoded corrected --- apps/wei/forms/surveys/wei2024.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/wei/forms/surveys/wei2024.py b/apps/wei/forms/surveys/wei2024.py index 9c418374..76932bef 100644 --- a/apps/wei/forms/surveys/wei2024.py +++ b/apps/wei/forms/surveys/wei2024.py @@ -276,13 +276,27 @@ class WEISurveyAlgorithm2024(WEISurveyAlgorithm): surveys = list(self.get_survey_class()(r) for r in self.get_registrations()) # All surveys surveys = [s for s in surveys if s.is_complete()] # Don't consider invalid surveys # Don't manage hardcoded people - surveys = [s for s in surveys if s.registration.bus is not None] + # surveys = [s for s in surveys if s.bus_id != None] + # surveys = [s for s in surveys if not hasattr(s.information, 'hardcoded') or not s.information.hardcoded] + + + # surveys = [s for s in surveys if s.registration.user_id in free_users] + + # hardcoded_first_year_mb = WEIMembership.objects.filter(bus != None,registration__first_year=True) + # hardcoded_first_year = hardcoded_first_year_mb.values_list('user__id', 'bus__id') + + hardcoded_first_year_mb = WEIMembership.objects.filter(registration__first_year=True) + hardcoded_first_year = {mb.user.id if mb.bus else None: mb.bus.id if mb.bus else None for mb in hardcoded_first_year_mb} + # Reset previous algorithm run for survey in surveys: survey.free() + if survey.registration.user_id in hardcoded_first_year.keys(): + survey.select_bus(hardcoded_first_year[s.registration.user_id]) survey.save() + non_men = [s for s in surveys if s.registration.gender != 'male'] men = [s for s in surveys if s.registration.gender == 'male'] @@ -290,7 +304,8 @@ class WEISurveyAlgorithm2024(WEISurveyAlgorithm): registrations = self.get_registrations() non_men_total = registrations.filter(~Q(gender='male')).count() for bus in self.get_buses(): - free_seats = bus.size - WEIMembership.objects.filter(bus=bus).count() + free_seats = bus.size - WEIMembership.objects.filter(bus=bus, registration__first_year=False).count() + free_seats -= sum(1 for s in non_men if s.information.selected_bus_pk == bus.pk) quotas[bus] = 4 + int(non_men_total / registrations.count() * free_seats) tqdm_obj = None @@ -303,7 +318,7 @@ class WEISurveyAlgorithm2024(WEISurveyAlgorithm): quotas = {} for bus in self.get_buses(): - free_seats = bus.size - WEIMembership.objects.filter(bus=bus).count() + free_seats = bus.size - WEIMembership.objects.filter(bus=bus, registration__first_year=False).count() free_seats -= sum(1 for s in non_men if s.information.selected_bus_pk == bus.pk) quotas[bus] = free_seats