diff --git a/app/jobs/scrape_panopto_job.rb b/app/jobs/scrape_panopto_job.rb index 8887c16..cb9fc4b 100644 --- a/app/jobs/scrape_panopto_job.rb +++ b/app/jobs/scrape_panopto_job.rb @@ -13,18 +13,17 @@ class ScrapePanoptoJob < ApplicationJob def scrape_course(course) panopto_folder_ids = course.panopto_folders panopto_folder_ids.each do |folder_id| - lectures_data = Panopto::list_folder folder_id - attributes = lectures_data.map do |lecture_data| + recording_data = Panopto::list_folder folder_id + attributes = recording_data.map do |lecture_data| { title: lecture_data['title'], start_time: Time.new(lecture_data['start_time']), - recording_id: lecture_data['panopto_delivery_id'], + recording_uuid: lecture_data['panopto_delivery_id'], course_id: course.id, - status: :undetermined } end - Lecture.insert_all(attributes, unique_by: :recording_id) + Recording.insert_all(attributes, unique_by: :recording_uuid) end end end diff --git a/app/models/lecture.rb b/app/models/lecture.rb index 7e36de5..ee5d000 100644 --- a/app/models/lecture.rb +++ b/app/models/lecture.rb @@ -1,6 +1,7 @@ class Lecture < ApplicationRecord belongs_to :course has_one :attendance + belongs_to :recording enum :status, [ :undetermined, @@ -12,26 +13,10 @@ class Lecture < ApplicationRecord ], default: :undetermined def week_number - ((start_time.beginning_of_week - Time.new('2023-10-02')) / 1.week).floor + ((start_time.beginning_of_week - START_OF_YEAR_5_SEMESTER_1) / 1.week).floor end def live_video_url nil end - - def recording_url - return nil if recording_id.nil? - - "https://uniofbath.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=#{recording_id}" - end - - def nice_title - if course.title == "General Relativity" - regex = /.+L(\d+).*/ - lecture_number = self.title.match(regex)[1].to_i - return "Lecture #{lecture_number}" - end - - title - end end diff --git a/app/models/recording.rb b/app/models/recording.rb index 4ffcd7c..dac26ae 100644 --- a/app/models/recording.rb +++ b/app/models/recording.rb @@ -1,3 +1,20 @@ +# This is a Foreign Object Reference Table, keyed to the external data source by #recording_uuid class Recording < ApplicationRecord belongs_to :course + + def recording_url + return nil if recording_uuid.nil? + + "https://uniofbath.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=#{recording_uuid}" + end + + def nice_title + if course.title == "General Relativity" + regex = /.+L(\d+).*/ + lecture_number = self.title.match(regex)[1].to_i + return "Lecture #{lecture_number}" + end + + title + end end diff --git a/app/views/attendance_tracker/index.html.erb b/app/views/attendance_tracker/index.html.erb index 01a3ff3..14dec1b 100644 --- a/app/views/attendance_tracker/index.html.erb +++ b/app/views/attendance_tracker/index.html.erb @@ -28,7 +28,7 @@ <% style = if lecture.start_time.future? then 'background: repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 10px, white 10px, white 20px);' else '' end %>