lecture-attendance-manager/app/models/lecture.rb
Joshua Coles 4c2272b1f0
All checks were successful
Build and Publish Docker Container / build (push) Successful in 5m44s
Fix regression in lecture ordering, add time of lecture on hover, fix lecture duration using hours instead of minutes
The update includes modifications in the lectures' order by start_time in course model. The lecture duration is now correctly calculated by minutes instead of hours. Additionally, in the lecture view, an online indicator is added for each lecture and popover is implemented to show the lecture start and end times..
2024-02-04 15:37:56 +00:00

51 lines
1.1 KiB
Ruby

class Lecture < ApplicationRecord
belongs_to :course
has_one :recording, dependent: :nullify
has_many :tracked_time_entries, dependent: :destroy, as: :subject
enum :kind, [
:lecture,
:problems_class,
], default: :lecture
include Trackable, CourseItem
def prepared?
tracked_time_entries.where(kind: [:preparation]).any?
end
def attended?
tracked_time_entries.where(kind: [:concurrent, :catchup]).any?
end
def entirely_attended_in_person?
!(tracked_time_entries.where(kind: [:catchup]).any?)
end
def reviewed?
tracked_time_entries.where(kind: [:review]).any?
end
def total_preparation_time
tracked_time_entries.preparation.sum(&:duration).seconds
end
def total_attendance_time
tracked_time_entries.where(kind: [:concurrent, :catchup]).sum(&:duration).seconds
end
def total_review_time
tracked_time_entries.review.sum(&:duration).seconds
end
# NAIVE: Assumes that lectures are 50 minutes long, this is true currently but not assured.
def end_time
start_time + 50.minutes
end
def is_live?
live_video_url.present? && start_time.past? && end_time.future?
end
end