Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COLORS #69

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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.
*
Expand Down
49 changes: 47 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
}
}