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

Fix roster format #1557

Merged
merged 3 commits into from
Jul 13, 2022
Merged
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
78 changes: 46 additions & 32 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ def download_roster
@cuds.each do |cud|
user = cud.user
# to_csv avoids issues with commas
output += [@course.semester, cud.user.email, user.last_name, user.first_name, cud.school,
cud.major, cud.year, cud.grade_policy, cud.lecture, cud.section].to_csv
output += [@course.semester, cud.user.email, user.last_name, user.first_name,
cud.school, cud.major, cud.year, cud.grade_policy,
@course.name, cud.lecture, cud.section].to_csv
end
send_data output, filename: "roster.csv", type: "text/csv", disposition: "inline"
end
Expand Down Expand Up @@ -637,15 +638,18 @@ def parse_roster_csv
begin
csv = detect_and_convert_roster(params["upload"]["file"].read)
csv.each do |row|
new_cud = { email: row[1].to_s,
last_name: row[2].to_s.chomp(" "),
first_name: row[3].to_s.chomp(" "),
school: row[4].to_s.chomp(" "),
major: row[5].to_s.chomp(" "),
year: row[6].to_s.chomp(" "),
grade_policy: row[7].to_s.chomp(" "),
lecture: row[9].to_s.chomp(" "),
section: row[10].to_s.chomp(" ") }
new_cud = { # Ignore Semester (row[0])
email: row[1].to_s,
last_name: row[2].to_s.chomp(" "),
first_name: row[3].to_s.chomp(" "),
school: row[4].to_s.chomp(" "),
major: row[5].to_s.chomp(" "),
year: row[6].to_s.chomp(" "),
grade_policy: row[7].to_s.chomp(" "),
# Ignore courseNumber (row[8])
lecture: row[9].to_s.chomp(" "),
section: row[10].to_s.chomp(" ")
}
cud = @currentCUDs.find do |current|
current.user && current.user.email.downcase == new_cud[:email].downcase
end
Expand Down Expand Up @@ -707,15 +711,15 @@ def parse_roster_csv
# column matching and convert to default roster

# map fields:
# map[0]: semester
# map[0]: semester (unused)
# map[1]: email
# map[2]: last_name
# map[3]: first_name
# map[4]: school
# map[5]: major
# map[6]: year
# map[7]: grade_policy
# map[8]: unused
# map[8]: course (unused)
# map[9]: lecture
# map[10]: section
# rubocop:disable Lint/UselessAssignment
Expand All @@ -726,34 +730,44 @@ def detect_and_convert_roster(roster)
raise "Roster cannot be recognized" if parsedRoster[0][0].nil?

case parsedRoster[0].length
when ROSTER_COLUMNS_F20
when ROSTER_COLUMNS_F20 # 34 fields
# In CMU S3 roster. Columns are:
# Semester(0), Course(1), Section(2), (Lecture)(3), (Mini-skip)(4),
# Last Name(5), Preferred/First Name(6), (MI-skip)(7), Andrew ID(8),
# (Email-skip)(9), College(10), (Department-skip)(11), Major(12),
# Class(13), Graduation Semester(skip)(14), Units(skip)(15), Grade Option(16), ...
map = [0, 8, 5, 6, 10, 12, 13, 16, -1, 1, 2]
# Semester(0 - skip), Course(1 - skip), Section(2), Lecture(3), Mini(4 - skip),
# Last Name(5), Preferred/First Name(6), MI(7 - skip), Andrew ID(8),
# Email(9 - skip), College(10), Department(11 - skip), Major(12),
# Class(13), Graduation Semester(14 - skip), Units(15 - skip), Grade Option(16)
# ... the remaining fields are all skipped but shown for completeness
# QPA Scale(17), Mid-Semester Grade(18), Primary Advisor(19), Final Grade(20),
# Default Grade(21), Time Zone Code(22), Time Zone Description(23), Added By(24),
# Added On(25), Confirmed(26), Waitlist Position(27), Units Carried/Max Units(28),
# Waitlisted By(29), Waitlisted On(30), Dropped By(31), Dropped On(32), Roster As Of Date(33)
map = [-1, 8, 5, 6, 10, 12, 13, 16, -1, 3, 2]
select_columns = ROSTER_COLUMNS_F20
when ROSTER_COLUMNS_F16
when ROSTER_COLUMNS_F16 # 32 fields
# In CMU S3 roster. Columns are:
# Semester(0), Course(1), Section(2), (Lecture-skip)(3), (Mini-skip)(4),
# Last Name(5), First Name(6), (MI-skip)(7), Andrew ID(8),
# (Email-skip)(9), School(10), (Department-skip)(11), Major(12),
# Year(13), (skip)(14), Grade Policy(15), ...
map = [0, 8, 5, 6, 10, 12, 13, 15, -1, 1, 2]
# Semester(0 - skip), Course(1 - skip), Section(2), Lecture(3), Mini(4 - skip),
# Last Name(5), Preferred/First Name(6), MI(7 - skip), Andrew ID(8),
# Email(9 - skip), College(10), Department(11), Major(12),
# Class(13), Graduation Semester(14 - skip), Units(15 - skip), Grade Option(16)
# ... the remaining fields are all skipped but shown for completeness
# QPA Scale(17), Mid-Semester Grade(18), Primary Advisor(19), Final Grade(20),
# Default Grade(21), Added By(22), Added On(23), Confirmed(24), Waitlist Position(25),
# Units Carried/Max Units(26), Waitlisted By(27), Waitlisted On(28), Dropped By(29),
# Dropped On(30), Roster As Of Date(31)
map = [-1, 8, 5, 6, 10, 12, 13, 16, -1, 3, 2]
select_columns = ROSTER_COLUMNS_F16
when ROSTER_COLUMNS_S15
when ROSTER_COLUMNS_S15 # 29 fields
# In CMU S3 roster. Columns are:
# Semester(0), Lecture(1), Section(2), (skip)(3), (skip)(4), Last Name(5),
# Semester(0 - skip), Lecture(1), Section(2), (skip)(3), (skip)(4), Last Name(5),
# First Name(6), (skip)(7), Andrew ID(8), (skip)(9), School(10),
# Major(11), Year(12), (skip)(13), Grade Policy(14), ...
map = [0, 8, 5, 6, 10, 11, 12, 14, -1, 1, 2]
# Major(11), Year(12), (skip)(13), Grade Policy(14), ... [elided]
map = [-1, 8, 5, 6, 10, 11, 12, 14, -1, 1, 2]
select_columns = ROSTER_COLUMNS_S15
else
# No header row. Columns are:
# Semester(0), Email(1), Last Name(2), First Name(3), School(4),
# Major(5), Year(6), Grade Policy(7), (skip)(8), Lecture(9),
# Section(10), ...
# Semester(0 - skip), Email(1), Last Name(2), First Name(3), School(4),
# Major(5), Year(6), Grade Policy(7), Course(8 - skip), Lecture(9),
# Section(10)
return parsedRoster
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fully consistent with what we're doing with SIO rosters (i.e. dropping the Semester and Course columns here, even though they will be ignored later on anyway), we should technically use a "map" here [-1, 1, 2, 3, 4, 5, 6, 7, -1, 9, 10]. However, this doesn't make a difference unless for some reason we make use of those columns in the future.

end
# rubocop:enable Lint/UselessAssignment
Expand Down