Implement role based shifts for crew

This commit is contained in:
Hornwitser 2025-03-10 20:58:33 +01:00
parent f69ca520c0
commit a9ba0c55e1
3 changed files with 221 additions and 21 deletions

View file

@ -1,5 +1,5 @@
import { Account } from "~/shared/types/account";
import { Schedule, TimeSlot } from "~/shared/types/schedule";
import { Role, Schedule, Shift, ShiftSlot, TimeSlot } from "~/shared/types/schedule";
const locations = [
{
@ -60,8 +60,8 @@ const events = [
},
{ name: "Fishing Trip", slots: ["d3 12:00 3h30m outside"]},
{ name: "Opening", slots: ["d1 18:30 1h30m stage"]},
{ name: "Closing", slots: ["d5 16:00 1h stage"]},
{ name: "Stage Teardown", crew: true, slots: ["d5 17:00 4h stage"]},
{ name: "Closing", slots: ["d5 10:00 1h stage"]},
{ name: "Stage Teardown", crew: true, slots: ["d5 11:00 4h stage"]},
{ name: "Setup Board Games", crew: true, slots: ["d1 11:30 30m summerhouse"]},
{
name: "Board Games",
@ -131,9 +131,59 @@ const events = [
{ name: "Setup Artist Alley", crew: true, slots: ["d4 10:00 2h clubhouse"]},
{ name: "Artist Alley", slots: ["d4 12:00 4h clubhouse"]},
{ name: "Teardown Artist Alley", crew: true, slots: ["d4 16:00 1h clubhouse"]},
{ name: "Feedback Panel", slots: ["d5 18:00 1h clubhouse"]},
{ name: "Feedback Panel", slots: ["d5 12:00 1h clubhouse"]},
];
const roles: Role[] = [
{ id: "medic", name: "Medic" },
{ id: "security", name: "Security" },
]
const rota = [
{
name: "Medic Early",
role: "medic",
slots: [
"d1 12:00 4h",
"d2 12:00 4h",
"d3 12:00 4h",
"d4 11:00 5h",
"d5 10:00 3h",
],
},
{
name: "Medic Late",
role: "medic",
slots: [
"d1 16:00 7h",
"d2 16:00 6h",
"d3 16:00 8h",
"d4 16:00 7h",
],
},
{
name: "Security Early",
role: "security",
slots: [
"d1 12:00 6h",
"d2 12:00 6h",
"d3 12:00 6h",
"d4 11:00 7h",
"d5 10:00 3h",
],
},
{
name: "Security Late",
role: "security",
slots: [
"d1 18:00 5h",
"d2 18:00 4h",
"d3 18:00 6h",
"d4 18:00 5h",
],
},
]
function toId(name: string) {
return name.toLowerCase().replace(/ /g, "-");
}
@ -142,8 +192,7 @@ function toIso(date: Date) {
return date.toISOString().replace(":00.000Z", "Z");
}
function toSlot(origin: Date, id: string, shorthand: string, index: number, counts: Map<string, number>): TimeSlot {
const [day, start, duration, location] = shorthand.split(" ");
function toDates(origin: Date, day: string, start: string, duration: string) {
const [startHours, startMinutes] = start.split(":").map(time => parseInt(time, 10));
const dayNumber = parseInt(day.slice(1));
@ -156,6 +205,13 @@ function toSlot(origin: Date, id: string, shorthand: string, index: number, coun
const durationTotal = parseInt(durationHours ?? "0") * 60 + parseInt(durationMinutes ?? "0")
const endDate = new Date(startDate.getTime() + durationTotal * 60e3);
return [startDate, endDate];
}
function toSlot(origin: Date, id: string, shorthand: string, index: number, counts: Map<string, number>): TimeSlot {
const [day, start, duration, location] = shorthand.split(" ");
const [startDate, endDate] = toDates(origin, day, start, duration);
return {
id: `${id}-${index}`,
start: toIso(startDate),
@ -165,6 +221,17 @@ function toSlot(origin: Date, id: string, shorthand: string, index: number, coun
};
}
function toShift(origin: Date, id: string, shorthand: string, index: number): ShiftSlot {
const [day, start, duration] = shorthand.split(" ");
const [startDate, endDate] = toDates(origin, day, start, duration);
return {
id: `${id}-${index}`,
start: toIso(startDate),
end: toIso(endDate),
};
}
export function generateDemoSchedule(): Schedule {
const origin = new Date();
const utcOffset = 1;
@ -195,6 +262,15 @@ export function generateDemoSchedule(): Schedule {
locations: locations.map(
({ name, description }) => ({ id: toId(name), name, description })
),
roles,
rota: rota.map(
({ name, role, slots }) => ({
id: toId(name),
name,
role,
slots: slots.map((shorthand, index) => toShift(origin, toId(name), shorthand, index))
})
)
};
}