Stash
This commit is contained in:
parent
69a97a3fa9
commit
9923067a17
@ -13,18 +13,17 @@ class ScrapePanoptoJob < ApplicationJob
|
|||||||
def scrape_course(course)
|
def scrape_course(course)
|
||||||
panopto_folder_ids = course.panopto_folders
|
panopto_folder_ids = course.panopto_folders
|
||||||
panopto_folder_ids.each do |folder_id|
|
panopto_folder_ids.each do |folder_id|
|
||||||
lectures_data = Panopto::list_folder folder_id
|
recording_data = Panopto::list_folder folder_id
|
||||||
attributes = lectures_data.map do |lecture_data|
|
attributes = recording_data.map do |lecture_data|
|
||||||
{
|
{
|
||||||
title: lecture_data['title'],
|
title: lecture_data['title'],
|
||||||
start_time: Time.new(lecture_data['start_time']),
|
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,
|
course_id: course.id,
|
||||||
status: :undetermined
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
Lecture.insert_all(attributes, unique_by: :recording_id)
|
Recording.insert_all(attributes, unique_by: :recording_uuid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
class Lecture < ApplicationRecord
|
class Lecture < ApplicationRecord
|
||||||
belongs_to :course
|
belongs_to :course
|
||||||
has_one :attendance
|
has_one :attendance
|
||||||
|
belongs_to :recording
|
||||||
|
|
||||||
enum :status, [
|
enum :status, [
|
||||||
:undetermined,
|
:undetermined,
|
||||||
@ -12,26 +13,10 @@ class Lecture < ApplicationRecord
|
|||||||
], default: :undetermined
|
], default: :undetermined
|
||||||
|
|
||||||
def week_number
|
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
|
end
|
||||||
|
|
||||||
def live_video_url
|
def live_video_url
|
||||||
nil
|
nil
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@ -1,3 +1,20 @@
|
|||||||
|
# This is a Foreign Object Reference Table, keyed to the external data source by #recording_uuid
|
||||||
class Recording < ApplicationRecord
|
class Recording < ApplicationRecord
|
||||||
belongs_to :course
|
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
|
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 %>
|
<% style = if lecture.start_time.future? then 'background: repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 10px, white 10px, white 20px);' else '' end %>
|
||||||
<tr style="<%= style %>">
|
<tr style="<%= style %>">
|
||||||
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6">
|
<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>
|
||||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||||
<%= lecture.start_time.to_fs(:dmy) %>
|
<%= lecture.start_time.to_fs(:dmy) %>
|
||||||
@ -59,7 +59,7 @@
|
|||||||
Start
|
Start
|
||||||
</button>
|
</button>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to "Open recording", lecture.recording_url %>
|
<%= link_to "Open recording", lecture.recording.recording_url %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
1
config/initializers/constants.rb
Normal file
1
config/initializers/constants.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
START_OF_YEAR_5_SEMESTER_1 = Time.new('2023-10-02')
|
||||||
@ -8,5 +8,7 @@ class CreateRecordings < ActiveRecord::Migration[7.0]
|
|||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index :recordings, :recording_uuid, unique: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
6
db/migrate/20231001163055_add_recording_id_to_lecture.rb
Normal file
6
db/migrate/20231001163055_add_recording_id_to_lecture.rb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class AddRecordingIdToLecture < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
remove_column :lectures, :recording_id
|
||||||
|
add_belongs_to :lectures, :recording
|
||||||
|
end
|
||||||
|
end
|
||||||
7
db/schema.rb
generated
7
db/schema.rb
generated
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2023_10_01_161500) do
|
ActiveRecord::Schema[7.0].define(version: 2023_10_01_163055) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
@ -36,12 +36,12 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_01_161500) do
|
|||||||
t.string "title", null: false
|
t.string "title", null: false
|
||||||
t.datetime "start_time", null: false
|
t.datetime "start_time", null: false
|
||||||
t.integer "status", default: 0, null: false
|
t.integer "status", default: 0, null: false
|
||||||
t.string "recording_id", null: false
|
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.bigint "course_id"
|
t.bigint "course_id"
|
||||||
|
t.bigint "recording_id"
|
||||||
t.index ["course_id"], name: "index_lectures_on_course_id"
|
t.index ["course_id"], name: "index_lectures_on_course_id"
|
||||||
t.index ["recording_id"], name: "index_lectures_on_recording_id", unique: true
|
t.index ["recording_id"], name: "index_lectures_on_recording_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "recordings", force: :cascade do |t|
|
create_table "recordings", force: :cascade do |t|
|
||||||
@ -52,6 +52,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_01_161500) do
|
|||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.index ["course_id"], name: "index_recordings_on_course_id"
|
t.index ["course_id"], name: "index_recordings_on_course_id"
|
||||||
|
t.index ["recording_uuid"], name: "index_recordings_on_recording_uuid", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
add_foreign_key "attendances", "lectures"
|
add_foreign_key "attendances", "lectures"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user