|
| 1 | +import { faker } from "@faker-js/faker"; // eslint-disable-line import/no-extraneous-dependencies |
| 2 | + |
| 3 | +const generateRandomLevels = () => { |
| 4 | + const levels = []; |
| 5 | + const numLevels = faker.number.int({ min: 1, max: 6 }); |
| 6 | + for (let i = 0; i < numLevels; i += 1) { |
| 7 | + levels.push(`L${i + 1}`); |
| 8 | + } |
| 9 | + return levels; |
| 10 | +}; |
| 11 | + |
| 12 | +const generateRandomOutcomes = () => { |
| 13 | + const outcomes = []; |
| 14 | + const outcome = faker.lorem.sentence({ min: 3, max: 6 }); |
| 15 | + for (let i = 0; i <= 6; i += 1) { |
| 16 | + outcomes.push(outcome); |
| 17 | + } |
| 18 | + return outcomes; |
| 19 | +}; |
| 20 | + |
| 21 | +const createRandomCourses = (type) => ({ |
| 22 | + name: faker.lorem.sentence({ min: 1, max: 3 }), |
| 23 | + code: faker.vehicle.vin(), |
| 24 | + theoryHours: |
| 25 | + type === "onlypractical" ? null : faker.number.int({ min: 2, max: 6 }), |
| 26 | + department: faker.database.mongodbObjectId(), // TODO |
| 27 | + tutorialHours: |
| 28 | + type === "tutorial" ? faker.number.int({ min: 2, max: 6 }) : null, |
| 29 | + practicalHours: faker.helpers.weightedArrayElement([ |
| 30 | + { value: faker.number.int({ min: 2, max: 6 }), weight: 6 }, |
| 31 | + { value: null, weight: 1 }, |
| 32 | + ]), |
| 33 | + ISAMarks: 20, |
| 34 | + ESEMarks: 60, |
| 35 | + tutorialMarks: type === "tutorial" ? 20 : null, |
| 36 | + practicalMarks: type === "nopractical" ? null : 30, |
| 37 | + semester: faker.database.mongodbObjectId(), |
| 38 | + subType: faker.helpers.arrayElement(["open", "professional", "core"]), |
| 39 | + prerequisites: generateRandomOutcomes(), |
| 40 | + objective: faker.lorem.sentence({ min: 6, max: 10 }), |
| 41 | + outcomes: { |
| 42 | + outcome: faker.lorem.sentence({ min: 3, max: 6 }), |
| 43 | + RBTLevel: generateRandomLevels(), |
| 44 | + }, |
| 45 | + modules: [faker.database.mongodbObjectId()], |
| 46 | + practicals: [faker.database.mongodbObjectId()], |
| 47 | + tutorials: [faker.database.mongodbObjectId()], |
| 48 | + assignments: [faker.database.mongodbObjectId()], |
| 49 | + reccTextbooks: generateRandomOutcomes(), |
| 50 | + refBooks: faker.lorem.word({ length: { min: 5, max: 7 } }), |
| 51 | +}); |
| 52 | + |
| 53 | +const generateCourses = ( |
| 54 | + createdSems, |
| 55 | + createdModules, |
| 56 | + createdPracs, |
| 57 | + createdTuts, |
| 58 | + createdDepts, |
| 59 | +) => { |
| 60 | + const courses = []; |
| 61 | + for (let i = 0, j = 0; j <= createdDepts.length; i += 1) { |
| 62 | + const type = faker.helpers.weightedArrayElement([ |
| 63 | + { value: "normal", weight: 12 }, |
| 64 | + { value: "tutorial", weight: 2 }, |
| 65 | + { value: "nopractical", weight: 2 }, |
| 66 | + { value: "onlypractical", weight: 1 }, |
| 67 | + ]); |
| 68 | + courses.push(createRandomCourses(type)); |
| 69 | + if (i >= createdSems.length) { |
| 70 | + i = 0; |
| 71 | + j += 1; |
| 72 | + } |
| 73 | + } |
| 74 | + return courses; |
| 75 | +}; |
| 76 | + |
| 77 | +export default generateCourses; |
0 commit comments