<commit_before>require 'celluloid'
require 'sirius/kosapi_client_registry'
require 'actors/etl_producer'
require 'actors/etl_consumer'

# Loads teacher timetables from KOSapi.
class TimetableSource
  include Celluloid
  include ETLProducer
  include ETLConsumer

  def initialize(input, output, faculty_semester)
    set_input(input)
    set_output(output)
    @faculty = faculty_semester.faculty
    @timetables = [].each
  end

  # Teacher username is expected as a row
  def process_row(username)
    logger.debug "Processing #{username}"
    timetables = fetch_timetable(username)
    @timetables = timetables.each
    @username = username
    logger.debug "Finished processing #{username}"
    produce_row if buffer_empty?
  end

  def produce_row_iterable
    output_row([@timetables.next, @username])
  end

  private

  def fetch_timetable(username)
    logger.debug "Fetching #{username}"
    client = Sirius::KOSapiClientRegistry.instance.client_for_faculty(@faculty)
    client.teachers.find(username).timetable
  end
end<commit_msg>Fetch teacher timetable slots for relevant semester instead of current one<commit_after>require 'celluloid'
require 'sirius/kosapi_client_registry'
require 'actors/etl_producer'
require 'actors/etl_consumer'

# Loads teacher timetables from KOSapi.
class TimetableSource
  include Celluloid
  include ETLProducer
  include ETLConsumer

  def initialize(input, output, faculty_semester)
    set_input(input)
    set_output(output)
    @faculty_semester = faculty_semester
    @timetables = [].each
  end

  # Teacher username is expected as a row
  def process_row(username)
    logger.debug "Processing #{username}"
    timetables = fetch_timetable(username)
    @timetables = timetables.each
    @username = username
    logger.debug "Finished processing #{username}"
    produce_row if buffer_empty?
  end

  def produce_row_iterable
    output_row([@timetables.next, @username])
  end

  private

  def fetch_timetable(username)
    logger.debug "Fetching #{username}"
    client = Sirius::KOSapiClientRegistry.instance.client_for_faculty(@faculty_semester.faculty)
    client.teachers.find(username).timetable(semester: @faculty_semester.code)
  end
end
{'fraction_non_alphanumeric': 0.07950931394820536, 'fraction_numerical': 0.0, 'mean_word_length': 4.749347258485639, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1184775', 'n_tokens_mistral': 715, 'n_tokens_neox': 684, 'n_words': 158}