From 7ef62f1e69f5eb7ef3f95b81ddb4efd86b0581aa Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 31 Dec 2023 14:32:56 +0100 Subject: [PATCH 1/5] Updated configs. --- results.json => benchmark/results.json | 0 benchmark/timeDistribution.ts | 2 +- jest.config.js | 10 ---------- jest.config.ts | 13 +++++++++++++ serverConfig.json | 6 ------ src/routes/{isOnline.ts => base.ts} | 0 src/server.ts | 12 ++++++------ src/startup/testing.ts | 4 ++++ tsconfig.json | 2 +- 9 files changed, 25 insertions(+), 24 deletions(-) rename results.json => benchmark/results.json (100%) delete mode 100644 jest.config.js create mode 100644 jest.config.ts delete mode 100644 serverConfig.json rename src/routes/{isOnline.ts => base.ts} (100%) create mode 100644 src/startup/testing.ts diff --git a/results.json b/benchmark/results.json similarity index 100% rename from results.json rename to benchmark/results.json diff --git a/benchmark/timeDistribution.ts b/benchmark/timeDistribution.ts index caa65a4..f870a7e 100644 --- a/benchmark/timeDistribution.ts +++ b/benchmark/timeDistribution.ts @@ -59,7 +59,7 @@ const benchmarkResults: BenchmarkResults = { middleValue, timestamp: new Date().toISOString(), }; -const resultsFilePath: string = 'results.json'; +const resultsFilePath: string = 'benchmark/results.json'; let existingResultsArray: BenchmarkResults[] = []; if (fs.existsSync(resultsFilePath)) { diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index aad4823..0000000 --- a/jest.config.js +++ /dev/null @@ -1,10 +0,0 @@ -// eslint-disable-next-line no-undef -module.exports = { - transform: { - '^.+\\.(ts)$': ['ts-jest', { tsconfig: 'tsconfig.json' }], - }, - moduleFileExtensions: ['ts', 'js'], - testMatch: ['**/test/**/*.test.(ts|js)'], - testEnvironment: 'node', - maxWorkers: 1, -}; diff --git a/jest.config.ts b/jest.config.ts new file mode 100644 index 0000000..ca894e4 --- /dev/null +++ b/jest.config.ts @@ -0,0 +1,13 @@ +import type { Config } from '@jest/types'; + +const config: Config.InitialOptions = { + preset: 'ts-jest', + testEnvironment: 'node', + moduleFileExtensions: ['ts', 'js'], + testMatch: ['**/test/**/*.test.(ts|js)'], + transform: { + '^.+\\.(ts)$': 'ts-jest', + }, +}; + +export default config; diff --git a/serverConfig.json b/serverConfig.json deleted file mode 100644 index 09bb660..0000000 --- a/serverConfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "frontend-Url": "", - "server-Url": "", - "mongoDb": "server" - -} \ No newline at end of file diff --git a/src/routes/isOnline.ts b/src/routes/base.ts similarity index 100% rename from src/routes/isOnline.ts rename to src/routes/base.ts diff --git a/src/server.ts b/src/server.ts index 80fb6eb..9787f2a 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,27 +1,27 @@ import express, { Express } from 'express'; import { configureCors } from './startup/cors'; -import isOnline from './routes/isOnline'; +import base from './routes/base'; import project from './routes/project'; import connectToDatabase from './startup/db'; -import config from './startup/config'; import addRateLimiter from './startup/limitRate'; import * as dotenv from 'dotenv'; import logger from './utils/logger'; +import { testingConfig } from './startup/testing'; dotenv.config(); const app: Express = express(); // startup -config(); configureCors(app); -connectToDatabase(); addRateLimiter(app); +connectToDatabase(); +testingConfig(); app.use(express.json()); -app.use('/', isOnline); +app.use('/', base); app.use('/project', project); -const port: number = process.env.PORT ? parseInt(process.env.PORT) : 3000; +const port: number = process.env.PORT ? parseInt(process.env.PORT) : 0; const server = app.listen(port, '0.0.0.0', () => { logger.info('Server started on port: ' + port); }); diff --git a/src/startup/testing.ts b/src/startup/testing.ts new file mode 100644 index 0000000..e63819c --- /dev/null +++ b/src/startup/testing.ts @@ -0,0 +1,4 @@ +export function testingConfig() { + if (process.env.NODE_ENV !== 'test') return; + process.env.PORT = '0'; +} diff --git a/tsconfig.json b/tsconfig.json index 6290c74..1f50f8f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,5 +8,5 @@ "outDir": "dist", "baseUrl": "*" }, - "include": ["**/**/*", "*", "jest.config.js"] + "include": ["**/**/*", "*", "jest.config.ts"] } From 693c9133e9f6e968760dcbd93b3471f9c06bc06b Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 14 Jul 2024 12:54:19 +0200 Subject: [PATCH 2/5] Renamed data properties. --- .vscode/launch.json | 2 +- src/alg/StudentDistribution.ts | 61 +++++------------ .../AllocateGroupsToItems.ts | 6 +- src/alg/StudentDistribution/CreateGraph.ts | 2 +- src/alg/StudentDistribution/FindPaths.ts | 12 ++-- src/alg/StudentDistribution/Utils.ts | 66 ++++++++++++++++++- src/data/Items.ts | 48 +++++++------- src/data/Projects.ts | 6 +- src/models/project.ts | 12 ++-- src/routes/project.ts | 2 +- src/types/Item.ts | 4 +- src/types/Path_config.ts | 4 +- src/types/Polls.ts | 1 + src/types/Project.ts | 6 +- test/alg/data.ts | 57 ++++++++-------- test/alg/failData.ts | 54 +++++++-------- test/alg/studentDistribution.test.ts | 14 ++-- 17 files changed, 193 insertions(+), 164 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4f943f5..b085c49 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,7 @@ "type": "node", "request": "launch", "name": "Debug TypeScript", - "program": "${workspaceFolder}/src/index.ts", + "program": "${workspaceFolder}/src/alg/test.ts", "preLaunchTask": "tsc: build - tsconfig.json", "outFiles": ["${workspaceFolder}/dist/**/*.js"], "sourceMaps": true diff --git a/src/alg/StudentDistribution.ts b/src/alg/StudentDistribution.ts index 259fd0f..8976c63 100644 --- a/src/alg/StudentDistribution.ts +++ b/src/alg/StudentDistribution.ts @@ -1,49 +1,22 @@ -import { Group, Groups } from '../Class/Groups'; +// tyoes import PollQuestion from '../types/Polls'; - import Student from '../types/Student'; +import Item from '../types/Item'; +import Project from '../types/Project'; +// algorithmen stages import createGraph from './StudentDistribution/CreateGraph'; import { distributeStudentsToPaths } from './StudentDistribution/DistributeStudents'; import { findPathsForTheGroups } from './StudentDistribution/FindPaths'; -import { getVotingIds } from './StudentDistribution/Utils'; import { allocateGroupsToItems } from './StudentDistribution/AllocateGroupsToItems'; -import Item from '../types/Item'; -import Project from '../types/Project'; -import Room from '../types/Room'; -import { rooms } from '../data/Rooms'; - -function buildGroupsByPaths( - polls: PollQuestion[], - students: Student[], - project: Project -): Group[] { - const groups = new Groups(); - students.forEach((student) => { - groups.add(getVotingIds(student._id, polls), student._id); - }); - if (groups.size() == 0) { - project.failed = true; - project.reasonForFailing = 'Zero Possilbe Groups'; - } - return groups.getAll(); -} - -function validating( - project: Project, - items: Item[], - students: Student[], - rooms: Room[] -): boolean { - if (items.length > 0 && students.length > 0 && rooms.length > 0) { - return true; - } else { - project.failed = true; - project.reasonForFailing = `StudentsAmount: ${students.length}}; RoomsAmount: ${rooms.length}; ItemsAmount: ${items.length}`; - return false; - } -} +//data and utils +import { rooms } from '../data/Rooms'; +import { + buildGroupsByPaths, + getVotingIds, + validating, +} from './StudentDistribution/Utils'; function main( items: Item[], @@ -53,27 +26,27 @@ function main( ): boolean { project.status = 'Validating'; validating(project, items, students, rooms); - if (project.failed) return false; + if (project.failedCalculating) return false; project.status = 'CreateGroups'; const groups = buildGroupsByPaths(polls, students, project); - if (project.failed) return false; + if (project.failedCalculating) return false; project.status = 'CreateGraph'; const g = createGraph(items, project); - if (project.failed) return false; + if (project.failedCalculating) return false; project.status = 'FindPaths'; findPathsForTheGroups(groups, items, g, project); - if (project.failed) return false; + if (project.failedCalculating) return false; project.status = 'Distributing'; distributeStudentsToPaths(items, groups, project); - if (project.failed) return false; + if (project.failedCalculating) return false; project.status = 'Allocating'; allocateGroupsToItems(items, groups, project); - if (project.failed) return false; + if (project.failedCalculating) return false; project.status = 'FinishedCalc'; return true; diff --git a/src/alg/StudentDistribution/AllocateGroupsToItems.ts b/src/alg/StudentDistribution/AllocateGroupsToItems.ts index 6743db2..a795f98 100644 --- a/src/alg/StudentDistribution/AllocateGroupsToItems.ts +++ b/src/alg/StudentDistribution/AllocateGroupsToItems.ts @@ -12,9 +12,9 @@ function allocateGroupsToItems( groups.forEach((group) => { const rooms = findRoommatesInGroup(group, project); group.paths.forEach((path_config) => { - if (path_config.valueForTestingStudentDistribution !== 0) { + if (path_config.testValueForDistributingStudents !== 0) { let studentsCount = - path_config.valueForTestingStudentDistribution; + path_config.testValueForDistributingStudents; while (studentsCount > 0) { let room = rooms.shift(); @@ -25,7 +25,7 @@ function allocateGroupsToItems( rooms.push(secondPart); } - allocateToItems(path_config.path, items, room); + allocateToItems(path_config.itemsInPath, items, room); studentsCount -= room.length; } } diff --git a/src/alg/StudentDistribution/CreateGraph.ts b/src/alg/StudentDistribution/CreateGraph.ts index 8cb8e5b..76475db 100644 --- a/src/alg/StudentDistribution/CreateGraph.ts +++ b/src/alg/StudentDistribution/CreateGraph.ts @@ -23,7 +23,7 @@ function createGraph(items: Item[], project: Project): DirectedGraph { }); }); if (G.sizeEdges() === 0) { - project.failed = true; + project.failedCalculating = true; project.reasonForFailing = 'Graph build failed: ZeroEdges'; } return G; diff --git a/src/alg/StudentDistribution/FindPaths.ts b/src/alg/StudentDistribution/FindPaths.ts index a58c451..9d4d30b 100644 --- a/src/alg/StudentDistribution/FindPaths.ts +++ b/src/alg/StudentDistribution/FindPaths.ts @@ -2,14 +2,14 @@ import { DirectedGraph, GraphNode } from '../../Class/Graph'; import { Group } from '../../Class/Groups'; import Item from '../../types/Item'; import Project from '../../types/Project'; -import { getDefaultIds } from './Utils'; +import { getRequiredGroupIds } from './Utils'; function findPathsForTheGroups( groups: Group[], items: Item[], g: DirectedGraph, project: Project, - requiredIds: Set = new Set(getDefaultIds(project)) + requiredIds: Set = new Set(getRequiredGroupIds(project)) ) { const entries = g.getNodesWithIndegreeZero(); groups.forEach((group) => { @@ -19,7 +19,7 @@ function findPathsForTheGroups( dfs(entry, ids, [], group.requiredEvents, group, items); }); if (group.paths.length == 0) { - project.failed = true; + project.failedCalculating = true; project.reasonForFailing = 'Zero paths for Group Found'; } }); @@ -44,8 +44,8 @@ function dfs( if (remainingIds.size === 0) { group.paths.push({ - path: newPath, - valueForTestingStudentDistribution: 0, + itemsInPath: newPath, + testValueForDistributingStudents: 0, }); } else if (node.edges !== null) { node.edges.forEach((edge) => @@ -57,7 +57,7 @@ function dfs( } function getMaxAvailableCapacity(path: Item[]): number { - return Math.min(...path.map((item) => item.groupCapazity)); + return Math.min(...path.map((item) => item.studentCapacity)); } export { findPathsForTheGroups, getMaxAvailableCapacity }; diff --git a/src/alg/StudentDistribution/Utils.ts b/src/alg/StudentDistribution/Utils.ts index 7eb4a6a..c143afc 100644 --- a/src/alg/StudentDistribution/Utils.ts +++ b/src/alg/StudentDistribution/Utils.ts @@ -1,10 +1,14 @@ +import { Group } from '../../Class/Groups'; import Item from '../../types/Item'; import PollQuestion from '../../types/Polls'; import Project from '../../types/Project'; +import Room from '../../types/Room'; +import Student from '../../types/Student'; +import { arraysHaveSameValues } from '../../utils/array'; const EXTRA_IDS_CACHE = new Map(); -function getDefaultIds(project: Project): string[] { - return project.idsThatAreRequiredForEveryone; +function getRequiredGroupIds(project: Project): string[] { + return project.requiredEventGroupsAsIds; } function getVotingIds(studentId: string, polls: PollQuestion[]): string[] { @@ -37,5 +41,61 @@ function getVotingIds(studentId: string, polls: PollQuestion[]): string[] { function findItemsByStudentId(studentId: string, items: Item[]): Item[] { return items.filter((item) => item.studentIds.includes(studentId)); } +function buildGroupsByPaths( + polls: PollQuestion[], + students: Student[], + project: Project +): Group[] { + const groups: Group[] = []; + students.forEach((student) => { + // if a group exists => add the student else create a group -export { getDefaultIds, getVotingIds, findItemsByStudentId }; + const itemPath = getVotingIds(student._id, polls); + const group = findGroup(itemPath); + if (group) group.studentIds.push(student._id); + else + groups.push({ + _id: groups.length + 1, + paths: [], + requiredEvents: itemPath, + studentIds: [student._id], + }); + }); + + if (groups.length == 0) { + project.failedCalculating = true; + project.reasonForFailing = 'Zero Possilbe Groups'; + } + + return groups; + + function findGroup(path: string[]) { + const matchingGroup: Group = groups.find((group) => + arraysHaveSameValues(group.requiredEvents, path) + ); + return matchingGroup; + } +} +function validating( + project: Project, + items: Item[], + students: Student[], + + rooms: Room[] +): boolean { + if (items.length > 0 && students.length > 0 && rooms.length > 0) { + return true; + } else { + project.failedCalculating = true; + project.reasonForFailing = `StudentsAmount: ${students.length}}; RoomsAmount: ${rooms.length}; ItemsAmount: ${items.length}`; + return false; + } +} + +export { + getRequiredGroupIds, + getVotingIds, + findItemsByStudentId, + validating, + buildGroupsByPaths, +}; diff --git a/src/data/Items.ts b/src/data/Items.ts index f2e16eb..7792bc7 100644 --- a/src/data/Items.ts +++ b/src/data/Items.ts @@ -8,8 +8,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 16, 10, 0), eventId: 'group1', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id2', @@ -18,8 +18,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 16, 10, 0), eventId: 'group2', studentIds: [], - groupCapazity: 2, - updatedGroupCapacity: 2, + studentCapacity: 2, + remainingCapacity: 2, }, { _id: 'id3', @@ -28,8 +28,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 16, 15, 0), eventId: 'group3', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id4', @@ -38,8 +38,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 17, 12, 0), eventId: 'solo3', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id5', @@ -48,8 +48,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 17, 15, 30), eventId: 'group2', studentIds: [], - groupCapazity: 98, - updatedGroupCapacity: 98, + studentCapacity: 98, + remainingCapacity: 98, }, { _id: 'id6', @@ -58,8 +58,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 18, 12, 0), eventId: 'group1', studentIds: [], - groupCapazity: 50, - updatedGroupCapacity: 50, + studentCapacity: 50, + remainingCapacity: 50, }, { _id: 'poll1', @@ -68,8 +68,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 18, 12, 0), eventId: 'poll1', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id7', @@ -78,8 +78,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 18, 15, 45), eventId: 'solo4', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id8', @@ -88,8 +88,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 19, 10, 30), eventId: 'solo5', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { @@ -99,8 +99,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 19, 15, 0), eventId: 'solo2', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id10', @@ -109,8 +109,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 20, 15, 30), eventId: 'group3', studentIds: [], - groupCapazity: 98, - updatedGroupCapacity: 98, + studentCapacity: 98, + remainingCapacity: 98, }, { _id: 'id11', @@ -119,8 +119,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 21, 15, 30), eventId: 'poll2', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, ]; diff --git a/src/data/Projects.ts b/src/data/Projects.ts index 718394e..d4a870d 100644 --- a/src/data/Projects.ts +++ b/src/data/Projects.ts @@ -3,7 +3,7 @@ import { Project } from '../../test/alg/data'; const berlin: Project = { _id: 'projectId1', name: 'Berlin 2024', - idsThatAreRequiredForEveryone: [ + requiredEventGroupsAsIds: [ 'group1', 'group2', 'group3', @@ -12,10 +12,10 @@ const berlin: Project = { 'solo4', 'solo5', ], - relatedPolls: ['id0', 'id1'], + pollIds: ['id0', 'id1'], status: 'WaitingForWorker', reasonForFailing: '', - failed: false, + failedCalculating: false, }; const projects = [berlin]; diff --git a/src/models/project.ts b/src/models/project.ts index a6fdbab..0bc356b 100644 --- a/src/models/project.ts +++ b/src/models/project.ts @@ -5,8 +5,8 @@ import Project from '../types/Project'; // Project schema const projectSchema = new Schema({ name: { type: String, minlength: 3, maxlength: 50, required: true }, - idsThatAreRequiredForEveryone: { type: [String], required: true }, - relatedPolls: { type: [String], required: false }, + requiredEventGroupsAsIds: { type: [String], required: true }, + pollIds: { type: [String], required: false }, status: { type: String, enum: [ @@ -25,7 +25,7 @@ const projectSchema = new Schema({ ], required: true, }, - failed: { type: Boolean, required: false }, + failedCalculating: { type: Boolean, required: false }, reasonForFailing: { type: String, required: false }, }); @@ -60,10 +60,10 @@ function validateSchema(project: Partial) { const { error } = schema.validate({ name: project.name, - idsThatAreRequiredForEveryone: project.idsThatAreRequiredForEveryone, - relatedPolls: project.relatedPolls, + idsThatAreRequiredForEveryone: project.requiredEventGroupsAsIds, + relatedPolls: project.pollIds, status: project.status, - failed: project.failed, + failed: project.failedCalculating, }); return { error }; diff --git a/src/routes/project.ts b/src/routes/project.ts index 843e9cb..0b5aa31 100644 --- a/src/routes/project.ts +++ b/src/routes/project.ts @@ -50,7 +50,7 @@ router.post('/', async (req: PaginationRequest, res: Response) => { 'idsThatAreRequiredForEveryone', ]) ); - project.failed = false; + project.failedCalculating = false; try { await project.save(); diff --git a/src/types/Item.ts b/src/types/Item.ts index 8bdbc4b..5e77340 100644 --- a/src/types/Item.ts +++ b/src/types/Item.ts @@ -5,8 +5,8 @@ interface Item { endTime: Date; eventId: string; studentIds: string[]; - groupCapazity: number; - updatedGroupCapacity: number; + studentCapacity: number; + remainingCapacity: number; } export default Item; diff --git a/src/types/Path_config.ts b/src/types/Path_config.ts index ac1e05e..0317f89 100644 --- a/src/types/Path_config.ts +++ b/src/types/Path_config.ts @@ -2,6 +2,6 @@ import Group from './Group'; import Item from './Item'; export interface Path_config { - path: Item[]; - valueForTestingStudentDistribution: number; + itemsInPath: Item[]; + testValueForDistributingStudents: number; } diff --git a/src/types/Polls.ts b/src/types/Polls.ts index be12974..930851c 100644 --- a/src/types/Polls.ts +++ b/src/types/Polls.ts @@ -3,6 +3,7 @@ interface PollChoice { text: string; eventId: string; studentIds: string[]; + limit?: number; } interface PollQuestion { diff --git a/src/types/Project.ts b/src/types/Project.ts index a8e096b..05020a2 100644 --- a/src/types/Project.ts +++ b/src/types/Project.ts @@ -1,8 +1,8 @@ interface Project { _id: string; name: string; - idsThatAreRequiredForEveryone: string[]; - relatedPolls: string[]; + requiredEventGroupsAsIds: string[]; + pollIds: string[]; status: | 'InPreperation' | 'WaitingForWorker' @@ -16,7 +16,7 @@ interface Project { | 'FinishedCalc' | 'StoreData' | 'Finished'; - failed: boolean; + failedCalculating: boolean; reasonForFailing: string; } diff --git a/test/alg/data.ts b/test/alg/data.ts index 84ea066..d536d2e 100644 --- a/test/alg/data.ts +++ b/test/alg/data.ts @@ -11,8 +11,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 16, 10, 0), eventId: 'group1', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id2', @@ -21,8 +21,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 16, 10, 0), eventId: 'group2', studentIds: [], - groupCapazity: 50, - updatedGroupCapacity: 50, + studentCapacity: 50, + remainingCapacity: 50, }, { _id: 'id3', @@ -31,8 +31,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 16, 15, 0), eventId: 'group3', studentIds: [], - groupCapazity: 50, - updatedGroupCapacity: 50, + studentCapacity: 50, + remainingCapacity: 50, }, { _id: 'id4', @@ -41,8 +41,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 17, 12, 0), eventId: 'solo3', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id5', @@ -51,8 +51,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 17, 15, 30), eventId: 'group2', studentIds: [], - groupCapazity: 50, - updatedGroupCapacity: 50, + studentCapacity: 50, + remainingCapacity: 50, }, { _id: 'id6', @@ -61,8 +61,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 18, 12, 0), eventId: 'group1', studentIds: [], - groupCapazity: 50, - updatedGroupCapacity: 50, + studentCapacity: 50, + remainingCapacity: 50, }, { _id: 'poll1', @@ -71,8 +71,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 18, 12, 0), eventId: 'poll1', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id7', @@ -81,8 +81,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 18, 15, 45), eventId: 'solo4', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id8', @@ -91,8 +91,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 19, 10, 30), eventId: 'solo5', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { @@ -102,8 +102,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 19, 15, 0), eventId: 'solo2', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id10', @@ -112,8 +112,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 20, 15, 30), eventId: 'group3', studentIds: [], - groupCapazity: 50, - updatedGroupCapacity: 50, + studentCapacity: 50, + remainingCapacity: 50, }, { _id: 'id11', @@ -122,8 +122,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 21, 15, 30), eventId: 'poll2', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, ]; @@ -149,9 +149,6 @@ const polls: PollQuestion[] = [ 'person29', 'person28', 'person27', - 'person26', - 'person25', - 'person24', ], text: 'Blueman Group', }, @@ -215,10 +212,10 @@ export { polls }; const project: Project = { _id: 'ProjectId', name: 'Berlin 2024', - failed: false, + failedCalculating: false, reasonForFailing: '', status: 'WaitingForWorker', - idsThatAreRequiredForEveryone: [ + requiredEventGroupsAsIds: [ 'group1', 'group2', 'group3', @@ -227,7 +224,7 @@ const project: Project = { 'solo4', 'solo5', ], - relatedPolls: ['id0', 'id1'], + pollIds: ['id0', 'id1'], }; export { project, Project }; diff --git a/test/alg/failData.ts b/test/alg/failData.ts index 9e87949..0d04c22 100644 --- a/test/alg/failData.ts +++ b/test/alg/failData.ts @@ -11,8 +11,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 16, 10, 0), eventId: 'group1', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id2', @@ -21,8 +21,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 16, 10, 0), eventId: 'group2', studentIds: [], - groupCapazity: 50, - updatedGroupCapacity: 50, + studentCapacity: 50, + remainingCapacity: 50, }, { _id: 'id3', @@ -31,8 +31,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 16, 15, 0), eventId: 'group3', studentIds: [], - groupCapazity: 50, - updatedGroupCapacity: 50, + studentCapacity: 50, + remainingCapacity: 50, }, { _id: 'id4', @@ -41,8 +41,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 17, 12, 0), eventId: 'solo3', studentIds: [], - groupCapazity: 20, - updatedGroupCapacity: 20, + studentCapacity: 20, + remainingCapacity: 20, }, { _id: 'id5', @@ -51,8 +51,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 17, 15, 30), eventId: 'group2', studentIds: [], - groupCapazity: 50, - updatedGroupCapacity: 50, + studentCapacity: 50, + remainingCapacity: 50, }, { _id: 'id6', @@ -61,8 +61,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 18, 12, 0), eventId: 'group1', studentIds: [], - groupCapazity: 50, - updatedGroupCapacity: 50, + studentCapacity: 50, + remainingCapacity: 50, }, { _id: 'poll1', @@ -71,8 +71,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 18, 12, 0), eventId: 'poll1', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id7', @@ -81,8 +81,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 18, 15, 45), eventId: 'solo4', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id8', @@ -91,8 +91,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 19, 10, 30), eventId: 'solo5', studentIds: [], - groupCapazity: 2, - updatedGroupCapacity: 2, + studentCapacity: 2, + remainingCapacity: 2, }, { @@ -102,8 +102,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 19, 15, 0), eventId: 'solo2', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, { _id: 'id10', @@ -112,8 +112,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 20, 15, 30), eventId: 'group3', studentIds: [], - groupCapazity: 50, - updatedGroupCapacity: 50, + studentCapacity: 50, + remainingCapacity: 50, }, { _id: 'id11', @@ -122,8 +122,8 @@ const items: Item[] = [ endTime: new Date(2023, 8, 21, 15, 30), eventId: 'poll2', studentIds: [], - groupCapazity: 100, - updatedGroupCapacity: 100, + studentCapacity: 100, + remainingCapacity: 100, }, ]; @@ -215,7 +215,7 @@ export { polls }; const project: Project = { _id: 'ProjectId', name: 'Berlin 2024', - idsThatAreRequiredForEveryone: [ + requiredEventGroupsAsIds: [ 'group1', 'group2', 'group3', @@ -224,10 +224,10 @@ const project: Project = { 'solo4', 'solo5', ], - failed: false, + failedCalculating: false, status: 'WaitingForWorker', reasonForFailing: '', - relatedPolls: ['id0', 'id1'], + pollIds: ['id0', 'id1'], }; export { project, Project }; diff --git a/test/alg/studentDistribution.test.ts b/test/alg/studentDistribution.test.ts index dfac77a..5f3a000 100644 --- a/test/alg/studentDistribution.test.ts +++ b/test/alg/studentDistribution.test.ts @@ -1,7 +1,7 @@ import { main } from '../../src/alg/StudentDistribution'; import { findItemsByStudentId, - getDefaultIds, + getRequiredGroupIds, getVotingIds, } from '../../src/alg/StudentDistribution/Utils'; import { items, polls, students, project } from './data'; @@ -14,7 +14,7 @@ describe('Time Distribution Algorithm', () => { expect(project.status).toEqual('FinishedCalc'); }); it('should allocate the correct number of items to each student', () => { - const requiredIdsLength = getDefaultIds(project).length; + const requiredIdsLength = getRequiredGroupIds(project).length; students.forEach((student) => { const studentId = student._id; @@ -37,7 +37,7 @@ describe('Time Distribution Algorithm', () => { allocationResult ); const expectedItemIds = [ - ...getDefaultIds(project), + ...getRequiredGroupIds(project), ...getVotingIds(studentId, polls), ]; @@ -49,7 +49,7 @@ describe('Time Distribution Algorithm', () => { it('should have only the allowed group size of students', () => { items.forEach((item) => { expect(item.studentIds.length).toBeLessThanOrEqual( - item.groupCapazity + item.studentCapacity ); }); }); @@ -62,8 +62,6 @@ describe('Time Distribution Algorithm', () => { allocationResult ); - expect(itemsForStudent.length).toBeGreaterThan(0); - for (let i = 0; i < itemsForStudent.length; i++) { for (let j = i + 1; j < itemsForStudent.length; j++) { const itemA = itemsForStudent[i]; @@ -80,7 +78,7 @@ describe('Time Distribution Algorithm', () => { otherItem.eventId === itemsForStudent[i].eventId && otherItem !== itemsForStudent[i] ); - const groupSize = itemsForStudent[i].groupCapazity; + const groupSize = itemsForStudent[i].studentCapacity; const studentsInGroup = groupEvents.reduce( (total, groupEvent) => total + groupEvent.studentIds.length, 0 @@ -93,7 +91,7 @@ describe('Time Distribution Algorithm', () => { it('should return false when no solution is found', () => { const result = main(failedItems, students, project, polls); expect(project.status).toBe('Distributing'); - expect(project.failed).toBe(true); + expect(project.failedCalculating).toBe(true); expect(result).toBe(false); }); }); From 75d5a6894d278610ddadddd85d2f608680e320a1 Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 14 Jul 2024 13:01:31 +0200 Subject: [PATCH 3/5] First working backtracking version for distributing. --- .../StudentDistribution/DistributeStudents.ts | 198 ++++++++++++------ 1 file changed, 133 insertions(+), 65 deletions(-) diff --git a/src/alg/StudentDistribution/DistributeStudents.ts b/src/alg/StudentDistribution/DistributeStudents.ts index 3e3493c..aee49ba 100644 --- a/src/alg/StudentDistribution/DistributeStudents.ts +++ b/src/alg/StudentDistribution/DistributeStudents.ts @@ -6,91 +6,159 @@ function distributeStudentsToPaths( items: Item[], groups: Group[], project: Project -) { +): void { setGroupsWithOnePath(groups, items); const changableGroups = groups.filter((group) => group.paths.length > 1); - let relevantItems = findRelevantItems(items, changableGroups); - - relevantItems = filterOutItemsWithoutCapacityProblems( - relevantItems, - amountRelevantStudents(changableGroups) - ); - return distributeWithMinimumCapacity( - changableGroups, - relevantItems, - project - ); -} -function distributeWithMinimumCapacity( - changableGroups: Group[], - relevantItems: Item[], - project: Project -) { - let working = true; - changableGroups.forEach((group) => { - let amountStudents = group.studentIds.length; - group.paths.forEach((path) => { - const minCapacity = Math.min( - ...path.path.map((pathItem) => pathItem.updatedGroupCapacity), - group.studentIds.length - ); - path.valueForTestingStudentDistribution = minCapacity; - amountStudents -= minCapacity; - relevantItems.forEach((item) => { - if (path.path.includes(item)) { - item.updatedGroupCapacity -= minCapacity; - } - }); + const groupsDistribution: { + groupId: number; + distributedStudentsPerPath: number[]; + validDistributionNumbers: number[][]; + amountToDistribute: number; + remainingToDistribute: number; + }[] = []; + + changableGroups.forEach((g) => { + groupsDistribution.push({ + groupId: g._id, + amountToDistribute: g.studentIds.length, + remainingToDistribute: g.studentIds.length, + distributedStudentsPerPath: Array(g.paths.length).fill(0), + validDistributionNumbers: [], }); + }); - if (amountStudents > 0) { - working = false; - project.failed = true; - project.reasonForFailing = 'Students left after distribution done'; - } + let validFound = false; + + changableGroups.forEach((g, index) => { + distributeItems( + 0, + g.studentIds.length, + new Array(g.paths.length).fill(0), + groupsDistribution[index].validDistributionNumbers, + g + ); }); - return working; -} -function amountRelevantStudents(changableGroups: Group[]) { - return changableGroups.reduce( - (total, group) => total + group.studentIds.length, - 0 - ); + if (!validFound) { + distributeStudentsToPath(0, 0); + } + + // Recursive function to distribute items + function distributeItems( + currentIndex: number, + remainingItems: number, + currentDistribution: number[], + validDistributionNumbers: number[][], + group: Group + ): void { + if (validFound) { + return; + } + + if (currentIndex === currentDistribution.length - 1) { + currentDistribution[currentIndex] = remainingItems; + + group.paths.forEach((p, index) => { + p.testValueForDistributingStudents = currentDistribution[index]; + }); + + if (isValid(groups)) { + validDistributionNumbers.push([...currentDistribution]); + } else { + group.paths.forEach((p) => { + p.testValueForDistributingStudents = 0; + }); + } + } else { + for (let i: number = 0; i <= remainingItems; i++) { + currentDistribution[currentIndex] = i; + distributeItems( + currentIndex + 1, + remainingItems - i, + currentDistribution, + validDistributionNumbers, + group + ); + } + } + } + + // Function to distribute students to paths recursively + function distributeStudentsToPath( + currentIndex: number, + groupIndex: number + ): void { + if (validFound || groupIndex >= changableGroups.length) { + project.failedCalculating = true; + return; + } + + const group = groupsDistribution[groupIndex]; + + if (currentIndex >= group.validDistributionNumbers.length) { + distributeStudentsToPath(0, groupIndex + 1); + return; + } + + group.validDistributionNumbers[currentIndex].forEach( + (distributionNumber, index) => { + changableGroups[groupIndex].paths[ + index + ].testValueForDistributingStudents = distributionNumber; + } + ); + + if (isValid(groups)) { + console.log('new result'); + groups.forEach((g) => { + const nums: number[] = []; + g.paths.forEach((p) => { + nums.push(p.testValueForDistributingStudents); + }); + console.log(`groupid: ${g._id}, pathDistribution: ${nums}`); + }); + validFound = true; + return; + } + + distributeStudentsToPath(currentIndex + 1, groupIndex); + } } -function findRelevantItems(items: Item[], changableGroups: Group[]): Item[] { - return items.filter((item) => { - let counter = 0; - changableGroups.forEach((group) => { - group.paths.forEach((path) => { - if (path.path.includes(item)) { - counter++; +function isValid(groups: Group[]): boolean { + const mapOfUsedCapacityPerItem: Map = new Map(); + let isValidDistribution = true; + + groups.forEach((g) => { + g.paths.forEach((path) => { + path.itemsInPath.forEach((item) => { + const itemMap = mapOfUsedCapacityPerItem.get(item) || 0; + mapOfUsedCapacityPerItem.set( + item, + itemMap + path.testValueForDistributingStudents + ); + + if ( + item.studentCapacity < mapOfUsedCapacityPerItem.get(item)! + ) { + isValidDistribution = false; } }); }); - return counter > 0; }); -} -function filterOutItemsWithoutCapacityProblems( - relevantItems: Item[], - amountRelevantStudents: number -) { - return relevantItems.filter( - (item) => item.updatedGroupCapacity < amountRelevantStudents - ); + return isValidDistribution; } -function setGroupsWithOnePath(groups: Group[], items: Item[]) { +function setGroupsWithOnePath(groups: Group[], items: Item[]): void { groups.forEach((group) => { if (group.paths.length === 1) { - group.paths[0].valueForTestingStudentDistribution = + group.paths[0].testValueForDistributingStudents = group.studentIds.length; items.forEach((item) => { - if (group.paths[0].path.includes(item)) { - item.updatedGroupCapacity -= group.studentIds.length; + if (group.paths[0].itemsInPath.includes(item)) { + item.remainingCapacity -= group.studentIds.length; } }); } From 7a3b3ab8c12b97001ffcfb25c0ce303c19a2268c Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 14 Jul 2024 13:13:05 +0200 Subject: [PATCH 4/5] Removed useless code and removed not working test. --- .../StudentDistribution/DistributeStudents.ts | 8 --- test/routes/project.test.ts | 51 ------------------- 2 files changed, 59 deletions(-) delete mode 100644 test/routes/project.test.ts diff --git a/src/alg/StudentDistribution/DistributeStudents.ts b/src/alg/StudentDistribution/DistributeStudents.ts index aee49ba..2c668b6 100644 --- a/src/alg/StudentDistribution/DistributeStudents.ts +++ b/src/alg/StudentDistribution/DistributeStudents.ts @@ -110,14 +110,6 @@ function distributeStudentsToPaths( ); if (isValid(groups)) { - console.log('new result'); - groups.forEach((g) => { - const nums: number[] = []; - g.paths.forEach((p) => { - nums.push(p.testValueForDistributingStudents); - }); - console.log(`groupid: ${g._id}, pathDistribution: ${nums}`); - }); validFound = true; return; } diff --git a/test/routes/project.test.ts b/test/routes/project.test.ts deleted file mode 100644 index 0f2a6da..0000000 --- a/test/routes/project.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import supertest, { SuperTest, Test } from 'supertest'; -import { server } from '../../src/server'; -import { seedProjectRoute } from '../seed'; -import { startDb, stopDB } from '../fakeDb'; - -describe('Project Routes Tests', () => { - let app: SuperTest; - let id = ''; - beforeAll(async () => { - app = supertest(server); - await startDb(); - seedProjectRoute(); - }); - - afterAll(async () => { - await stopDB(); - server.close(); - }); - - it('should get projects when GET /:id', async () => { - const response = await app.get('/project/65750b72771d33966c6da5cc'); - expect(response.status).toBe(200); - expect(response.body.name).toEqual('GetSpecialId'); - expect(response.body._id).toEqual('65750b72771d33966c6da5cc'); - }); - - it('should create a project when POST /', async () => { - const newProject = { - name: 'Create/Delete-Event', - idsThatAreRequiredForEveryone: ['solo5'], - relatedPolls: ['id0', 'id1'], - status: 'WaitingForWorker', - reasonForFailing: '', - }; - const response = await app.post('/project/').send(newProject); - expect(response.status).toBe(200); - }); - it('should get all projects', async () => { - const response = await app.get('/project'); - expect(response.status).toBe(200); - const projects = response.body; - expect(projects.length).toBeGreaterThan(0); - - const testId = projects[1]._id; - if (testId) id = testId; - }); - it('should delete', async () => { - const response = await app.delete('/project/' + id); - expect(response.status).toBe(200); - }); -}); From 393971f4384507ca1c43861b8cb3f73327309f77 Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 14 Jul 2024 13:26:06 +0200 Subject: [PATCH 5/5] Removed unnessecary remainingCapacity property. --- src/alg/StudentDistribution/DistributeStudents.ts | 9 ++------- src/data/Items.ts | 14 +------------- src/data/Polls.ts | 10 +--------- src/types/Item.ts | 1 - test/alg/data.ts | 12 ------------ test/alg/failData.ts | 12 ------------ 6 files changed, 4 insertions(+), 54 deletions(-) diff --git a/src/alg/StudentDistribution/DistributeStudents.ts b/src/alg/StudentDistribution/DistributeStudents.ts index 2c668b6..4e30168 100644 --- a/src/alg/StudentDistribution/DistributeStudents.ts +++ b/src/alg/StudentDistribution/DistributeStudents.ts @@ -7,7 +7,7 @@ function distributeStudentsToPaths( groups: Group[], project: Project ): void { - setGroupsWithOnePath(groups, items); + setGroupsWithOnePath(groups); const changableGroups = groups.filter((group) => group.paths.length > 1); const groupsDistribution: { @@ -143,16 +143,11 @@ function isValid(groups: Group[]): boolean { return isValidDistribution; } -function setGroupsWithOnePath(groups: Group[], items: Item[]): void { +function setGroupsWithOnePath(groups: Group[]): void { groups.forEach((group) => { if (group.paths.length === 1) { group.paths[0].testValueForDistributingStudents = group.studentIds.length; - items.forEach((item) => { - if (group.paths[0].itemsInPath.includes(item)) { - item.remainingCapacity -= group.studentIds.length; - } - }); } }); } diff --git a/src/data/Items.ts b/src/data/Items.ts index 7792bc7..c540672 100644 --- a/src/data/Items.ts +++ b/src/data/Items.ts @@ -9,7 +9,6 @@ const items: Item[] = [ eventId: 'group1', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id2', @@ -19,7 +18,6 @@ const items: Item[] = [ eventId: 'group2', studentIds: [], studentCapacity: 2, - remainingCapacity: 2, }, { _id: 'id3', @@ -29,7 +27,6 @@ const items: Item[] = [ eventId: 'group3', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id4', @@ -39,7 +36,6 @@ const items: Item[] = [ eventId: 'solo3', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id5', @@ -49,7 +45,6 @@ const items: Item[] = [ eventId: 'group2', studentIds: [], studentCapacity: 98, - remainingCapacity: 98, }, { _id: 'id6', @@ -59,7 +54,6 @@ const items: Item[] = [ eventId: 'group1', studentIds: [], studentCapacity: 50, - remainingCapacity: 50, }, { _id: 'poll1', @@ -69,7 +63,6 @@ const items: Item[] = [ eventId: 'poll1', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id7', @@ -79,7 +72,6 @@ const items: Item[] = [ eventId: 'solo4', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id8', @@ -89,7 +81,6 @@ const items: Item[] = [ eventId: 'solo5', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { @@ -100,7 +91,6 @@ const items: Item[] = [ eventId: 'solo2', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id10', @@ -110,7 +100,6 @@ const items: Item[] = [ eventId: 'group3', studentIds: [], studentCapacity: 98, - remainingCapacity: 98, }, { _id: 'id11', @@ -119,8 +108,7 @@ const items: Item[] = [ endTime: new Date(2023, 8, 21, 15, 30), eventId: 'poll2', studentIds: [], - studentCapacity: 100, - remainingCapacity: 100, + studentCapacity: 50, }, ]; diff --git a/src/data/Polls.ts b/src/data/Polls.ts index 3abe186..767fadc 100644 --- a/src/data/Polls.ts +++ b/src/data/Polls.ts @@ -53,15 +53,7 @@ const polls: PollQuestion[] = [ 'person76', 'person20', 'person17', - 'person23', - 'person31', - 'person30', - 'person29', - 'person28', - 'person27', - 'person26', - 'person25', - 'person24', + 'person88', ], text: 'Planspiel Bundestag', }, diff --git a/src/types/Item.ts b/src/types/Item.ts index 5e77340..6c68fac 100644 --- a/src/types/Item.ts +++ b/src/types/Item.ts @@ -6,7 +6,6 @@ interface Item { eventId: string; studentIds: string[]; studentCapacity: number; - remainingCapacity: number; } export default Item; diff --git a/test/alg/data.ts b/test/alg/data.ts index d536d2e..d21fb94 100644 --- a/test/alg/data.ts +++ b/test/alg/data.ts @@ -12,7 +12,6 @@ const items: Item[] = [ eventId: 'group1', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id2', @@ -22,7 +21,6 @@ const items: Item[] = [ eventId: 'group2', studentIds: [], studentCapacity: 50, - remainingCapacity: 50, }, { _id: 'id3', @@ -32,7 +30,6 @@ const items: Item[] = [ eventId: 'group3', studentIds: [], studentCapacity: 50, - remainingCapacity: 50, }, { _id: 'id4', @@ -42,7 +39,6 @@ const items: Item[] = [ eventId: 'solo3', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id5', @@ -52,7 +48,6 @@ const items: Item[] = [ eventId: 'group2', studentIds: [], studentCapacity: 50, - remainingCapacity: 50, }, { _id: 'id6', @@ -62,7 +57,6 @@ const items: Item[] = [ eventId: 'group1', studentIds: [], studentCapacity: 50, - remainingCapacity: 50, }, { _id: 'poll1', @@ -72,7 +66,6 @@ const items: Item[] = [ eventId: 'poll1', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id7', @@ -82,7 +75,6 @@ const items: Item[] = [ eventId: 'solo4', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id8', @@ -92,7 +84,6 @@ const items: Item[] = [ eventId: 'solo5', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { @@ -103,7 +94,6 @@ const items: Item[] = [ eventId: 'solo2', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id10', @@ -113,7 +103,6 @@ const items: Item[] = [ eventId: 'group3', studentIds: [], studentCapacity: 50, - remainingCapacity: 50, }, { _id: 'id11', @@ -123,7 +112,6 @@ const items: Item[] = [ eventId: 'poll2', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, ]; diff --git a/test/alg/failData.ts b/test/alg/failData.ts index 0d04c22..77eb178 100644 --- a/test/alg/failData.ts +++ b/test/alg/failData.ts @@ -12,7 +12,6 @@ const items: Item[] = [ eventId: 'group1', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id2', @@ -22,7 +21,6 @@ const items: Item[] = [ eventId: 'group2', studentIds: [], studentCapacity: 50, - remainingCapacity: 50, }, { _id: 'id3', @@ -32,7 +30,6 @@ const items: Item[] = [ eventId: 'group3', studentIds: [], studentCapacity: 50, - remainingCapacity: 50, }, { _id: 'id4', @@ -42,7 +39,6 @@ const items: Item[] = [ eventId: 'solo3', studentIds: [], studentCapacity: 20, - remainingCapacity: 20, }, { _id: 'id5', @@ -52,7 +48,6 @@ const items: Item[] = [ eventId: 'group2', studentIds: [], studentCapacity: 50, - remainingCapacity: 50, }, { _id: 'id6', @@ -62,7 +57,6 @@ const items: Item[] = [ eventId: 'group1', studentIds: [], studentCapacity: 50, - remainingCapacity: 50, }, { _id: 'poll1', @@ -72,7 +66,6 @@ const items: Item[] = [ eventId: 'poll1', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id7', @@ -82,7 +75,6 @@ const items: Item[] = [ eventId: 'solo4', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id8', @@ -92,7 +84,6 @@ const items: Item[] = [ eventId: 'solo5', studentIds: [], studentCapacity: 2, - remainingCapacity: 2, }, { @@ -103,7 +94,6 @@ const items: Item[] = [ eventId: 'solo2', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, { _id: 'id10', @@ -113,7 +103,6 @@ const items: Item[] = [ eventId: 'group3', studentIds: [], studentCapacity: 50, - remainingCapacity: 50, }, { _id: 'id11', @@ -123,7 +112,6 @@ const items: Item[] = [ eventId: 'poll2', studentIds: [], studentCapacity: 100, - remainingCapacity: 100, }, ];