Compare commits

..

3 Commits

Author SHA1 Message Date
mcngnt 131f508433 Merge branch 'survey_wei_2024' into 'main'
update hardcoded

See merge request bde/nk20!273
2024-09-12 12:03:10 +02:00
mcngnt c1a353963a handle hardcoded corrected 2024-09-12 11:36:37 +02:00
mcngnt 178ce2b579 update hardcoded 2024-09-10 22:41:35 +02:00
1 changed files with 16 additions and 7 deletions

View File

@ -276,13 +276,27 @@ class WEISurveyAlgorithm2024(WEISurveyAlgorithm):
surveys = list(self.get_survey_class()(r) for r in self.get_registrations()) # All surveys 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 surveys = [s for s in surveys if s.is_complete()] # Don't consider invalid surveys
# Don't manage hardcoded people # 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.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 # Reset previous algorithm run
for survey in surveys: for survey in surveys:
survey.free() survey.free()
if survey.registration.user_id in hardcoded_first_year.keys():
survey.select_bus(hardcoded_first_year[s.registration.user_id])
survey.save() survey.save()
non_men = [s for s in surveys if s.registration.gender != 'male'] non_men = [s for s in surveys if s.registration.gender != 'male']
men = [s for s in surveys if s.registration.gender == 'male'] men = [s for s in surveys if s.registration.gender == 'male']
@ -291,9 +305,7 @@ class WEISurveyAlgorithm2024(WEISurveyAlgorithm):
non_men_total = registrations.filter(~Q(gender='male')).count() non_men_total = registrations.filter(~Q(gender='male')).count()
for bus in self.get_buses(): 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, registration__first_year=False).count()
# Remove hardcoded people free_seats -= sum(1 for s in non_men if s.information.selected_bus_pk == bus.pk)
free_seats -= WEIMembership.objects.filter(bus=bus, registration__first_year=True,
registration__information_json__icontains="hardcoded").count()
quotas[bus] = 4 + int(non_men_total / registrations.count() * free_seats) quotas[bus] = 4 + int(non_men_total / registrations.count() * free_seats)
tqdm_obj = None tqdm_obj = None
@ -308,9 +320,6 @@ class WEISurveyAlgorithm2024(WEISurveyAlgorithm):
for bus in self.get_buses(): 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, registration__first_year=False).count()
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)
# Remove hardcoded people
free_seats -= WEIMembership.objects.filter(bus=bus, registration__first_year=True,
registration__information_json__icontains="hardcoded").count()
quotas[bus] = free_seats quotas[bus] = free_seats
if display_tqdm: if display_tqdm: