Skip to content

Commit

Permalink
Implemented basic schedule init
Browse files Browse the repository at this point in the history
  • Loading branch information
fwestling committed Jan 2, 2024
1 parent 191b9c7 commit 5abfb0b
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 8 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ yarn add latitude-scheduler
pnpm i --save latitude-scheduler
```

##

## Development

Developing inside this repo is reasonably straightforward; the source code is in the `src` directory, tests are conducted using Jest, and we build the code using TSUP.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"luxon": "^3.4.4"
"luxon": "^3.4.4",
"uuid": "^9.0.1"
}
}
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions src/presets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Activity from "./v8/activity";
import { TournamentConfig, TournamentOptions } from "./v8/tournament";
import { TournamentConfig, TournamentOptions } from "./v8/config";
import initAusFLL from "./v8/initialise/ausFLL";
import Tournament from "./v8/tournament";

export const presets = ["AUS FLL"] as const;
export const presets = ["ausFLL"] as const;

export type Preset = (typeof presets)[number];

Expand All @@ -11,9 +13,16 @@ type PresetReturn = {
options: TournamentOptions;
};

export const initialise = (tournament: Tournament, preset: Preset) => {
switch (preset) {
case "ausFLL":
return initAusFLL(tournament);
}
};

export const getPreset = (preset: Preset): PresetReturn => {
switch (preset) {
case "AUS FLL":
case "ausFLL":
return getPresetAUSFLL();
}
};
Expand Down
3 changes: 3 additions & 0 deletions src/utilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { v4 as guid } from "uuid";

export const generateId = () => guid();
46 changes: 45 additions & 1 deletion src/v8/activity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
import { generateId } from "../utilities";

/**
* Activity type for scheduling; options are:
* - all: all teams are scheduled at once
* - single: each team will get a single run at this activity
* - multiple: each team will get multiple runs at this activity
*/
export type ActivityType = "all" | "single" | "multiple";

/**
* A single type of tournament activity.
* e.g. Judging session, Lunch break, Robot Round 1
*/
export default class Activity {}
export default class Activity {
id: string;
type: ActivityType;
name: string;
/**
* How long (in minutes) is one session of this activity?
* Specifically, how long is the team at the location
*/
duration: number;
/**
* How long (in minutes) does it take to clean up after this activity?
* Specifically, how long after a team is done can the next team start?
*/
cleanup: number;
/** When does the activity start? In minutes from midnight on the first tournament day */
start: number;

/** Names of each location */
locations: string[];
constructor(
name: string,
type: ActivityType,
start: number,
duration: number,
cleanup: number
) {
this.id = generateId();
this.name = name;
this.type = type;
this.duration = duration;
this.cleanup = cleanup;
this.start = start;
this.locations = [];
}
}
40 changes: 40 additions & 0 deletions src/v8/initialise/ausFLL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Activity from "../activity";
import Tournament from "../tournament";

const initAusFLL = (tournament: Tournament) => {
let time = tournament.config.startTime;
const numTeams = tournament.teams.length;
const numTables = 4;

tournament.activities.push(
new Activity("Opening Ceremony", "all", time, 30, 0)
);
tournament.activities.push(new Activity("Lunch", "all", 12 * 60, 30, 0));
tournament.activities.push(
new Activity(
"Closing Ceremony",
"all",
tournament.config.endTime - 30,
30,
0
)
);
const availableTime =
tournament.config.endTime - tournament.config.startTime - 60 - 30;
const matchesPerRound = Math.ceil(numTeams / 2);
const timeForRound = Math.ceil(availableTime / 3);
const matchLength = Math.ceil(timeForRound / matchesPerRound);
const matchDuration = Math.max(Math.ceil(matchLength / 2), 4);
const matchCleanup = matchLength - matchDuration;
time += 30;
tournament.activities.push(new Activity("Judging", "single", time, 45, 0));
tournament.activities.push(
new Activity("Round 1", "single", time, matchDuration, matchCleanup)
);
time += matchLength * matchesPerRound;
tournament.activities.push(new Activity("Round 2", "single", time, 4, 2));
time += matchLength * matchesPerRound;
tournament.activities.push(new Activity("Round 3", "single", time, 4, 2));
};

export default initAusFLL;
2 changes: 1 addition & 1 deletion src/v8/tournament.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class Tournament {
name = "Tournament",
numberOfDays,
numberOfTeams = 24,
preset = "AUS FLL",
preset = "ausFLL",
}: TournamentInitialProps) {
this.name = name;
this.teams = new Array(numberOfTeams)
Expand Down

0 comments on commit 5abfb0b

Please sign in to comment.