<commit_before># frozen_string_literal: true

require_dependency "#{Rails.root}/lib/word_count"

#= Utilities for calcuating statistics for course activity
class CourseStatistics
  ################
  # Entry points #
  ################

  def initialize(course_ids, opts = {})
    @course_ids = course_ids
    @opts = opts
    find_contribution_ids
    find_upload_usage
    find_user_counts
    find_article_counts
  end

  # For a set of course ids, generate a human-readable summary of what the users
  # in those courses contributed.
  def report_statistics
    report = {
      course_count: @course_ids.uniq.count,
      students_excluding_instructors: @pure_student_ids.count,
      trained_students: @trained_student_count,
      characters_added: @characters_added,
      words_added: @words_added,
      revisions: @revision_ids.count,
      articles_edited: @article_ids.count,
      articles_created: @surviving_article_ids.count,
      articles_deleted: @deleted_article_ids.count,
      file_uploads: @upload_ids.count,
      files_in_use: @used_count,
      global_usages: @usage_count
    }

    report = { @opts[:campaign].to_sym => report } if @opts[:campaign]
    report
  end<commit_msg>Add page views to the 'campaign intersection' tool<commit_after># frozen_string_literal: true

require_dependency "#{Rails.root}/lib/word_count"

#= Utilities for calcuating statistics for course activity
class CourseStatistics
  ################
  # Entry points #
  ################

  def initialize(course_ids, opts = {})
    @course_ids = course_ids
    @opts = opts
    find_contribution_ids
    find_upload_usage
    find_user_counts
    find_article_counts
  end

  # For a set of course ids, generate a human-readable summary of what the users
  # in those courses contributed.
  def report_statistics
    report = {
      course_count: @course_ids.uniq.count,
      students_excluding_instructors: @pure_student_ids.count,
      trained_students: @trained_student_count,
      characters_added: @characters_added,
      words_added: @words_added,
      revisions: @revision_ids.count,
      articles_edited: @article_ids.count,
      articles_created: @surviving_article_ids.count,
      articles_deleted: @deleted_article_ids.count,
      file_uploads: @upload_ids.count,
      files_in_use: @used_count,
      global_usages: @usage_count,
      cumulative_page_views_estimate: Course.where(id: @course_ids).sum(:view_sum)
    }

    report = { @opts[:campaign].to_sym => report } if @opts[:campaign]
    report
  end
{'fraction_non_alphanumeric': 0.10295857988165681, 'fraction_numerical': 0.0, 'mean_word_length': 3.9628180039138945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4103886', 'n_tokens_mistral': 809, 'n_tokens_neox': 777, 'n_words': 169}