<commit_before>class Parallel < Sequel::Model

  many_to_one :course
  one_to_many :timetable_slots

  DB_KEYS = [:id, :code, :capacity, :occupied, :semester, :teacher]

  def self.from_kosapi(kosapi_parallel)
    parallel_hash = kosapi_parallel.to_hash
    parallel_hash[:id] = parallel_hash[:link].href.split('/').last
    parallel_hash = parallel_hash.select { |key,_| DB_KEYS.include? key }

    Parallel.unrestrict_primary_key
    parallel = self.new(parallel_hash)
    parallel.save
    kosapi_parallel.timetable_slots.each do |slot|
      TimetableSlot.from_kosapi(slot, parallel_hash)
    end
    parallel
  end

  def generate_events(time_converter, calendar_planner)
    teaching_times = teaching_times(time_converter)
    event_periods = plan_calendar(teaching_times, calendar_planner)
    create_events(event_periods)
  end

  private
  def teaching_times(time_converter)
    timetable_slots.map do |slot|
      teaching_period = time_converter.convert_time(slot.first_hour, slot.duration)
      Sirius::TeachingTime.new(teaching_period: teaching_period, day: slot.day, parity: slot.parity)
    end
  end

  def plan_calendar(teaching_times, calendar_planner)
    teaching_times.map{ |tt| tt.plan_calendar(calendar_planner) }.flatten
  end

  def create_events(event_periods)
    factory = Sirius::EventFactory.new
    event_periods.map { |period| factory.build_event(period) }
  end

end<commit_msg>Cleaned up Parallel.from_kosapi.<commit_after>class Parallel < Sequel::Model

  many_to_one :course
  one_to_many :timetable_slots

  class << self

    DB_KEYS = [:id, :code, :capacity, :occupied, :semester, :teacher]

    def from_kosapi(kosapi_parallel)
      parallel_hash = get_attr_hash(kosapi_parallel)
      parallel = create_parallel(parallel_hash)
      process_slots(kosapi_parallel)
      parallel
    end

    def get_attr_hash(kosapi_parallel)
      parallel_hash = kosapi_parallel.to_hash
      parallel_hash[:id] = parallel_hash[:link].id
      parallel_hash.select { |key,_| DB_KEYS.include? key }
    end

    def create_parallel(attr_hash)
      Parallel.unrestrict_primary_key
      parallel = self.new(attr_hash)
      parallel.save
    end

    def process_slots(kosapi_parallel)
      kosapi_parallel.timetable_slots.each do |slot|
        TimetableSlot.from_kosapi(slot, kosapi_parallel)
      end
    end
  end



  def generate_events(time_converter, calendar_planner)
    teaching_times = teaching_times(time_converter)
    event_periods = plan_calendar(teaching_times, calendar_planner)
    create_events(event_periods)
  end

  private
  def teaching_times(time_converter)
    timetable_slots.map do |slot|
      teaching_period = time_converter.convert_time(slot.first_hour, slot.duration)
      Sirius::TeachingTime.new(teaching_period: teaching_period, day: slot.day, parity: slot.parity)
    end
  end

  def plan_calendar(teaching_times, calendar_planner)
    teaching_times.map{ |tt| tt.plan_calendar(calendar_planner) }.flatten
  end

  def create_events(event_periods)
    factory = Sirius::EventFactory.new
    event_periods.map { |period| factory.build_event(period) }
  end




end
{'fraction_non_alphanumeric': 0.08394510054261091, 'fraction_numerical': 0.0, 'mean_word_length': 4.339011925042589, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '475514', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1052, 'n_words': 179}