diff --git a/apps/nextjs/src/app/dashboard/Assignments.tsx b/apps/nextjs/src/app/dashboard/Assignments.tsx index fb7a7f2..daedf3d 100644 --- a/apps/nextjs/src/app/dashboard/Assignments.tsx +++ b/apps/nextjs/src/app/dashboard/Assignments.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { Metadata } from "next"; import Image from "next/image"; import { Button } from "@/components/ui/button"; @@ -19,6 +19,7 @@ import { import { ScrollArea } from "@/components/ui/scroll-area"; import { Separator } from "@/components/ui/separator"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import { assignTasks } from "@/lib/utils/autoassign"; import { DndContext, DragOverlay, useDroppable } from "@dnd-kit/core"; import { AssignmentCard, MemberCard } from "./components/cards"; @@ -33,7 +34,19 @@ import { UserNav } from "./components/user-nav"; const tags = Array.from({ length: 50 }).map( (_, i, a) => `v1.2.0-beta.${a.length - i}`, ); - +function autoAssign( + assignments: string[], + members: { [key: string]: string[] }, + setMembers: (members: { [key: string]: string[] }) => void, + setAssignments: (assignments: string[]) => void, +) { + // useEffect(() => { + const autoassign = assignTasks(assignments, Object.keys(members)); + console.log(autoassign, typeof autoassign); + setMembers(autoassign); + setAssignments([]); + // }, []); +} export default function Assignments() { // XXX: Use real data via tRPC const [members, setMembers] = useState<{ [key: string]: string[] }>( @@ -137,6 +150,13 @@ export default function Assignments() { */} + ); } diff --git a/apps/nextjs/src/app/dashboard/page.tsx b/apps/nextjs/src/app/dashboard/page.tsx index eb72f4c..4272733 100644 --- a/apps/nextjs/src/app/dashboard/page.tsx +++ b/apps/nextjs/src/app/dashboard/page.tsx @@ -17,7 +17,7 @@ import { ScrollArea } from "@/components/ui/scroll-area"; import { Separator } from "@/components/ui/separator"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; -import Assignments from "./Assignments"; +import Assignments, { autoassign } from "./Assignments"; import { CalendarDateRangePicker } from "./components/date-range-picker"; import { MainNav } from "./components/main-nav"; import { Overview } from "./components/overview"; diff --git a/apps/nextjs/src/app/matches/page.tsx b/apps/nextjs/src/app/matches/page.tsx new file mode 100644 index 0000000..7ab86c8 --- /dev/null +++ b/apps/nextjs/src/app/matches/page.tsx @@ -0,0 +1,19 @@ +import React from "react"; +import { createTRPCClient } from "@trpc/client"; +import { httpBatchLink } from "@trpc/client/links/httpBatchLink"; +import { createTRPCReact } from "@trpc/react-query"; + +import type { AppRouter } from "@acme/api"; + +const api = createTRPCReact(); + +export default async function getTeamEvents(teamKey: string, year: number) { + const teamEvents = await api.tba.teamEvents.useQuery({ + teamKey, + year, + }); + console.log(teamEvents); + return teamEvents; +} + +console.log("HAAAAAAA: ", getTeamEvents("frc254", 2023)); diff --git a/apps/nextjs/src/lib/utils/autoassign.js b/apps/nextjs/src/lib/utils/autoassign.js new file mode 100644 index 0000000..edd962d --- /dev/null +++ b/apps/nextjs/src/lib/utils/autoassign.js @@ -0,0 +1,49 @@ +export function assignTasks(times, users) { + // Sort the times for ordered assignment + const sortedTimes = times.sort(); + + // Initialize assignments, lastAssigned, and taskCount objects + const assignments = {}; + const lastAssigned = {}; + const taskCount = {}; + // biome-ignore lint/complexity/noForEach: +users.forEach(user => { + assignments[user] = []; + lastAssigned[user] = null; + taskCount[user] = 0; + }); + + for (const time of sortedTimes) { + // Find the user with the least tasks and no concurrent task (if possible) + let bestUser = null; + for (const user of users) { + if (!lastAssigned[user] || lastAssigned[user] !== time) { + bestUser = bestUser || user; // Assign the first available user + if (taskCount[user] < taskCount[bestUser]) { + bestUser = user; // Update if a user with fewer tasks is found + } + } + } + + // Assign the task to the best user or the first available user + if (bestUser) { + assignments[bestUser].push(time); + lastAssigned[bestUser] = time; + taskCount[bestUser]++; + } else { + console.warn("No user available for time:", time); // Log a warning if no user is available + } + } + + return assignments; + } + + // // Example usage: + // const times = ['10:00', '10:30', '11:00', '11:30'].reduce((acc, time) => acc.concat(Array(6).fill(time)), []); + // const users = ['Bryan', 'has', 'no', 'girls', 'also', 'the', 'scouting', 'app', 'works','on','his','computer']; + + // const assignments = assignTasks(times, users); + // for (const user in assignments) { + // console.log(`${user}: ${assignments[user]}`); + // } + \ No newline at end of file