<commit_before>require 'interpipe/interactor'
require 'kosapi_client'
require 'sirius/kosapi_client_registry'

class FetchParallelStudents
  include Interpipe::Interactor

  def setup(client: nil)
    @forced_client = client
  end

  def perform(parallels:, faculty_semester:, **options)
    @kosapi_client = get_kosapi_client(faculty_semester)
    students = parallels.map do |parallel|
      [parallel, fetch_students(parallel)]
    end
    @students = Hash[students]
  end

  def results
    {students: @students}
  end

  def fetch_students(parallel)
    @kosapi_client.parallels.find(parallel.id).students.limit(100).offset(0)
  end

  private
  def get_kosapi_client(faculty_semester)
    @forced_client || Sirius::KOSapiClientRegistry.instance.client_for_faculty(faculty_semester.faculty)
  end

end<commit_msg>Refactor FetchParallelStudents interactor.<commit_after>require 'interpipe/interactor'
require 'kosapi_client'
require 'sirius/kosapi_client_registry'

class FetchParallelStudents
  include Interpipe::Interactor

  def setup(client: nil)
    @forced_client = client
  end

  def perform(parallels:, faculty_semester:, **options)
    client = kosapi_client(faculty_semester)
    students = parallels.map do |parallel|
      [parallel, fetch_students(parallel, client)]
    end
    @students = Hash[students]
  end

  def results
    {students: @students}
  end

  def fetch_students(parallel, client)
    client.parallels.find(parallel.id).students.limit(100).offset(0)
  end

  private
  def kosapi_client(faculty_semester)
    @forced_client || Sirius::KOSapiClientRegistry.instance.client_for_faculty(faculty_semester.faculty)
  end

end
{'fraction_non_alphanumeric': 0.08992154496077248, 'fraction_numerical': 0.004828002414001207, 'mean_word_length': 5.095588235294118, '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': '3820955', 'n_tokens_mistral': 581, 'n_tokens_neox': 554, 'n_words': 99}