Created
May 12, 2024 18:51
-
-
Save SrejonKhan/3e9f6a8baff14e0f779af6d92297e206 to your computer and use it in GitHub Desktop.
Semester Result generator to generate bulk fake result with valid courses for respected semester.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function extractIdParts(id) { | |
if (id.length < 16) { | |
throw new Error("ID Length cannot be less than 16."); | |
} | |
const regex = /(\d{3})(\d{2})(\d{1})(\d{2})(\d{5})(\d{3})/; | |
const match = regex.exec(id); | |
if (!match) { | |
throw new Error("Invalid ID format"); | |
} | |
const validSemesterCodes = { | |
1: "Spring", | |
2: "Fall", | |
}; | |
const validHostelCodes = { | |
"01": "Yes", | |
"02": "No", | |
}; | |
const validProgramNames = { | |
"05101": "CSE", | |
"05131": "EEE", | |
"05081": "CE", | |
"04081": "DBA", | |
"02161": "ENGLISH", | |
"08131": "LAW", | |
}; | |
// Extract the matched groups | |
const universityCode = match[1]; | |
const admissionYear = "20" + match[2]; | |
const semesterCode = match[3]; | |
const semesterName = validSemesterCodes[match[3]] ?? "Unknown"; | |
const hostelStatus = validHostelCodes[match[4]] ?? "Unknown"; | |
const programCode = match[5]; | |
const programName = validProgramNames[match[5]] ?? "Unknown"; | |
const studentSerial = match[6]; | |
const idParts = { | |
universityCode, | |
admissionYear, | |
semesterCode, | |
semesterName, | |
hostelStatus, | |
programCode, | |
programName, | |
studentSerial, | |
}; | |
return idParts; | |
} | |
function getCurrentSemester(id, currentDate) { | |
const { admissionYear, semesterCode } = extractIdParts(id); | |
const admissionDate = | |
semesterCode == "1" | |
? new Date(admissionYear, 3, 1) // spring | |
: new Date(admissionYear, 9, 1); // fall | |
const diff = | |
currentDate.getMonth() - admissionDate.getMonth() + 12 * (currentDate.getFullYear() - admissionDate.getFullYear()); | |
const currentSemester = parseInt(Math.ceil(diff / 6)); // 6 = bi-semester | |
return currentSemester; | |
} | |
// Example usage | |
const id = "0822220105101022"; | |
const idParts = extractIdParts(id); | |
console.log(idParts); | |
const currentDate = new Date(2024, 2, 14); // February 14, 2024 | |
const currentSemester = getCurrentSemester(id, currentDate); | |
console.log(`Student is currently in semester: ${currentSemester}`); | |
// generate IDs | |
const universityCode = "082"; | |
const programCodes = ["05101", "05131", "05081", "04081", "02161", "08131"]; | |
function generateStudentId(semesterCode, admissionYear, programCode, studentNumber) { | |
const formattedStudentNumber = studentNumber.toString().padStart(3, "0"); | |
const hostelCode = "01"; | |
return `${universityCode}${admissionYear}${semesterCode}${hostelCode}${programCode}${formattedStudentNumber}`; | |
} | |
function generateStudentsForSemester(semesterCode, admissionYear) { | |
const students = []; | |
for (let programCode of programCodes) { | |
for (let i = 1; i <= 50; i++) { | |
const id = generateStudentId(semesterCode, admissionYear, programCode, i); | |
students.push(id); | |
} | |
} | |
return students; | |
} | |
const semesters = { | |
"Spring 2020": generateStudentsForSemester("1", 20), | |
"Fall 2020": generateStudentsForSemester("2", 20), | |
"Spring 2022": generateStudentsForSemester("1", 22), | |
"Fall 2022": generateStudentsForSemester("2", 22), | |
"Spring 2023": generateStudentsForSemester("1", 23), | |
"Fall 2023": generateStudentsForSemester("2", 23), | |
}; | |
console.log(semesters); | |
/* ------------------------ BANGLA NAME GENERATOR ------------------------ */ | |
function generateBanglaName() { | |
// Common Bangla first names (replace with desired names if needed) | |
const firstNames = [ | |
"Akash", | |
"Anik", | |
"Afrin", | |
"Arman", | |
"Anika", | |
"Anjum", | |
"Arifa", | |
"Asif", | |
"Alisha", | |
"Anamika", | |
"Bablu", | |
"Babul", | |
"Bobby", | |
"Bindu", | |
"Chandni", | |
"Chhobi", | |
"Chotu", | |
"Dipti", | |
"Durga", | |
"Dalia", | |
"Emon", | |
"Eva", | |
"Farah", | |
"Farzana", | |
"Farida", | |
"Gita", | |
"Gulshan", | |
"Hasina", | |
"Humaira", | |
"Imran", | |
"Jalal", | |
"Jamal", | |
"Javed", | |
"Johny", | |
"Joyita", | |
"Kajal", | |
"Kamal", | |
"Kartik", | |
"Khalid", | |
"Kiran", | |
"Laila", | |
"Lucky", | |
"Luna", | |
"Mamun", | |
"Munmun", | |
"Muniya", | |
"Nasir", | |
"Nadira", | |
"Neha", | |
"Nikhil", | |
"Nilufar", | |
"Nilanjana", | |
"Nirupama", | |
"Nirob", | |
"Parvathy", | |
"Priya", | |
"Purnima", | |
"Rashid", | |
"Rehana", | |
"Renuka", | |
"Rezwan", | |
"Rimi", | |
"Rina", | |
"Rubina", | |
"Rumi", | |
"Sabina", | |
"Salim", | |
"Samia", | |
"Sana", | |
"Sayem", | |
"Shabana", | |
"Shahanwaz", | |
"Shaima", | |
"Shakib", | |
"Shamim", | |
"Sharika", | |
"Shimul", | |
"Shraddha", | |
"Sohan", | |
"Sumaiya", | |
"Sumon", | |
"Tania", | |
"Taslima", | |
"Tanvir", | |
"Tania", | |
"Urmi", | |
"Yasmin", | |
"Zarina", | |
]; | |
// Common Bangla last names (replace with desired names if needed) | |
const lastNames = [ | |
"Ahmed", | |
"Alam", | |
"Ali", | |
"Chowdhury", | |
"Das", | |
"Gupta", | |
"Hossain", | |
"Islam", | |
"Khan", | |
"Mondal", | |
"Rahman", | |
"Sarkar", | |
"Sen", | |
"Shah", | |
"Sheikh", | |
"Talukder", | |
"Yeasmin", | |
]; | |
// Randomly select a first name | |
const firstName = firstNames[Math.floor(Math.random() * firstNames.length)]; | |
// Randomly select a last name | |
const lastName = lastNames[Math.floor(Math.random() * lastNames.length)]; | |
// Combine the names with a space | |
const fullName = `${firstName} ${lastName}`; | |
return fullName; | |
} | |
// Generate a Bangla name and log it | |
console.log(generateBanglaName()); | |
/* ------------------------ RANDOM GRADE GENERATOR ------------------------ */ | |
function getRandomGrade() { | |
// Create an array of objects, where each object represents a row in the table. | |
const grades = [ | |
{ number: "80% and above", grade: "A+", point: 4.0 }, | |
{ number: "75% to less than 80%", grade: "A", point: 3.75 }, | |
{ number: "70% to less than 75%", grade: "A-", point: 3.5 }, | |
{ number: "65% to less than 70%", grade: "B+", point: 3.25 }, | |
{ number: "60% to less than 65%", grade: "B", point: 3.0 }, | |
{ number: "55% to less than 60%", grade: "B-", point: 2.75 }, | |
{ number: "50% to less than 55%", grade: "C+", point: 2.5 }, | |
{ number: "45% to less than 50%", grade: "C", point: 2.25 }, | |
{ number: "40% to less than 45%", grade: "D", point: 2.0 }, | |
{ number: "<40% Less than 40%", grade: "F", point: 0.0 }, | |
]; | |
// Get a random number between 0 and the length of the grades array (inclusive). | |
const randomIndex = Math.floor(Math.random() * grades.length); | |
// Return the grade and grade point at the random index. | |
return grades[randomIndex]; | |
} | |
// Example usage: | |
const randomGrade = getRandomGrade(); | |
console.log(`Random grade: ${randomGrade.grade} (${randomGrade.point})`); | |
/* ------------------------ RESULT GENERATOR ------------------------ */ | |
const courses = { | |
total_bsc_credit: 145, | |
semesters: [ | |
{ | |
semester_name: "First Semester", | |
courses: [ | |
{ | |
course_code: "CSE 113", | |
course_title: "Discrete Mathematics", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 112", | |
course_title: "Introduction to Computing Sessional", | |
credit: 1.5, | |
}, | |
{ | |
course_code: "CHEM 111", | |
course_title: "Chemistry", | |
credit: 3, | |
}, | |
{ | |
course_code: "CHEM 112", | |
course_title: "Chemistry Sessional", | |
credit: 1, | |
}, | |
{ | |
course_code: "ENG 111", | |
course_title: "English Reading and Speaking", | |
credit: 2, | |
}, | |
{ | |
course_code: "MATH 111", | |
course_title: "MATH I (Differential Calculus, Integral Calculus and Matrix)", | |
credit: 3, | |
}, | |
{ | |
course_code: "EEE 111", | |
course_title: "Electrical Circuit Analysis", | |
credit: 3, | |
}, | |
{ | |
course_code: "EEE 112", | |
course_title: "Electrical Circuit Analysis Sessional", | |
credit: 1.5, | |
}, | |
], | |
total_credit: 18, | |
}, | |
{ | |
semester_name: "Second Semester", | |
courses: [ | |
{ | |
course_code: "CSE 121", | |
course_title: "Structured Programming Language", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 122", | |
course_title: "Structured Programming Language Sessional", | |
credit: 1.5, | |
}, | |
{ | |
course_code: "GED 121", | |
course_title: "History of the Emergence of Bangladesh", | |
credit: 2, | |
}, | |
{ | |
course_code: "ENG 121", | |
course_title: "English Writing and Listening", | |
credit: 3, | |
}, | |
{ | |
course_code: "MATH 121", | |
course_title: "MATH II (Vector Analysis, Linear Algebra, Coordinate Geometry and Fourier Analysis)", | |
credit: 3, | |
}, | |
{ | |
course_code: "EEE 121", | |
course_title: "Electronic Devices and Circuits", | |
credit: 3, | |
}, | |
{ | |
course_code: "EEE 122", | |
course_title: "Electronic Devices and Circuits Sessional", | |
credit: 1.5, | |
}, | |
{ | |
course_code: "PHY 121", | |
course_title: "Physics I", | |
credit: 3, | |
}, | |
{ | |
course_code: "PHY 124", | |
course_title: "Basic Physics Sessional", | |
credit: 1, | |
}, | |
], | |
total_credit: 21, | |
}, | |
{ | |
semester_name: "Third Semester", | |
courses: [ | |
{ | |
course_code: "CSE 211", | |
course_title: "Data Structures", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 212", | |
course_title: "Data Structures Sessional", | |
credit: 1.5, | |
}, | |
{ | |
course_code: "CSE 213", | |
course_title: "Object Oriented Programming Language", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 214", | |
course_title: "Object Oriented Programming Language Sessional", | |
credit: 1.5, | |
}, | |
{ | |
course_code: "MATH 211", | |
course_title: "MATH III (Differential Equations, Complex Variables and Laplace Transforms)", | |
credit: 3, | |
}, | |
{ | |
course_code: "PHY 211", | |
course_title: "Physics II", | |
credit: 3, | |
}, | |
{ | |
course_code: "HUM 211", | |
course_title: "Bangla Language", | |
credit: 2, | |
}, | |
{ | |
course_code: "GED 211", | |
course_title: "Finance and Investment", | |
credit: 3, | |
}, | |
], | |
total_credit: 20, | |
}, | |
{ | |
semester_name: "Fourth Semester", | |
courses: [ | |
{ | |
course_code: "CSE 221", | |
course_title: "Computer Algorithms and Complexity", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 222", | |
course_title: "Computer Algorithms and Complexity Sessional", | |
credit: 1.5, | |
}, | |
{ | |
course_code: "CSE 223", | |
course_title: "Digital Logic Design", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 224", | |
course_title: "Digital Logic Design Sessional", | |
credit: 1.5, | |
}, | |
{ | |
course_code: "CSE 225", | |
course_title: "Numerical Methods", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 226", | |
course_title: "Numerical Methods Sessional", | |
credit: 1, | |
}, | |
{ | |
course_code: "MATH 221", | |
course_title: "MATH IV (Probability and Statistics)", | |
credit: 3, | |
}, | |
{ | |
course_code: "GED 221", | |
course_title: "Engineering Economics", | |
credit: 3, | |
}, | |
], | |
total_credit: 19, | |
}, | |
{ | |
semester_name: "Fifth Semester", | |
courses: [ | |
{ | |
course_code: "CSE 311", | |
course_title: "Operating System", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 312", | |
course_title: "Operating System Sessional", | |
credit: 1, | |
}, | |
{ | |
course_code: "CSE 313", | |
course_title: "Database Management System", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 314", | |
course_title: "Database Management System Sessional", | |
credit: 1.5, | |
}, | |
{ | |
course_code: "CSE 315", | |
course_title: "Computer Architecture and Design", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 317", | |
course_title: "Software Engineering and Design Patterns", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 318", | |
course_title: "Software Engineering and Design Patterns Sessional", | |
credit: 1, | |
}, | |
{ | |
course_code: "CSE 319", | |
course_title: "Theory of Computation", | |
credit: 3, | |
}, | |
{ | |
course_code: "CE 311", | |
course_title: "Engineering Drawing", | |
credit: 1, | |
}, | |
{ | |
course_code: "CE 312", | |
course_title: "Engineering Drawing and CAD Sessional", | |
credit: 1, | |
}, | |
], | |
total_credit: 20.5, | |
}, | |
{ | |
semester_name: "Sixth Semester", | |
courses: [ | |
{ | |
course_code: "CSE 321", | |
course_title: "Data Communications", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 322", | |
course_title: "Data Communications Sessional", | |
credit: 1, | |
}, | |
{ | |
course_code: "CSE 323", | |
course_title: "Web Technologies", | |
credit: 2, | |
}, | |
{ | |
course_code: "CSE 324", | |
course_title: "Web Technologies Sessional", | |
credit: 1.5, | |
}, | |
{ | |
course_code: "CSE 325", | |
course_title: "Microprocessor, Assembly Language and Computer Interfacing", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 326", | |
course_title: "Microprocessor, Assembly Language and Computer Interfacing Sessional", | |
credit: 1.5, | |
}, | |
{ | |
course_code: "CSE 327", | |
course_title: "Computer Networks", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 328", | |
course_title: "Computer Networks Sessional", | |
credit: 1.5, | |
}, | |
{ | |
course_code: "CSE 301", | |
course_title: "Integrated Design Project", | |
credit: 2, | |
}, | |
{ | |
course_code: "CSE 329", | |
course_title: "Management Information System", | |
credit: 2, | |
}, | |
], | |
total_credit: 20.5, | |
}, | |
{ | |
semester_name: "Seventh Semester", | |
courses: [ | |
{ | |
course_code: "CSE 411", | |
course_title: "Machine Learning", | |
credit: 2, | |
}, | |
{ | |
course_code: "CSE 412", | |
course_title: "Machine Learning Sessional", | |
credit: 1, | |
}, | |
{ | |
course_code: "CSE-413", | |
course_title: "Compiler Design and Construction", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 414", | |
course_title: "Compiler Design and Construction Sessional", | |
credit: 1, | |
}, | |
{ | |
course_code: "CSE 415", | |
course_title: "Research Methodology and Complex Engineering Activities", | |
credit: 2, | |
}, | |
{ | |
course_code: "GED 411", | |
course_title: "Business Communications", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 401", | |
course_title: "Capstone Project (Part-1)", | |
credit: 2, | |
}, | |
], | |
total_credit: 14, | |
}, | |
{ | |
semester_name: "Eighth Semester", | |
courses: [ | |
{ | |
course_code: "CSE 421", | |
course_title: "Artificial Intelligence", | |
credit: 3, | |
}, | |
{ | |
course_code: "CSE 422", | |
course_title: "Artificial Intelligence Sessional", | |
credit: 1, | |
}, | |
{ | |
course_code: "GED 421", | |
course_title: "Sociology for Engineers", | |
credit: 2, | |
}, | |
{ | |
course_code: "GED 423", | |
course_title: "Engineering Ethics", | |
credit: 2, | |
}, | |
{ | |
course_code: "CSE 402", | |
course_title: "Capstone (Part-2)", | |
credit: 4, | |
}, | |
], | |
total_credit: 12, | |
}, | |
], | |
}; | |
const results = []; | |
for (const semesterCode in semesters) { | |
const studentIds = semesters[semesterCode]; | |
const currentDate = new Date(2024, 1, 14); // February 14, 2024 | |
studentIds.forEach((id) => { | |
const currentSemester = courses.semesters[getCurrentSemester(id, currentDate) - 1]; | |
const currentCourses = currentSemester.courses; | |
const result = { | |
id: id, | |
name: generateBanglaName(), | |
semester: semesterCode, | |
courses: [], | |
dob: "2024-02-22", | |
}; | |
let totalCredit = 0; | |
let totalCg = 0; | |
currentCourses.forEach((course) => { | |
const randomGrade = getRandomGrade(); | |
course.grade = randomGrade.grade; | |
if (randomGrade.point == 0.0) course.status = "FAILED"; | |
else course.status = "PASSED"; | |
result.courses.push(course); | |
totalCredit += course.credit; | |
totalCg += randomGrade.point; | |
}); | |
result.cgpa = (totalCg / currentCourses.length).toFixed(2); | |
// if (result.cgpa >= 4) console.log("bipod"); | |
results.push({ | |
key: id, | |
value: JSON.stringify(result), | |
expiration_ttl: 86400, | |
}); | |
}); | |
} | |
console.log(results.length); | |
// const fs = require("fs"); | |
// fs.createWriteStream("fake_results.json").write(JSON.stringify(results)); | |
const result = [ | |
{ | |
id: "0822210105101022", | |
name: "Srejon", | |
semester: "FALL 2023", | |
cgpa: "3.42", | |
courses: [ | |
{ | |
course_code: "CSE-211", | |
course_title: "Data Structures", | |
credit: "3.00", | |
grade: "A+", | |
status: "PASSED", | |
}, | |
// other courses | |
], | |
}, | |
// other students | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment