diff --git a/Matcher.js b/Matcher.js index 3fa1c84..eece02e 100644 --- a/Matcher.js +++ b/Matcher.js @@ -16,6 +16,9 @@ class Matcher { // An array containing Student objects representing every student this.allStudents = []; + // An array containing Student objects that are preassigned + this.preAssignedStudents = []; + // An array containing all workshop objects sorted from least to most popular this.workshopsByPopularity = []; @@ -80,6 +83,30 @@ class Matcher { student.updatePopularities(); } + /** + * Adds a preassigned Student object into preAssignedStudents + * + * @param {string} firstName The first name of the student. + * @param {string} lastName The last name of the student. + * @param {string} grade The last name of the student. + * @param {array} assignments The student's assignments as an array of integers. + */ + addPreassignedStudent(firstName, lastName, grade, assignments) { + const student = new Student( + firstName, + lastName, + assignments, + grade, + this.sessionsPerWorkshop + ); + for (let i = 0; i < assignments.length; i++) { + //for all assignments + const workshop = this.workshopsByNumber[assignments[i]]; + student.assignWorkshop(workshop); + } + this.preAssignedStudents.push(student); + } + /** * Helper function for sorting that compares two workshops by their popularity. * diff --git a/main.js b/main.js index 6d5cf53..a2be8ef 100644 --- a/main.js +++ b/main.js @@ -11,6 +11,12 @@ const COLUMN_WORKSHOP_CAPACITY = 6; const COLUMN_WORKSHOP_BUILDING = 4; const COLUMN_WORKSHOP_ROOM = 5; +// Column indicies of the Pre-assignment Sheet +const COLUMN_FIRST_NAMEP = 0; +const COLUMN_LAST_NAMEP = 1; +const COLUMN_GRADEP = 2; +const COLUMN_ASSIGNMENTS = [3, 4, 5]; + // Column indices of student preferences in order from most preferred to least const PREFERENCE_COLUMNS = [1, 2, 3, 4, 5, 6]; @@ -118,8 +124,19 @@ function main() { matcher.addNewStudent(firstName, lastName, preferenceNums, grade); } - Logger.log(matcher.allStudents[0].firstName); - Logger.log(matcher.allStudents[0].preferences[0].name); + for (let l = 1; l < PRE_ASSIGNMENT_DATA.length; l++) { + // For all preassignements l + const firstName = PRE_ASSIGNMENT_DATA[l][COLUMN_FIRST_NAMEP]; + const lastName = PRE_ASSIGNMENT_DATA[l][COLUMN_LAST_NAMEP]; + const grade = PRE_ASSIGNMENT_DATA[l][COLUMN_GRADEP]; + const assignments = []; + for (let m = 0; m < COLUMN_ASSIGNMENTS.length; m++) { + //for each Assignment m + assignments.push(PRE_ASSIGNMENT_DATA[l][COLUMN_ASSIGNMENTS[m]]); + } + + matcher.addPreassignedStudent(firstName, lastName, grade, assignments); + } populateSheet(outputSheet, matcher); } @@ -139,6 +156,25 @@ function populateSheet(outputSheet, matcher) { // All student lines to output const studentLines = []; + for (const student of matcher.preAssignedStudents) { + const studentLine = []; + studentLine.push(student.firstName); + studentLine.push(student.lastName); + studentLine.push(student.grade); + + // List the student's assigned workshops in the row + for (const workshop of student.assignedWorkshops) { + if (workshop === null) { + studentLine.push("", "", ""); + } else { + studentLine.push(workshop.number); + studentLine.push(workshop.name); + studentLine.push(workshop.location); + } + } + studentLines.push(studentLine); + } + for (const student of matcher.allStudents) { const studentLine = []; studentLine.push(student.firstName); @@ -163,4 +199,13 @@ function populateSheet(outputSheet, matcher) { outputSheet .getRange(outputSheet.getLastRow() + 1, 1, rowCount, columnCount) .setValues(studentLines); + + let colors = ["PaleGreen", "PaleTurquoise", "Pink", "PeachPuff", "White"]; + for (let i = 0; i < 5; i++) { + let colorColumn = (i*3) + 1; + let color = colors[i]; + outputSheet + .getRange(1, colorColumn, outputSheet.getLastRow(), colorColumn + 2) + .setBackground(color); + } }