Update lecture properties and various migration changes
Modified code to remove 'status' field from lecture's table and added 'event_uuid' field. Also refined the 'start_time' field in recordings' table to handle datetime instead of strings. Further, made minor changes in scraping jobs and seeding logic. Implemented these changes to allow lectures to be associated with calendar events and streamlined various fields.
This commit is contained in:
@@ -11,6 +11,7 @@ class CourseDashboard < Administrate::BaseDashboard
|
||||
id: Field::Number,
|
||||
lectures: Field::HasMany,
|
||||
panopto_folders: Field::String.with_options(searchable: false),
|
||||
semester_start_date: Field::Date,
|
||||
title: Field::String,
|
||||
toggl_project: Field::Number,
|
||||
unit_code: Field::String,
|
||||
@@ -27,7 +28,7 @@ class CourseDashboard < Administrate::BaseDashboard
|
||||
id
|
||||
lectures
|
||||
panopto_folders
|
||||
title
|
||||
semester_start_date
|
||||
].freeze
|
||||
|
||||
# SHOW_PAGE_ATTRIBUTES
|
||||
@@ -36,6 +37,7 @@ class CourseDashboard < Administrate::BaseDashboard
|
||||
id
|
||||
lectures
|
||||
panopto_folders
|
||||
semester_start_date
|
||||
title
|
||||
toggl_project
|
||||
unit_code
|
||||
@@ -49,6 +51,7 @@ class CourseDashboard < Administrate::BaseDashboard
|
||||
FORM_ATTRIBUTES = %i[
|
||||
lectures
|
||||
panopto_folders
|
||||
semester_start_date
|
||||
title
|
||||
toggl_project
|
||||
unit_code
|
||||
|
||||
@@ -11,9 +11,9 @@ class LectureDashboard < Administrate::BaseDashboard
|
||||
id: Field::Number,
|
||||
attendance: Field::HasOne,
|
||||
course: Field::BelongsTo,
|
||||
recording_id: Field::String,
|
||||
event_uuid: Field::String,
|
||||
recording: Field::BelongsTo,
|
||||
start_time: Field::DateTime,
|
||||
status: Field::Select.with_options(searchable: false, collection: ->(field) { field.resource.class.send(field.attribute.to_s.pluralize).keys }),
|
||||
title: Field::String,
|
||||
created_at: Field::DateTime,
|
||||
updated_at: Field::DateTime,
|
||||
@@ -28,7 +28,7 @@ class LectureDashboard < Administrate::BaseDashboard
|
||||
id
|
||||
attendance
|
||||
course
|
||||
recording_id
|
||||
event_uuid
|
||||
].freeze
|
||||
|
||||
# SHOW_PAGE_ATTRIBUTES
|
||||
@@ -37,9 +37,9 @@ class LectureDashboard < Administrate::BaseDashboard
|
||||
id
|
||||
attendance
|
||||
course
|
||||
recording_id
|
||||
event_uuid
|
||||
recording
|
||||
start_time
|
||||
status
|
||||
title
|
||||
created_at
|
||||
updated_at
|
||||
@@ -51,9 +51,9 @@ class LectureDashboard < Administrate::BaseDashboard
|
||||
FORM_ATTRIBUTES = %i[
|
||||
attendance
|
||||
course
|
||||
recording_id
|
||||
event_uuid
|
||||
recording
|
||||
start_time
|
||||
status
|
||||
title
|
||||
].freeze
|
||||
|
||||
|
||||
@@ -1,21 +1,71 @@
|
||||
class ScrapeCalendarJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def clean_up_lecture_title(unit_code, short_lecture_title) end
|
||||
|
||||
def perform(*args)
|
||||
ics_file = HTTParty.get("https://mytimetable.bath.ac.uk/ical?6519757b&group=false&timetable=!MjAyMyFzdHVkZW50c2V0ITRDRjQ5MjlGRTg1M0Q4N0MyMDZENTVDNUQ3QTJFNzk0&eu=amMzMDkxQGJhdGguYWMudWs=&h=MiuDbRiudE_Yf7B25v2SfEuFCtmYGkFb5sAUI3yGmtY=")
|
||||
calendars = Icalendar::Calendar.parse(ics_file)
|
||||
calendar = calendars.first
|
||||
|
||||
calendar.events.each do |event|
|
||||
unit_codes = Course.all.map(&:unit_code)
|
||||
|
||||
events = calendar.events.map do |event|
|
||||
summary = event.summary
|
||||
match = summary.split('-')
|
||||
|
||||
# Handle odd events we don't care about
|
||||
return if match.length != 2
|
||||
next if match.length != 2
|
||||
|
||||
unit_code = match[0]
|
||||
short_lecture_title = match[1]
|
||||
start_time = event.dtstart
|
||||
start_time = event.dtstart.to_time
|
||||
event_uuid = event.uid.to_s
|
||||
|
||||
next if unit_code.nil? ||
|
||||
short_lecture_title.nil? ||
|
||||
event_uuid.nil? ||
|
||||
start_time.nil? ||
|
||||
!unit_code.in?(unit_codes)
|
||||
|
||||
{
|
||||
unit_code:,
|
||||
short_lecture_title:,
|
||||
start_time:,
|
||||
event_uuid:,
|
||||
}
|
||||
end
|
||||
|
||||
events
|
||||
.compact
|
||||
.filter { |attrs| attrs[:unit_code].in? unit_codes }
|
||||
.group_by { |attrs| attrs[:unit_code] }
|
||||
.map do |unit_code, course_events|
|
||||
course = Course.find_by(unit_code: unit_code)
|
||||
|
||||
lecture_counter = 0
|
||||
|
||||
course_events.each do |event|
|
||||
# Naive check to see if we've already created this lecture
|
||||
if course.lectures.find_by(event_uuid: event[:event_uuid]).present? || course.lectures.find_by(
|
||||
start_time: (event[:start_time].beginning_of_hour + 5.minutes)..(event[:start_time].beginning_of_hour + 1.hour + 5.minutes)
|
||||
).present?
|
||||
next
|
||||
end
|
||||
|
||||
if event[:short_lecture_title].starts_with? "Lec"
|
||||
lecture_counter += 1
|
||||
title = "Lecture #{lecture_counter}"
|
||||
else
|
||||
title = event[:short_lecture_title]
|
||||
end
|
||||
|
||||
course.lectures.create!(
|
||||
title: title,
|
||||
start_time: event[:start_time],
|
||||
event_uuid: event[:event_uuid],
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,13 +27,22 @@ class ScrapePanoptoJob < ApplicationJob
|
||||
|
||||
created.each do |new_recording_attrs|
|
||||
new_recording = Recording.new(new_recording_attrs)
|
||||
Lecture.create!(
|
||||
title: new_recording.nice_title,
|
||||
start_time: new_recording.start_time,
|
||||
course_id: new_recording.course_id,
|
||||
status: :undetermined,
|
||||
recording_id: new_recording.id
|
||||
)
|
||||
|
||||
# Find existing lecture to associate with this recording
|
||||
if (lecture = course.lectures.find_by(
|
||||
start_time: new_recording.start_time.beginning_of_hour + 15.minutes,
|
||||
recording_id: nil,
|
||||
))
|
||||
lecture.update!(recording_id: new_recording.id)
|
||||
else
|
||||
# Else create a new lecture
|
||||
Lecture.create!(
|
||||
title: new_recording.nice_title,
|
||||
start_time: new_recording.start_time,
|
||||
course_id: new_recording.course_id,
|
||||
recording_id: new_recording.id
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,15 +3,6 @@ class Lecture < ApplicationRecord
|
||||
has_one :attendance
|
||||
belongs_to :recording, optional: true
|
||||
|
||||
enum :status, [
|
||||
:undetermined,
|
||||
:future,
|
||||
:happening_now,
|
||||
:attended_in_person,
|
||||
:watched_recording,
|
||||
:missed,
|
||||
], default: :undetermined
|
||||
|
||||
def week_number
|
||||
((start_time.beginning_of_week - course.semester_start_date.to_time) / 1.week).floor + 1
|
||||
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.recording.nice_title %>
|
||||
<%= lecture.title %>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||
<%= lecture.start_time.to_fs(:dmy) %>
|
||||
|
||||
Reference in New Issue
Block a user