<commit_before>namespace :analytics do
  desc 'Count number of articles edited per cohort'
  task articles_edited: 'batch:setup_logger' do
    Cohort.all.each do |cohort|
      course_ids = cohort.courses.pluck(:id)
      student_ids = CoursesUsers
                    .where(course_id: course_ids, role: 0)
                    .pluck(:user_id).uniq
      revisions = Revision.where(user_id: student_ids)
      revision_ids = revisions.pluck(:id)
      page_ids = revisions.pluck(:article_id).uniq
      article_ids = Article.where(namespace: 0, id: page_ids).pluck(:id)
      upload_ids = CommonsUpload.where(user_id: student_ids).pluck(:id)
      used_uploads = CommonsUpload.where(id: upload_ids).where('usage_count > 0')
      used_count = used_uploads.count
      usage_count = used_uploads.sum(:usage_count)
      pp "#{cohort.slug}:"
      pp "    #{student_ids.count} students"
      pp "    #{revision_ids.count} revisions"
      pp "    #{article_ids.count} articles edited"
      pp "    #{upload_ids.count} files uploaded"
      pp "    #{used_count} files in use"
      pp "    #{usage_count} global usages"
    end
  end
end<commit_msg>Fix output of analytics rake task.<commit_after>namespace :analytics do
  desc 'Count number of articles edited per cohort'
  task articles_edited: 'batch:setup_logger' do
    Cohort.all.each do |cohort|
      course_ids = cohort.courses.pluck(:id)
      student_ids = CoursesUsers
                    .where(course_id: course_ids, role: 0)
                    .pluck(:user_id).uniq
      revisions = Revision.where(user_id: student_ids)
      revision_ids = revisions.pluck(:id)
      page_ids = revisions.pluck(:article_id).uniq
      article_ids = Article.where(namespace: 0, id: page_ids).pluck(:id)
      upload_ids = CommonsUpload.where(user_id: student_ids).pluck(:id)
      used_uploads = CommonsUpload.where(id: upload_ids).where('usage_count > 0')
      used_count = used_uploads.count
      usage_count = used_uploads.sum(:usage_count)
      Rails.logger.info "#{cohort.slug}:"
      Rails.logger.info "    #{student_ids.count} students"
      Rails.logger.info "    #{revision_ids.count} revisions"
      Rails.logger.info "    #{article_ids.count} articles edited"
      Rails.logger.info "    #{upload_ids.count} files uploaded"
      Rails.logger.info "    #{used_count} files in use"
      Rails.logger.info "    #{usage_count} global usages"
    end
  end
end
{'fraction_non_alphanumeric': 0.11088211046990931, 'fraction_numerical': 0.00247320692497939, 'mean_word_length': 3.0115702479338844, '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': '7453057', 'n_tokens_mistral': 814, 'n_tokens_neox': 783, 'n_words': 160}