Stash
This commit is contained in:
@@ -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
|
||||
|
||||
+2
-17
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 %>
|
||||
<tr style="<%= style %>">
|
||||
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6">
|
||||
<%= lecture.nice_title %>
|
||||
<%= lecture.recording.nice_title %>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||
<%= lecture.start_time.to_fs(:dmy) %>
|
||||
@@ -59,7 +59,7 @@
|
||||
Start
|
||||
</button>
|
||||
<% else %>
|
||||
<%= link_to "Open recording", lecture.recording_url %>
|
||||
<%= link_to "Open recording", lecture.recording.recording_url %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user