you do wanna make me cry and i wanna say goodbye
This commit is contained in:
parent
eb21bfe099
commit
25c2c1bee9
|
@ -7,9 +7,6 @@ def assign_random_shifts(modeladmin, request, queryset):
|
||||||
member.assign_random_shifts()
|
member.assign_random_shifts()
|
||||||
|
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
|
|
||||||
|
|
||||||
class FallbackAssignmentInline(admin.TabularInline):
|
class FallbackAssignmentInline(admin.TabularInline):
|
||||||
model = FallbackAssignment
|
model = FallbackAssignment
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
# Generated by Django 4.0.4 on 2023-05-12 19:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("app", "0011_room_description"),
|
||||||
|
("fallback", "0002_fallbackassignment"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="fallbackassignment",
|
||||||
|
name="slot",
|
||||||
|
field=models.IntegerField(default=0),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="teammember",
|
||||||
|
name="fallback_shifts",
|
||||||
|
field=models.ManyToManyField(
|
||||||
|
through="fallback.FallbackAssignment", to="app.shift"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,4 +1,6 @@
|
||||||
from shiftregister.app.models import *
|
from shiftregister.importer.models import *
|
||||||
|
|
||||||
|
night_shift_query = Q(start_at__hour__gte=21) | Q(start_at__hour__lte=10)
|
||||||
|
|
||||||
|
|
||||||
class TeamMember(models.Model):
|
class TeamMember(models.Model):
|
||||||
|
@ -6,9 +8,24 @@ class TeamMember(models.Model):
|
||||||
fallback_shifts = models.ManyToManyField(Shift, through="FallbackAssignment")
|
fallback_shifts = models.ManyToManyField(Shift, through="FallbackAssignment")
|
||||||
|
|
||||||
def assign_random_shifts(self):
|
def assign_random_shifts(self):
|
||||||
shifts = Shift.objects.order_by("?")[:5]
|
events_bucket_1 = Event.objects.filter(
|
||||||
for shift in shifts:
|
~night_shift_query, deleted=False, calendar__needs_fallback=True
|
||||||
self.fallback_shifts.add(shift)
|
)
|
||||||
|
events_bucket_2 = Event.objects.filter(
|
||||||
|
night_shift_query, deleted=False, calendar__needs_fallback=True
|
||||||
|
)
|
||||||
|
self._assign_from_bucket(events_bucket_1)
|
||||||
|
self._assign_from_bucket(events_bucket_2)
|
||||||
|
|
||||||
|
def _assign_from_bucket(self, bucket):
|
||||||
|
quota = global_preferences["helper__fallback_quota"]
|
||||||
|
number_of_team_members = TeamMember.objects.count()
|
||||||
|
max_shifts_per_member = bucket.count() / (number_of_team_members * quota)
|
||||||
|
|
||||||
|
assigned_shifts = self.fallback_shifts.filter(night_shift_query)
|
||||||
|
|
||||||
|
# for events in events:
|
||||||
|
# self.fallback_shifts.add(events)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.name}"
|
return f"{self.name}"
|
||||||
|
|
Loading…
Reference in New Issue