Commit 410ff7a6 authored by Zach Perkins's avatar Zach Perkins
Browse files

Used more efficient ActiveRecord create

parent cc4f4bdc
...@@ -41,6 +41,8 @@ Semester.delete_all ...@@ -41,6 +41,8 @@ Semester.delete_all
semester = Semester.create! season: 'Fall', year: 2018 semester = Semester.create! season: 'Fall', year: 2018
semester.save! semester.save!
all_sections = []
total.each do |subject, sections| total.each do |subject, sections|
puts "Adding courses for #{subject}..." puts "Adding courses for #{subject}..."
sections.each do |section| sections.each do |section|
...@@ -49,6 +51,23 @@ total.each do |subject, sections| ...@@ -49,6 +51,23 @@ total.each do |subject, sections|
next next
end end
section_name = "#{section[:subj]} #{section[:course_number]} #{section[:section]}"
all_sections.push({
name: section_name,
crn: section[:crn],
section_type: section[:type],
title: section[:title],
instructor: section[:instructor],
start_date: section[:start_date],
end_date: section[:end_date],
days: section[:days],
start_time: section[:start_time],
end_time: section[:end_time],
location: section[:location],
course: course
})
# Find or create a course and set its semester # Find or create a course and set its semester
# TODO: this breaks when you try to do more than one semester, # TODO: this breaks when you try to do more than one semester,
# since just the subject + course_number do not uniquely identify a course # since just the subject + course_number do not uniquely identify a course
...@@ -58,25 +77,12 @@ total.each do |subject, sections| ...@@ -58,25 +77,12 @@ total.each do |subject, sections|
course.semester = semester course.semester = semester
course.save! course.save!
section_name = "#{section[:subj]} #{section[:course_number]} #{section[:section]}"
# puts "Adding #{section_name}..." # puts "Adding #{section_name}..."
CourseSection.create!(name: section_name,
crn: section[:crn],
section_type: section[:type],
title: section[:title],
instructor: section[:instructor],
start_date: section[:start_date],
end_date: section[:end_date],
days: section[:days],
start_time: section[:start_time],
end_time: section[:end_time],
location: section[:location],
course: course)
end end
end end
CourseSection.create!(all_sections)
# create closures for the days there will be no classes # create closures for the days there will be no classes
# see: https://registrar.gmu.edu/calendars/fall-2018/ # see: https://registrar.gmu.edu/calendars/fall-2018/
Closure.create! date: Date.new(2018, 9, 3), semester: semester Closure.create! date: Date.new(2018, 9, 3), semester: semester
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment