<commit_before>class SerializeVitallySalesAccount

  def initialize(school)
    @school = school
  end

  def data
    {
      accountId: @school.id.to_s,
      # Type is used by Vitally to determine which data type the payload contains in batches
      type: 'account',
      # Vitally requires a unique messageId for dedupication purposes
      messageId: SecureRandom.uuid,
      traits: {
        name: @school.name,
        address: @school.street,
        city: @school.city,
        state: @school.state,
        zipcode: @school.zipcode,
        district: @school.leanm,
        phone: @school.phone,
        charter: @school.charter,
        frl: @school.free_lunches,
        ppin: @school.ppin,
        nces_id: @school.nces_id,
        school_subscription: school_subscription,
        school_type: @school.ulocal_to_school_type,
        employee_count: employee_count,
        paid_teacher_subscriptions: paid_teacher_subscriptions,
        active_students: active_students,
        activities_finished: activities_finished,
        activities_per_student: activities_per_student,
        school_link: school_link,
        created_at: @school.created_at,
        premium_expiry_date: subscription_expiration_date,
        last_active: last_active
      }
    }
  end

  private def activities_per_student
    if active_students > 0
      (activities_finished.to_f / active_students).round(2)
    else
      0
    end
  end

  private def active_students
    @active_students ||= ActivitySession.select(:user_id).distinct
      .joins(classroom_unit: {classroom: {teachers: :school}})
      .where(state: 'finished')
      .where('schools.id = ?', @school.id)
      .count
  end

  private def activities_finished
    @activities_finished ||= ClassroomsTeacher
      .joins(user: :school, classroom: :activity_sessions)
        .where('schools.id = ?', @school.id)
        .where('activity_sessions.state = ?', 'finished')
        .count
  end

  private def school_subscription
    if @school.subscription
      @school.subscription.account_type
    else
      'NA'
    end
  end

  private def employee_count
    @school.users.where(role: 'teacher').count || 0
  end

  private def paid_teacher_subscriptions
    School.joins(users: :subscriptions)
      .where(id: @school.id)
      .where('subscriptions.account_type = ?', 'Teacher Paid')
      .count
  end

  private def school_link
    "https://www.quill.org/cms/schools/#{@school.id}"
  end

  private def subscription_expiration_date
    @school&.subscription&.expiration || 'NA'
  end

  private def last_active
    @school.users.maximum(:last_sign_in)
    School.joins(users: {classrooms_i_teach: :activity_sessions})
          .where(id: @school.id)
          .maximum(:completed_at)
  end
end<commit_msg>Remove an extraneous leftover line<commit_after>class SerializeVitallySalesAccount

  def initialize(school)
    @school = school
  end

  def data
    {
      accountId: @school.id.to_s,
      # Type is used by Vitally to determine which data type the payload contains in batches
      type: 'account',
      # Vitally requires a unique messageId for dedupication purposes
      messageId: SecureRandom.uuid,
      traits: {
        name: @school.name,
        address: @school.street,
        city: @school.city,
        state: @school.state,
        zipcode: @school.zipcode,
        district: @school.leanm,
        phone: @school.phone,
        charter: @school.charter,
        frl: @school.free_lunches,
        ppin: @school.ppin,
        nces_id: @school.nces_id,
        school_subscription: school_subscription,
        school_type: @school.ulocal_to_school_type,
        employee_count: employee_count,
        paid_teacher_subscriptions: paid_teacher_subscriptions,
        active_students: active_students,
        activities_finished: activities_finished,
        activities_per_student: activities_per_student,
        school_link: school_link,
        created_at: @school.created_at,
        premium_expiry_date: subscription_expiration_date,
        last_active: last_active
      }
    }
  end

  private def activities_per_student
    if active_students > 0
      (activities_finished.to_f / active_students).round(2)
    else
      0
    end
  end

  private def active_students
    @active_students ||= ActivitySession.select(:user_id).distinct
      .joins(classroom_unit: {classroom: {teachers: :school}})
      .where(state: 'finished')
      .where('schools.id = ?', @school.id)
      .count
  end

  private def activities_finished
    @activities_finished ||= ClassroomsTeacher
      .joins(user: :school, classroom: :activity_sessions)
        .where('schools.id = ?', @school.id)
        .where('activity_sessions.state = ?', 'finished')
        .count
  end

  private def school_subscription
    if @school.subscription
      @school.subscription.account_type
    else
      'NA'
    end
  end

  private def employee_count
    @school.users.where(role: 'teacher').count || 0
  end

  private def paid_teacher_subscriptions
    School.joins(users: :subscriptions)
      .where(id: @school.id)
      .where('subscriptions.account_type = ?', 'Teacher Paid')
      .count
  end

  private def school_link
    "https://www.quill.org/cms/schools/#{@school.id}"
  end

  private def subscription_expiration_date
    @school&.subscription&.expiration || 'NA'
  end

  private def last_active
    School.joins(users: {classrooms_i_teach: :activity_sessions})
          .where(id: @school.id)
          .maximum(:completed_at)
  end
end
{'fraction_non_alphanumeric': 0.09461899602744674, 'fraction_numerical': 0.001444564824846515, 'mean_word_length': 2.8680167597765363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '828682', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1715, 'n_words': 358}