Skip to content

Commit

Permalink
Rename assignmentStrategy to assignmentAlgorithm (#1034)
Browse files Browse the repository at this point in the history
* Rename assignmentStrategy to assignmentAlgorithm

* More renaming

* More renaming
  • Loading branch information
Archinowsk authored Aug 25, 2024
1 parent 49060b1 commit aab739d
Show file tree
Hide file tree
Showing 26 changed files with 142 additions and 134 deletions.
2 changes: 1 addition & 1 deletion client/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ export const translationEN = {
sentryTesting: "Sentry testing",
sentryClientTest: "Client test",
sentryBackendTest: "Backend test",
strategy: "Strategy",
signupStrategy: "Signup strategy",
loginProvider: "Login provider",
},
} as const;
2 changes: 1 addition & 1 deletion client/src/locales/fi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ export const translationFI = {
sentryTesting: "Sentryn testaus",
sentryClientTest: "Client-testi",
sentryBackendTest: "Backend-testi",
strategy: "Strategia",
signupStrategy: "Ilmoittautumisstapa",
loginProvider: "Kirjautumistapa",
},
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const SignupStrategySelector = (): ReactElement => {

return (
<div>
<span>{t("admin.strategy")}</span>{" "}
<span>{t("admin.signupStrategy")}</span>{" "}
<Dropdown
options={strategies}
selectedValue={signupStrategy as string}
Expand Down
2 changes: 1 addition & 1 deletion server/src/features/assignment/assignmentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const storeAssignment = async (
startTime: string,
): Promise<PostAssignmentResponse | ApiError> => {
const assignResultsResult = await runAssignment({
assignmentStrategy: config.event().assignmentStrategy,
assignmentAlgorithm: config.event().assignmentAlgorithm,
startTime,
});

Expand Down
8 changes: 4 additions & 4 deletions server/src/features/assignment/padg/padgAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
unwrapResult,
} from "shared/utils/result";
import { AssignmentError } from "shared/types/api/errors";
import { AssignmentStrategy } from "shared/config/eventConfigTypes";
import { AssignmentAlgorithm } from "shared/config/eventConfigTypes";

export const padgAssignment = (
users: readonly User[],
Expand All @@ -33,7 +33,7 @@ export const padgAssignment = (
return makeSuccessResult({
results: [],
message: "Padg Assignment Result - No starting program items",
algorithm: AssignmentStrategy.PADG,
algorithm: AssignmentAlgorithm.PADG,
status: AssignmentResultStatus.NO_STARTING_PROGRAM_ITEMS,
});
}
Expand All @@ -50,7 +50,7 @@ export const padgAssignment = (
return makeSuccessResult({
results: [],
message: "Padg Assignment Result - No lottery signups",
algorithm: AssignmentStrategy.PADG,
algorithm: AssignmentAlgorithm.PADG,
status: AssignmentResultStatus.NO_LOTTERY_SIGNUPS,
});
}
Expand Down Expand Up @@ -95,7 +95,7 @@ export const padgAssignment = (
Object.assign({
...assignmentResult,
message,
algorithm: AssignmentStrategy.PADG,
algorithm: AssignmentAlgorithm.PADG,
status: AssignmentResultStatus.SUCCESS,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getGroups } from "server/features/assignment/utils/getGroups";
import { getList } from "server/features/assignment/utils/getList";
import { getEvents } from "server/features/assignment/utils/getEvents";
import { formatResults } from "server/features/assignment/utils/formatResults";
import { AssignmentStrategyResult, Input } from "server/types/resultTypes";
import { AssignmentAlgorithmResult, Input } from "server/types/resultTypes";
import { ProgramItem } from "shared/types/models/programItem";
import { User } from "shared/types/models/user";
import { DirectSignupsForProgramItem } from "server/features/direct-signup/directSignupTypes";
Expand All @@ -22,7 +22,7 @@ export const runPadgAssignment = (
attendeeGroups: readonly User[][],
startTime: string,
directSignups: readonly DirectSignupsForProgramItem[],
): Result<AssignmentStrategyResult, AssignmentError> => {
): Result<AssignmentAlgorithmResult, AssignmentError> => {
const groupsResult = getGroups(attendeeGroups, startTime);
if (isErrorResult(groupsResult)) {
return groupsResult;
Expand Down
8 changes: 4 additions & 4 deletions server/src/features/assignment/random/randomAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
unwrapResult,
} from "shared/utils/result";
import { AssignmentError } from "shared/types/api/errors";
import { AssignmentStrategy } from "shared/config/eventConfigTypes";
import { AssignmentAlgorithm } from "shared/config/eventConfigTypes";

export const randomAssignment = (
users: readonly User[],
Expand All @@ -33,7 +33,7 @@ export const randomAssignment = (
return makeSuccessResult({
results: [],
message: "Random Assignment Result - No starting program items",
algorithm: AssignmentStrategy.RANDOM,
algorithm: AssignmentAlgorithm.RANDOM,
status: AssignmentResultStatus.NO_STARTING_PROGRAM_ITEMS,
});
}
Expand All @@ -50,7 +50,7 @@ export const randomAssignment = (
return makeSuccessResult({
results: [],
message: "Random Assignment Result - No lottery signups",
algorithm: AssignmentStrategy.RANDOM,
algorithm: AssignmentAlgorithm.RANDOM,
status: AssignmentResultStatus.NO_LOTTERY_SIGNUPS,
});
}
Expand Down Expand Up @@ -94,7 +94,7 @@ export const randomAssignment = (
Object.assign({
...assignmentResult,
message,
algorithm: AssignmentStrategy.RANDOM,
algorithm: AssignmentAlgorithm.RANDOM,
status: AssignmentResultStatus.SUCCESS,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getList } from "server/features/assignment/utils/getList";
import { getRandomAssignEvents } from "server/features/assignment/random/utils/getRandomAssignEvents";
import { formatResults } from "server/features/assignment/utils/formatResults";
import { ProgramItem } from "shared/types/models/programItem";
import { AssignmentStrategyResult } from "server/types/resultTypes";
import { AssignmentAlgorithmResult } from "server/types/resultTypes";
import {
ListItem,
RandomAssignUpdateLInput,
Expand All @@ -29,7 +29,7 @@ export const runRandomAssignment = (
attendeeGroups: readonly User[][],
startTime: string,
directSignups: readonly DirectSignupsForProgramItem[],
): Result<AssignmentStrategyResult, AssignmentError> => {
): Result<AssignmentAlgorithmResult, AssignmentError> => {
const groupsResult = getGroups(attendeeGroups, startTime);
if (isErrorResult(groupsResult)) {
return groupsResult;
Expand Down
40 changes: 20 additions & 20 deletions server/src/features/assignment/runAssignment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dayjs from "dayjs";
import { faker } from "@faker-js/faker";
import { runAssignment } from "server/features/assignment/runAssignment";
import { generateTestData } from "server/test/test-data-generation/generators/generateTestData";
import { AssignmentStrategy } from "shared/config/eventConfigTypes";
import { AssignmentAlgorithm } from "shared/config/eventConfigTypes";
import { config } from "shared/config";
import { saveUser } from "server/features/user/userRepository";
import { saveProgramItems } from "server/features/program-item/programItemRepository";
Expand Down Expand Up @@ -66,14 +66,14 @@ describe("Assignment with valid data", () => {

test("should return valid results after multiple executions on different times", async () => {
const { eventStartTime } = config.event();
const assignmentStrategy = AssignmentStrategy.PADG;
const assignmentAlgorithm = AssignmentAlgorithm.PADG;
const startTime = dayjs(eventStartTime).add(2, "hours").toISOString();

// FIRST RUN

const assignResults = unsafelyUnwrap(
await runAssignment({
assignmentStrategy,
assignmentAlgorithm,
startTime,
}),
);
Expand Down Expand Up @@ -101,7 +101,7 @@ describe("Assignment with valid data", () => {
const startTime2 = dayjs(eventStartTime).add(3, "hours").toISOString();

const assignResults2Result = await runAssignment({
assignmentStrategy,
assignmentAlgorithm,
startTime: startTime2,
});
expect(assignResults2Result.error).toBeUndefined();
Expand Down Expand Up @@ -131,7 +131,7 @@ describe("Assignment with valid data", () => {

describe("Assignment with multiple program types and directSignupAlwaysOpen", () => {
test("should not remove signups of non-'twoPhaseSignupProgramTypes' program types", async () => {
const assignmentStrategy = AssignmentStrategy.RANDOM_PADG;
const assignmentAlgorithm = AssignmentAlgorithm.RANDOM_PADG;

// Populate database
await saveProgramItems([
Expand Down Expand Up @@ -191,7 +191,7 @@ describe("Assignment with multiple program types and directSignupAlwaysOpen", ()

const assignResults = unsafelyUnwrap(
await runAssignment({
assignmentStrategy,
assignmentAlgorithm,
startTime: testProgramItem.startTime,
}),
);
Expand All @@ -217,7 +217,7 @@ describe("Assignment with multiple program types and directSignupAlwaysOpen", ()
test("should not remove directSignupAlwaysOpen signups if user doesn't have updated result", async () => {
const directSignupAlwaysOpenId =
config.event().directSignupAlwaysOpenIds[0];
const assignmentStrategy = AssignmentStrategy.RANDOM_PADG;
const assignmentAlgorithm = AssignmentAlgorithm.RANDOM_PADG;

// Populate database
await saveProgramItems([
Expand Down Expand Up @@ -266,7 +266,7 @@ describe("Assignment with multiple program types and directSignupAlwaysOpen", ()

const assignResults = unsafelyUnwrap(
await runAssignment({
assignmentStrategy,
assignmentAlgorithm,
startTime: testProgramItem.startTime,
}),
);
Expand Down Expand Up @@ -300,7 +300,7 @@ describe("Assignment with multiple program types and directSignupAlwaysOpen", ()
test("should not remove previous signup from moved program item if user doesn't have updated result", async () => {
// User1, programItem1: 14:00 direct signup -> program item moved 15:00
// User2, programItem2: 15:00 lottery signup -> doesn't affect user1 signup
const assignmentStrategy = AssignmentStrategy.RANDOM_PADG;
const assignmentAlgorithm = AssignmentAlgorithm.RANDOM_PADG;

const assignmentTime = dayjs(testProgramItem.startTime)
.add(1, "hours")
Expand Down Expand Up @@ -341,7 +341,7 @@ describe("Assignment with multiple program types and directSignupAlwaysOpen", ()

const assignResults = unsafelyUnwrap(
await runAssignment({
assignmentStrategy,
assignmentAlgorithm,
startTime: assignmentTime,
}),
);
Expand Down Expand Up @@ -377,7 +377,7 @@ describe("Assignment with multiple program types and directSignupAlwaysOpen", ()
test("should update directSignupAlwaysOpen signup with assignment signup if user has updated result", async () => {
const directSignupAlwaysOpenId =
config.event().directSignupAlwaysOpenIds[0];
const assignmentStrategy = AssignmentStrategy.RANDOM_PADG;
const assignmentAlgorithm = AssignmentAlgorithm.RANDOM_PADG;

// Populate database
await saveProgramItems([
Expand Down Expand Up @@ -439,7 +439,7 @@ describe("Assignment with multiple program types and directSignupAlwaysOpen", ()

const assignResults = unsafelyUnwrap(
await runAssignment({
assignmentStrategy,
assignmentAlgorithm,
startTime: testProgramItem.startTime,
}),
);
Expand Down Expand Up @@ -469,7 +469,7 @@ describe("Assignment with multiple program types and directSignupAlwaysOpen", ()
test("should update previous signup from moved program item with assignment signup if user has updated result", async () => {
// ProgramItem1: 14:00 direct signup -> program item moved 15:00
// ProgramItem2: 15:00 lottery signup -> replaces ProgramItem1
const assignmentStrategy = AssignmentStrategy.RANDOM_PADG;
const assignmentAlgorithm = AssignmentAlgorithm.RANDOM_PADG;

const assignmentTime = dayjs(testProgramItem.startTime)
.add(1, "hours")
Expand Down Expand Up @@ -512,7 +512,7 @@ describe("Assignment with multiple program types and directSignupAlwaysOpen", ()

const assignResults = unsafelyUnwrap(
await runAssignment({
assignmentStrategy,
assignmentAlgorithm,
startTime: assignmentTime,
}),
);
Expand Down Expand Up @@ -550,7 +550,7 @@ describe("Assignment with multiple program types and directSignupAlwaysOpen", ()

// ProgramItem1: 14:00 direct signup LARP
// ProgramItem2: 14:00 lottery signup TABLETOP_RPG -> replaces ProgramItem1
const assignmentStrategy = AssignmentStrategy.RANDOM_PADG;
const assignmentAlgorithm = AssignmentAlgorithm.RANDOM_PADG;
const assignmentTime = testProgramItem.startTime;

await saveProgramItems([
Expand Down Expand Up @@ -588,7 +588,7 @@ describe("Assignment with multiple program types and directSignupAlwaysOpen", ()

const assignResults = unsafelyUnwrap(
await runAssignment({
assignmentStrategy,
assignmentAlgorithm,
startTime: assignmentTime,
}),
);
Expand Down Expand Up @@ -621,7 +621,7 @@ describe("Assignment with first time bonus", () => {
test("should assign user without previous 'twoPhaseSignupProgramTypes' signup", async () => {
const directSignupAlwaysOpenId =
config.event().directSignupAlwaysOpenIds[0];
const assignmentStrategy = AssignmentStrategy.RANDOM_PADG;
const assignmentAlgorithm = AssignmentAlgorithm.RANDOM_PADG;
const tournamentProgramItemId = "AIAHHUA";

// Populate database
Expand Down Expand Up @@ -689,7 +689,7 @@ describe("Assignment with first time bonus", () => {

const assignResults = unsafelyUnwrap(
await runAssignment({
assignmentStrategy,
assignmentAlgorithm,
startTime: testProgramItem.startTime,
}),
);
Expand Down Expand Up @@ -743,7 +743,7 @@ describe("Assignment with first time bonus", () => {
});

test("should assign user with previous failed lottery signup", async () => {
const assignmentStrategy = AssignmentStrategy.RANDOM_PADG;
const assignmentAlgorithm = AssignmentAlgorithm.RANDOM_PADG;

// Populate database
await saveProgramItems([
Expand Down Expand Up @@ -777,7 +777,7 @@ describe("Assignment with first time bonus", () => {

const assignResults = unsafelyUnwrap(
await runAssignment({
assignmentStrategy,
assignmentAlgorithm,
startTime: testProgramItem2.startTime,
}),
);
Expand Down
12 changes: 6 additions & 6 deletions server/src/features/assignment/runAssignment.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { logger } from "server/utils/logger";
import { runAssignmentStrategy } from "server/features/assignment/utils/runAssignmentStrategy";
import { runAssignmentAlgorithm } from "server/features/assignment/utils/runAssignmentAlgorithm";
import { removeInvalidProgramItemsFromUsers } from "server/features/assignment/utils/removeInvalidProgramItemsFromUsers";
import { AssignmentResult } from "server/types/resultTypes";
import { findUsers } from "server/features/user/userRepository";
import { findProgramItems } from "server/features/program-item/programItemRepository";
import { AssignmentStrategy } from "shared/config/eventConfigTypes";
import { AssignmentAlgorithm } from "shared/config/eventConfigTypes";
import { config } from "shared/config";
import { removeOverlapSignups } from "server/features/assignment/utils/removeOverlapSignups";
import { saveResults } from "server/features/assignment/utils/saveResults";
Expand All @@ -21,14 +21,14 @@ import {
import { AssignmentError, MongoDbError } from "shared/types/api/errors";

interface RunAssignmentParams {
assignmentStrategy: AssignmentStrategy;
assignmentAlgorithm: AssignmentAlgorithm;
startTime?: string;
useDynamicStartTime?: boolean;
assignmentDelay?: number;
}

export const runAssignment = async ({
assignmentStrategy,
assignmentAlgorithm,
startTime,
useDynamicStartTime = false,
assignmentDelay = 0,
Expand Down Expand Up @@ -103,8 +103,8 @@ export const runAssignment = async ({
}
const directSignups = unwrapResult(directSignupsResult);

const assignResultsResult = runAssignmentStrategy(
assignmentStrategy,
const assignResultsResult = runAssignmentAlgorithm(
assignmentAlgorithm,
validLotterySignupsUsers,
validLotterySignupProgramItems,
assignmentTime,
Expand Down
Loading

0 comments on commit aab739d

Please sign in to comment.