lecture-attendance-manager/app/models/lecture.rb

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.hour
end
def is_live?
live_video_url.present? && start_time.past? && end_time.future?
end
end