more updates
This commit is contained in:
+27
-13
@@ -4,6 +4,7 @@ from typing import Iterable, List, Literal, Optional
|
||||
from pydantic import BaseModel, Extra, validator
|
||||
|
||||
from rich.pretty import pprint
|
||||
from rota.console import console
|
||||
|
||||
# from .shifts import RotaBuilder, days, sites
|
||||
import uuid
|
||||
@@ -199,27 +200,37 @@ class Worker(BaseModel):
|
||||
(self.id, week, day)
|
||||
] = f"OOP ({oop_name})".format(self.oop)
|
||||
|
||||
days_to_end = (self.calculated_end_date - Rota.start_date).days
|
||||
|
||||
# loop throught dates converting to week / day combination
|
||||
for item in self.pref_not_to_work:
|
||||
days_from_start = (item.date - Rota.start_date).days
|
||||
week = days_from_start // 7 + 1
|
||||
day = Rota.days[(days_from_start % 7)]
|
||||
# Weight the value to take into account the number of preferences
|
||||
# 1 is added to the total number of requests to ensure they do not outweight
|
||||
# a single (or fewer) request(s)
|
||||
Rota.pref_not_to_work[(self.id, week, day)] = 1 / (
|
||||
len(self.pref_not_to_work) + 1
|
||||
)
|
||||
Rota.pref_not_to_work_reason[(self.id, week, day)] = item.reason
|
||||
# Ignore dates past the end of the rota (or end date)
|
||||
if days_from_start < days_to_end:
|
||||
week = days_from_start // 7 + 1
|
||||
day = Rota.days[(days_from_start % 7)]
|
||||
# Weight the value to take into account the number of preferences
|
||||
# 1 is added to the total number of requests to ensure they do not outweight
|
||||
# a single (or fewer) request(s)
|
||||
Rota.pref_not_to_work[(self.id, week, day)] = 1 / (
|
||||
len(self.pref_not_to_work) + 1
|
||||
)
|
||||
Rota.pref_not_to_work_reason[(self.id, week, day)] = item.reason
|
||||
|
||||
# print(not_available_to_work)
|
||||
# loop throught dates converting to week / day combination
|
||||
|
||||
unavailable_set = set()
|
||||
for item in self.not_available_to_work:
|
||||
days_from_start = (item.date - Rota.start_date).days
|
||||
week = days_from_start // 7 + 1
|
||||
day = Rota.days[(days_from_start % 7)]
|
||||
Rota.unavailable_to_work.add((self.id, week, day))
|
||||
Rota.unavailable_to_work_reason[(self.id, week, day)] = item.reason
|
||||
# Ignore dates past the end of the rota (or end date)
|
||||
if days_from_start < days_to_end:
|
||||
week = days_from_start // 7 + 1
|
||||
day = Rota.days[(days_from_start % 7)]
|
||||
Rota.unavailable_to_work.add((self.id, week, day))
|
||||
Rota.unavailable_to_work_reason[(self.id, week, day)] = item.reason
|
||||
unavailable_set.add((week, day))
|
||||
|
||||
|
||||
for item in self.work_requests:
|
||||
days_from_start = (item.date - Rota.start_date).days
|
||||
@@ -257,6 +268,9 @@ class Worker(BaseModel):
|
||||
if days_to_work < 1:
|
||||
self.fte_adj = 0
|
||||
|
||||
if days_to_work > 0 and (days_to_work - len(unavailable_set)) / days_to_work < 0.3:
|
||||
console.print(f"Warning {self.name} has excessive unavailability [{len(unavailable_set)}/{days_to_work}, adjusted fte={self.fte_adj}] (this may be infeasible)", style="red")
|
||||
|
||||
def __lt__(self, other) -> bool:
|
||||
return (self.site, self.grade, self.fte_adj, self.name) < (
|
||||
other.site,
|
||||
|
||||
Reference in New Issue
Block a user