-
Notifications
You must be signed in to change notification settings - Fork 2
Freeplay alg #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Freeplay alg #37
Changes from 8 commits
d28295b
8a6752c
2ae5d76
de8c4c2
7b4395c
ba7c570
93e2bc7
4362195
317328c
125db21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,33 +1,116 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { StaffAttendeeID, AdminAttendeeID, CamperAttendeeID, Freeplay } from "../../../types/sessionTypes"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Staff } from "@/types/personTypes"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { StaffAttendeeID, AdminAttendeeID, CamperAttendeeID, Freeplay, PostID, FreeplayID } from "@/types/sessionTypes"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { a } from "framer-motion/dist/types.d-BJcRxCew"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { doesConflictExist } from "./schedulingUtils"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| export class FreeplayScheduler { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| /* The current freeplay schedule */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| schedule: Freeplay = { posts: {}, buddies: {} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| schedule: FreeplayID = { posts: {}, buddies: {}, id: "", sessionId: "" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /* The session attendees that still need to be assigned */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| campers: CamperAttendeeID[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| staff: StaffAttendeeID[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| admins: AdminAttendeeID[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| assignedStaff: StaffAttendeeID[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assignedAdmin: AdminAttendeeID[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| posts: PostID[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /* The freeplay buddies from other freeplays in this session */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| otherFreeplayBuddies: { [attendeeId: number]: number[] } = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // postInfo includes a list of all posts with PostID information (necessary for requiresAdmin flag) --> schedule only includes string of IDs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor() { } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| withSchedule(schedule: Freeplay): FreeplayScheduler { this.schedule = schedule; return this; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| withSchedule(schedule: FreeplayID): FreeplayScheduler { this.schedule = schedule; return this; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| withCampers(campers: CamperAttendeeID[]): FreeplayScheduler { this.campers = campers; return this; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| withStaff(staff: StaffAttendeeID[]): FreeplayScheduler { this.staff = staff; return this; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| withAdmins(admins: AdminAttendeeID[]): FreeplayScheduler { this.admins = admins; return this; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| withPosts(posts: PostID[]): FreeplayScheduler { this.posts = posts; return this; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| getCamperById = (id: number) => this.campers.find(c => c.id === id); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| getPostByID = (id: string) => this.posts.find(p => p.name === id); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+34
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Post lookup should match PostID.id, not name. Schedule keys are post IDs; using 🔧 Suggested fix- getPostByID = (id: string) => this.posts.find(p => p.name === id);
+ getPostByID = (id: string) => this.posts.find(p => p.id === id);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // withOtherFreeplays should build the previousFreeplayBuddies object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||||||||||||||||||||||||||||||||||||||||||||||||||
| withOtherFreeplays(otherFreeplays: Freeplay[]): FreeplayScheduler { return this; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| withOtherFreeplays(otherFreeplays: Freeplay[]): FreeplayScheduler { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const freeplay of otherFreeplays) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const buddieIDStr in freeplay.buddies) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const buddieID = Number(buddieIDStr); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (buddieID in this.otherFreeplayBuddies) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const attendees = freeplay.buddies[buddieID]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // add all attendees that don't already exist | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const att of attendees) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
DurjaMan27 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!this.otherFreeplayBuddies[buddieID].includes(att)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this.otherFreeplayBuddies[buddieID].push(att); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const attendees = freeplay.buddies[buddieID]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this.otherFreeplayBuddies[buddieID] = attendees; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid mutating input freeplay buddy arrays. Assigning and then pushing into arrays sourced from 🧹 Suggested fix- const attendees = freeplay.buddies[buddieID];
+ const attendees = [...freeplay.buddies[buddieID]];
// add all attendees that don't already exist
for (const att of attendees) {
if (!this.otherFreeplayBuddies[buddieID].includes(att)) {
this.otherFreeplayBuddies[buddieID].push(att);
}
}
} else {
- const attendees = freeplay.buddies[buddieID];
- this.otherFreeplayBuddies[buddieID] = attendees;
+ const attendees = [...freeplay.buddies[buddieID]];
+ this.otherFreeplayBuddies[buddieID] = attendees;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return this; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Assigns ADMINs to all posts that require ADMINs and either STAFF or ADMINs to all other posts */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assignPosts() { return this; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assignPosts() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Keep track of available staff/admins | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const availableAdmins = this.admins.filter(admin => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| !this.assignedAdmin.some(assigned => assigned.id === admin.id) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ).filter(admin => !admin.daysOff.includes(this.schedule.id)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const availableStaff = this.staff.filter(staff => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| !this.assignedStaff.some(assigned => assigned.id === staff.id) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ).filter(staff => !staff.daysOff.includes(this.schedule.id)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("Available Staff: ", availableStaff); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("Available Admins: ", availableAdmins); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // assign all ADMIN-only roles first | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const postID in this.schedule.posts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const assigned = this.schedule.posts[postID]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const post = this.getPostByID(postID); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (assigned.length == 0 && post?.requiresAdmin) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (availableAdmins.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const adminID: AdminAttendeeID = availableAdmins.shift()!; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this.schedule.posts[postID] = [adminID.id]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this.assignedAdmin.push(adminID); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // assigns all other roles (not Admin-specific) to admins first, then staff | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const postID in this.schedule.posts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const assigned = this.schedule.posts[postID]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (assigned.length == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (availableAdmins.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const adminID: AdminAttendeeID = availableAdmins.shift()!; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this.schedule.posts[postID] = [adminID.id]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this.assignedAdmin.push(adminID); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (availableStaff.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const staffID: StaffAttendeeID = availableStaff.shift()!; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this.schedule.posts[postID] = [staffID.id]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this.assignedStaff.push(staffID); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+93
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t assign STAFF to admin-only posts in the second pass. The second loop assigns staff to any empty post, including 🛠️ Suggested fix- for (const postID in this.schedule.posts) {
- const assigned = this.schedule.posts[postID];
- if (assigned.length == 0) {
- if (availableAdmins.length > 0) {
- const adminID: AdminAttendeeID = availableAdmins.shift()!;
- this.schedule.posts[postID] = [adminID.id];
- this.assignedAdmin.push(adminID);
- } else if (availableStaff.length > 0) {
- const staffID: StaffAttendeeID = availableStaff.shift()!;
- this.schedule.posts[postID] = [staffID.id];
- this.assignedStaff.push(staffID);
- }
- }
- }
+ for (const postID in this.schedule.posts) {
+ const assigned = this.schedule.posts[postID];
+ if (assigned.length == 0) {
+ const post = this.getPostByID(postID);
+ if (post?.requiresAdmin) {
+ if (availableAdmins.length > 0) {
+ const adminID: AdminAttendeeID = availableAdmins.shift()!;
+ this.schedule.posts[postID] = [adminID.id];
+ this.assignedAdmin.push(adminID);
+ }
+ continue; // keep empty if no admins left
+ }
+ if (availableAdmins.length > 0) {
+ const adminID: AdminAttendeeID = availableAdmins.shift()!;
+ this.schedule.posts[postID] = [adminID.id];
+ this.assignedAdmin.push(adminID);
+ } else if (availableStaff.length > 0) {
+ const staffID: StaffAttendeeID = availableStaff.shift()!;
+ this.schedule.posts[postID] = [staffID.id];
+ this.assignedStaff.push(staffID);
+ }
+ }
+ }🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return this; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Assigns campers to remaining ADMIN & STAFF members for freeplay according to the following rules: | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -39,7 +122,164 @@ export class FreeplayScheduler { | |||||||||||||||||||||||||||||||||||||||||||||||||
| to the same staff member. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| - Prioritize avoiding assigning the same "freeplay buddy" (previous buddy) if possible. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assignCampers() { return this; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assignCampers() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // First filter out by days off | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const availableStaff = this.staff.filter(staff => !staff.daysOff.includes(this.schedule.id)).filter(staff => !this.assignedStaff.some(assigned => assigned.id === staff.id) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| //const allAssignedStaffers = [...this.assignedStaff, ...this.assignedAdmin]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const allFemaleStaff = availableStaff.filter(c => c.gender == "Female"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const allfemaleCampers = this.campers.filter(c => c.gender === "Female"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const allOtherCampers = this.campers.filter(c => c.gender !== "Female" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("Female Campers: ", allfemaleCampers); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("Female Staff: ", allFemaleStaff); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // 2. Assign female campers | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const camper of allfemaleCampers) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let assigned = this.assignToOpenStaffFirstStep(allFemaleStaff, camper); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Fallback: assign to any female staffer with another camper of the same bunk | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!assigned) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assigned = this.assignToOpenStaffSecondStep(allFemaleStaff, camper); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!assigned) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assigned = this.assignToOpenStaffThirdStep(allFemaleStaff, camper); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!assigned) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.warn("No staffer available for camper: ", camper); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const allOtherStaff = availableStaff.filter(c => !this.schedule.buddies[c.id] || this.schedule.buddies[c.id].length == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // 3. Assign male campers | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const camper of allOtherCampers) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let assigned = this.assignToOpenStaffFirstStep(allOtherStaff, camper); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Fallback: assign to any staffer with another camper of the same bunk | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!assigned) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assigned = this.assignToOpenStaffSecondStep(allOtherStaff, camper); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!assigned) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assigned = this.assignToOpenStaffThirdStep(allOtherStaff, camper); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!assigned) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.warn("No staffer available for camper: ", camper); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return this; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assigns camper to any staffer (not in same bunk)that they weren't assigned to before | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assignToOpenStaffFirstStep(allAssignedStaffers: (StaffAttendeeID | AdminAttendeeID)[], camper: CamperAttendeeID) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let assigned = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Loop through female staffers/admins first | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const staffer of allAssignedStaffers) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Checks if staffer is already assigned to a camper | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const alreadyAssigned = this.schedule.buddies[staffer.id] || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Checks if staffer was already assigned to this camper in a previous iteration | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const prevBuddies = this.otherFreeplayBuddies[staffer.id] || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check buddy conflict (camper.id appears in staffer's prevBuddies) and if camper-staff conflict exists | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const hasConflict = prevBuddies.includes(camper.id) || doesConflictExist(staffer, [camper.id]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!hasConflict && alreadyAssigned.length == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( (staffer.role === "STAFF" && staffer.bunk !== camper.bunk)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!this.schedule.buddies[staffer.id]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this.schedule.buddies[staffer.id] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this.schedule.buddies[staffer.id].push(camper.id); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assigned = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+198
to
+208
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Find the FreeplayScheduler.ts file and extract the function signature
fd -e ts -n FreeplayScheduler && head -230 src/features/scheduling/generation/FreeplayScheduler.ts | tail -50Repository: Hack4Impact-UMD/camp-starfish Length of output: 303 🏁 Script executed: # Search for AdminAttendee interface definition
rg -n "interface AdminAttendee" -A 10Repository: Hack4Impact-UMD/camp-starfish Length of output: 748 🏁 Script executed: # Check if AdminAttendee has a bunk property
rg -n "bunk" --type=ts -A 2 -B 2 | head -80Repository: Hack4Impact-UMD/camp-starfish Length of output: 4890 🏁 Script executed: # Find all calls to assignToOpenStaffFirstStep to see what's passed
rg -n "assignToOpenStaffFirstStep" -B 3 -A 3Repository: Hack4Impact-UMD/camp-starfish Length of output: 2151 🏁 Script executed: # Check the commented-out line 128 context
sed -n '120,135p' src/features/scheduling/generation/FreeplayScheduler.tsRepository: Hack4Impact-UMD/camp-starfish Length of output: 756 🏁 Script executed: # Find AdminAttendee interface (not AdminAttendeeID)
rg -n "interface AdminAttendee[^I]" -A 15Repository: Hack4Impact-UMD/camp-starfish Length of output: 55 🏁 Script executed: # Check the specific lines 198-208 in FreeplayScheduler.ts to see the exact code
sed -n '198,208p' src/features/scheduling/generation/FreeplayScheduler.tsRepository: Hack4Impact-UMD/camp-starfish Length of output: 444 🏁 Script executed: # Check if AdminAttendee has role property and what values it can have
rg -n "role.*ADMIN" --type=ts -B 2 -A 2Repository: Hack4Impact-UMD/camp-starfish Length of output: 3833 ADMINs are silently skipped due to role check. The function signature accepts Either narrow the type signature to 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return assigned | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assigns camper to any staffer with another camper of the same bunk | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assignToOpenStaffSecondStep(allAssignedStaffers: (StaffAttendeeID | AdminAttendeeID)[], camper: CamperAttendeeID) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| let assigned = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const staffer of allAssignedStaffers) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const prevBuddies = this.otherFreeplayBuddies[staffer.id] || [] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const hasConflict = prevBuddies.includes(camper.id) || doesConflictExist(staffer, [camper.id]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (hasConflict) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const alreadyAssigned = this.schedule.buddies[staffer.id] || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (alreadyAssigned.length == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const otherCamper = this.getCamperById(alreadyAssigned[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!otherCamper) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (otherCamper.bunk == camper.bunk && otherCamper.id !== camper.id) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this.schedule.buddies[staffer.id].push(camper.id); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assigned = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return assigned; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| assignToOpenStaffThirdStep(allAssignedStaffers: (StaffAttendeeID | AdminAttendeeID)[], camper: CamperAttendeeID) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| let assigned = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const staffer of allAssignedStaffers) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (doesConflictExist(staffer, [camper.id])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const alreadyAssigned = this.schedule.buddies[staffer.id] || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (alreadyAssigned.length == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const otherCamper = this.getCamperById(alreadyAssigned[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!otherCamper) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!doesConflictExist(otherCamper, [camper.id])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this.schedule.buddies[staffer.id].push(camper.id); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assigned = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return assigned; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| getSchedule() { return this.schedule; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.