load_course_ratings.rb 937 Bytes
Newer Older
Zac Wood's avatar
Zac Wood committed
1 2
require 'json'

Zac Wood's avatar
Zac Wood committed
3
[['sp19', 'Spring', '2019'], ['sp18', 'Spring', '2018'], ['sm18', 'Summer', '2018'], ['f18', 'Fall', '2018'],
Zac Wood's avatar
Zac Wood committed
4 5
 ['sp17', 'Spring', '2017'], ['sm17', 'Summer', '2017'], ['f17', 'Fall', '2017'],
 ['sp16', 'Spring', '2016'], ['sm16', 'Summer', '2016'], ['f16', 'Fall', '2016']].each do |arr|
6 7 8 9 10
  begin
    ratings = JSON.parse(File.read("db/data/#{arr[0]}.json"))
  rescue StandardError
    next
  end
Zac Wood's avatar
Zac Wood committed
11 12
  semester = Semester.find_by(season: arr[1], year: arr[2])
  next if semester.nil?
Zac Wood's avatar
Zac Wood committed
13

Zac Wood's avatar
Zac Wood committed
14
  puts "Loading #{arr[1]} #{arr[2]} course ratings..."
15

Zac Wood's avatar
Zac Wood committed
16 17 18 19 20 21 22 23 24 25 26
  ratings.each do |section, qs|
    section = section.split(',').first
    subj = section.match(/[A-Z]+/)[0]
    course = section.match(/[0-9]{3} /)[0].strip
    sect_num = section.match(/ [A-Z0-9]+/)[0].strip
    name = "#{subj} #{course} #{sect_num}"
    s = CourseSection.find_by(name: name, semester: semester)
    next if s.nil?
    s.rating_questions = qs
    s.save!
  end
Zac Wood's avatar
Zac Wood committed
27
end