You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: watch_statistics_concern.rb
    path of file: ./repos/coursemology2/app/models/concerns/course/video
    
    the code of the file until where you have to start completion: # frozen_string_literal: true
module Course::Video::WatchStatisticsConcern
  extend ActiveSupport
    
  def start_and_end_times
    video_duration = (is_a? Course::Video) ? duration : video.duration
    result = { start: [], end: [] }
    relevant_events_scope.all_start_and_end_events.to_a.group_by { |d| d[:session_id] }.each do |_, session_events|
      session_intervals = filter_interval_events(session_events, video_duration)
      result[:start] += session_intervals[:start]
      result[:end] += session_intervals[:end]
    end
    result.transform_values(&:sort)
  end