Compare commits
No commits in common. "99285186e50ac7f736754a5b00443e0f156755a7" and "7242ed2eddb249834fee81ea17735351659fb03f" have entirely different histories.
99285186e5
...
7242ed2edd
|
@ -2,9 +2,7 @@ import math
|
||||||
import secrets
|
import secrets
|
||||||
from base64 import urlsafe_b64encode
|
from base64 import urlsafe_b64encode
|
||||||
from datetime import datetime, time
|
from datetime import datetime, time
|
||||||
from random import random
|
|
||||||
|
|
||||||
import sentry_sdk
|
|
||||||
from django.db.models import Count, Exists, ExpressionWrapper, Max, OuterRef, Sum
|
from django.db.models import Count, Exists, ExpressionWrapper, Max, OuterRef, Sum
|
||||||
from django.db.models.fields import DateTimeField
|
from django.db.models.fields import DateTimeField
|
||||||
from django.db.models.lookups import LessThan
|
from django.db.models.lookups import LessThan
|
||||||
|
@ -76,24 +74,17 @@ class TeamMember(models.Model):
|
||||||
free_slot_count = free_bucket.annotate(
|
free_slot_count = free_bucket.annotate(
|
||||||
needed_helpers=F("required_helpers") - F("fallback_count")
|
needed_helpers=F("required_helpers") - F("fallback_count")
|
||||||
).aggregate(sum=Sum("needed_helpers"))["sum"]
|
).aggregate(sum=Sum("needed_helpers"))["sum"]
|
||||||
|
|
||||||
quota = global_preferences["helper__fallback_quota"]
|
|
||||||
number_of_team_members = TeamMember.objects.count()
|
|
||||||
max_shifts_per_member = total_slot_count / max(
|
|
||||||
number_of_team_members * quota, 1
|
|
||||||
)
|
|
||||||
|
|
||||||
active_team_members = (
|
active_team_members = (
|
||||||
TeamMember.objects.filter(~Q(fallback_shifts=None)).count() + 1
|
TeamMember.objects.filter(~Q(fallback_shifts=None)).count() + 1
|
||||||
)
|
)
|
||||||
shifts_per_member = total_slot_count / active_team_members
|
|
||||||
|
|
||||||
extra_chance, shift_count = math.modf(
|
quota = global_preferences["helper__fallback_quota"]
|
||||||
min(max_shifts_per_member, shifts_per_member)
|
number_of_team_members = TeamMember.objects.count()
|
||||||
|
max_shifts_per_member = math.ceil(
|
||||||
|
total_slot_count / max((number_of_team_members * quota), 1)
|
||||||
)
|
)
|
||||||
shift_count = int(shift_count)
|
shifts_per_member = math.ceil(total_slot_count / (active_team_members))
|
||||||
if extra_chance > random():
|
shift_count = min(max_shifts_per_member, shifts_per_member)
|
||||||
shift_count += 1
|
|
||||||
|
|
||||||
blocked_times = []
|
blocked_times = []
|
||||||
for shift in self.fallback_shifts.all():
|
for shift in self.fallback_shifts.all():
|
||||||
|
@ -183,9 +174,6 @@ class TeamMember(models.Model):
|
||||||
break
|
break
|
||||||
if not assignment:
|
if not assignment:
|
||||||
print("could not find any matching assignments to take away")
|
print("could not find any matching assignments to take away")
|
||||||
sentry_sdk.capture_message(
|
|
||||||
"could not find any matching assignments to take away"
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
shifts_needed -= 1
|
shifts_needed -= 1
|
||||||
blocked_times.append(
|
blocked_times.append(
|
||||||
|
|
Loading…
Reference in New Issue