From 998d4af4e0bd6edcbfd18c90f95bd7a8cc726233 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Tue, 17 Dec 2024 09:51:48 -0800 Subject: [PATCH] Remove features for generating CSVs of course/campaign revisions This is necessary as part of the project to deprecate the Revisions table. --- .../campaign_stats_download_modal.jsx | 6 - .../overview/course_stats_download_modal.jsx | 5 - app/controllers/analytics_controller.rb | 8 +- config/routes.rb | 1 - lib/analytics/campaign_csv_builder.rb | 13 --- lib/analytics/course_revisions_csv_builder.rb | 105 ------------------ spec/controllers/analytics_controller_spec.rb | 9 -- spec/controllers/campaigns_controller_spec.rb | 11 -- .../course_revisions_csv_builder_spec.rb | 32 ------ 9 files changed, 1 insertion(+), 189 deletions(-) delete mode 100644 lib/analytics/course_revisions_csv_builder.rb delete mode 100644 spec/lib/analytics/course_revisions_csv_builder_spec.rb diff --git a/app/assets/javascripts/components/campaign/campaign_stats_download_modal.jsx b/app/assets/javascripts/components/campaign/campaign_stats_download_modal.jsx index 92082dcffb..80369304db 100644 --- a/app/assets/javascripts/components/campaign/campaign_stats_download_modal.jsx +++ b/app/assets/javascripts/components/campaign/campaign_stats_download_modal.jsx @@ -5,7 +5,6 @@ const CampaignStatsDownloadModal = ({ campaign_slug }) => { const courseDataLink = `/campaigns/${campaign_slug}/courses.csv`; const articlesEditedLink = `/campaigns/${campaign_slug}/articles_csv.csv`; - const RevisionsLink = `/campaigns/${campaign_slug}/revisions_csv.csv`; const editorsLink = `/campaigns/${campaign_slug}/students.csv`; const editorsByCourseLink = `/campaigns/${campaign_slug}/students.csv?course=true`; const instructorsLink = `/campaigns/${campaign_slug}/instructors.csv?course=true`; @@ -32,11 +31,6 @@ const CampaignStatsDownloadModal = ({ campaign_slug }) => { {I18n.t('campaign.data_articles_info')}


-

- {I18n.t('campaign.data_revisions')} - {I18n.t('campaign.data_revisions_info')} -

-

{I18n.t('campaign.data_editor_usernames')} {I18n.t('campaign.data_editor_usernames_info')} diff --git a/app/assets/javascripts/components/overview/course_stats_download_modal.jsx b/app/assets/javascripts/components/overview/course_stats_download_modal.jsx index f7c2247eb6..cd9bd4c000 100644 --- a/app/assets/javascripts/components/overview/course_stats_download_modal.jsx +++ b/app/assets/javascripts/components/overview/course_stats_download_modal.jsx @@ -20,7 +20,6 @@ const CourseStatsDownloadModal = ({ course }) => { const uploadsCsvLink = `/course_uploads_csv?course=${course.slug}`; const studentsCsvLink = `/course_students_csv?course=${course.slug}`; const articlesCsvLink = `/course_articles_csv?course=${course.slug}`; - const revisionsCsvLink = `/course_revisions_csv?course=${course.slug}`; const wikidataCsvLink = `/course_wikidata_csv?course=${course.slug}`; let wikidataLink; @@ -61,10 +60,6 @@ const CourseStatsDownloadModal = ({ course }) => { {I18n.t('courses.data_articles_info')}


-

- {I18n.t('courses.data_revisions')} - {I18n.t('courses.data_revisions_info')} -

{wikidataLink} ); diff --git a/app/controllers/analytics_controller.rb b/app/controllers/analytics_controller.rb index 353f679640..de765ceb0b 100644 --- a/app/controllers/analytics_controller.rb +++ b/app/controllers/analytics_controller.rb @@ -6,7 +6,6 @@ require_dependency "#{Rails.root}/lib/analytics/course_uploads_csv_builder" require_dependency "#{Rails.root}/lib/analytics/course_students_csv_builder" require_dependency "#{Rails.root}/lib/analytics/course_articles_csv_builder" -require_dependency "#{Rails.root}/lib/analytics/course_revisions_csv_builder" require_dependency "#{Rails.root}/lib/analytics/course_wikidata_csv_builder" require_dependency "#{Rails.root}/lib/analytics/campaign_csv_builder" require_dependency "#{Rails.root}/lib/analytics/ungreeted_list" @@ -18,7 +17,7 @@ class AnalyticsController < ApplicationController include CourseHelper before_action :require_signed_in, only: :ungreeted before_action :set_course, only: %i[course_csv course_uploads_csv - course_students_csv course_articles_csv course_revisions_csv + course_students_csv course_articles_csv course_wikidata_csv] ######################## @@ -76,11 +75,6 @@ def course_articles_csv filename: "#{@course.slug}-articles-#{Time.zone.today}.csv" end - def course_revisions_csv - send_data CourseRevisionsCsvBuilder.new(@course).generate_csv, - filename: "#{@course.slug}-revisions-#{Time.zone.today}.csv" - end - def course_wikidata_csv send_data CourseWikidataCsvBuilder.new(@course).generate_csv, filename: "#{@course.slug}-wikidata-#{Time.zone.today}.csv" diff --git a/config/routes.rb b/config/routes.rb index 0872bbf629..ddccc8e33e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -253,7 +253,6 @@ get 'course_students_csv' => 'analytics#course_students_csv' get 'course_articles_csv' => 'analytics#course_articles_csv' get 'tagged_courses_csv/:tag' => 'analytics#tagged_courses_csv' - get 'course_revisions_csv' => 'analytics#course_revisions_csv' get 'course_wikidata_csv' => 'analytics#course_wikidata_csv' get 'all_courses_csv' => 'analytics#all_courses_csv' get 'all_courses' => 'analytics#all_courses' diff --git a/lib/analytics/campaign_csv_builder.rb b/lib/analytics/campaign_csv_builder.rb index 6705a38634..737797a772 100644 --- a/lib/analytics/campaign_csv_builder.rb +++ b/lib/analytics/campaign_csv_builder.rb @@ -3,7 +3,6 @@ require 'csv' require_dependency "#{Rails.root}/lib/analytics/course_csv_builder" require_dependency "#{Rails.root}/lib/analytics/course_articles_csv_builder" -require_dependency "#{Rails.root}/lib/analytics/course_revisions_csv_builder" require_dependency "#{Rails.root}/app/workers/campaign_csv_worker" require "#{Rails.root}/lib/analytics/course_wikidata_csv_builder" @@ -33,18 +32,6 @@ def articles_to_csv CSV.generate { |csv| csv_data.each { |line| csv << line } } end - def revisions_to_csv - csv_data = [CourseRevisionsCsvBuilder::CSV_HEADERS + ['course_slug']] - @campaign.courses.find_each do |course| - CourseRevisionsCsvBuilder.new(course).revisions_rows.each do |row| - row_with_slug = row + [course.slug] - csv_data << row_with_slug - end - end - - CSV.generate { |csv| csv_data.each { |line| csv << line } } - end - def wikidata_to_csv csv_data = [CourseWikidataCsvBuilder::CSV_HEADERS] courses = @campaign.courses diff --git a/lib/analytics/course_revisions_csv_builder.rb b/lib/analytics/course_revisions_csv_builder.rb deleted file mode 100644 index bd096b5329..0000000000 --- a/lib/analytics/course_revisions_csv_builder.rb +++ /dev/null @@ -1,105 +0,0 @@ -# frozen_string_literal: true - -require 'csv' - -class CourseRevisionsCsvBuilder - def initialize(course) - @course = course - set_revisions - end - - def generate_csv - csv_data = [CSV_HEADERS] - revisions_rows.each do |row| - csv_data << row - end - CSV.generate { |csv| csv_data.each { |line| csv << line } } - end - - def revisions_rows - @new_revisions.values.map do |revision_data| - build_row(revision_data) - end - end - - # rubocop:disable Metrics/AbcSize - def set_revisions - @new_revisions = {} - @course.revisions.includes(:wiki, :article, :user).map do |edit| - # Skip if the Article record is missing - next unless edit.article - - revision_edits = @new_revisions[edit.article_id] || new_revision(edit) - update_title_username(revision_edits, edit) - revision_edits[:mw_rev_id] = edit.mw_rev_id - revision_edits[:mw_page_id] = edit.mw_page_id - revision_edits[:wiki] = edit.wiki.domain - update_characters_references_views(revision_edits, edit) - revision_edits[:new_article] = true if edit.new_article - revision_edits[:deleted] = true if edit.deleted - revision_edits[:wp10] = edit.wp10 - revision_edits[:wp10_previous] = edit.wp10_previous - @new_revisions[edit.article_id] = revision_edits - end - end - # rubocop:enable Metrics/AbcSize - - def new_revision(edit) - article = edit.article - { - title: article.title, - new_article: false, - views: 0, - characters: {}, - references: {}, - deleted: edit.deleted, - wp10: {}, - wp10_previous: {} - } - end - - def update_title_username(revision_edits, edit) - revision_edits[:title] = edit.article.title - revision_edits[:username] = edit.user.username - end - - def update_characters_references_views(revision_edits, edit) - revision_edits[:characters] = edit.characters - revision_edits[:references] = edit.references_added - revision_edits[:views] = edit.views - end - - CSV_HEADERS = %w[ - Article_title - User - revision_id - page_id - wiki - characters_added - references_added - new - pageviews - deleted - wp10 - wp10_previous - ].freeze - - def build_row(revision_data) - row = [revision_data[:title]] - row << revision_data[:username] - row << revision_data[:mw_rev_id] - row << revision_data[:mw_page_id] - row << revision_data[:wiki] - add_characters_references(revision_data, row) - row << revision_data[:new_article] - row << revision_data[:views] - row << revision_data[:deleted] - row << revision_data[:wp10] - row << revision_data[:wp10_previous] - end - - def add_characters_references(revision_data, row) - row << revision_data[:characters] - row << revision_data[:references] - end -end diff --git a/spec/controllers/analytics_controller_spec.rb b/spec/controllers/analytics_controller_spec.rb index c5d02b0e46..a7e128bed3 100644 --- a/spec/controllers/analytics_controller_spec.rb +++ b/spec/controllers/analytics_controller_spec.rb @@ -109,15 +109,6 @@ end end - describe '#course_revisions_csv' do - let(:course) { create(:course, slug: 'foo/bar_(baz)') } - - it 'returns a CSV' do - get '/course_revisions_csv', params: { course: course.slug } - expect(response.body).to include('references_added') - end - end - describe '#course_wikidata_csv' do let(:wikidata) { Wiki.get_or_create(language: nil, project: 'wikidata') } let(:course) { create(:course, slug: 'foo/bar_(baz)', home_wiki: wikidata) } diff --git a/spec/controllers/campaigns_controller_spec.rb b/spec/controllers/campaigns_controller_spec.rb index 68d57f2306..4cd03b1275 100644 --- a/spec/controllers/campaigns_controller_spec.rb +++ b/spec/controllers/campaigns_controller_spec.rb @@ -417,17 +417,6 @@ expect(csv).to include(article.title) end - it 'return a csv of revision data' do - expect(CsvCleanupWorker).to receive(:perform_at) - get "/campaigns/#{campaign.slug}/revisions_csv", params: request_params - get "/campaigns/#{campaign.slug}/revisions_csv", params: request_params - follow_redirect! - csv = response.body.force_encoding('utf-8') - expect(csv).to include(course.slug) - expect(csv).to include(article.title) - expect(csv).to include('references_added') - end - it 'returns a csv of wikidata' do expect(CsvCleanupWorker).to receive(:perform_at) get "/campaigns/#{campaign.slug}/wikidata.csv" diff --git a/spec/lib/analytics/course_revisions_csv_builder_spec.rb b/spec/lib/analytics/course_revisions_csv_builder_spec.rb deleted file mode 100644 index 799c537d8e..0000000000 --- a/spec/lib/analytics/course_revisions_csv_builder_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' -require "#{Rails.root}/lib/analytics/course_revisions_csv_builder" - -describe CourseRevisionsCsvBuilder do - let(:course) { create(:course) } - let(:user) { create(:user, registered_at: course.start + 1.minute) } - let!(:courses_user) { create(:courses_user, course:, user:) } - - let(:article) { create(:article) } - let(:article2) { create(:article, title: 'Second_Article') } - let(:revision_count) { 5 } - let(:subject) { described_class.new(course).generate_csv } - - before do - revision_count.times do |i| - create(:revision, mw_rev_id: i, user:, date: course.start + 1.minute, article:) - end - # one revision for second article - create(:revision, mw_rev_id: 123, user:, date: course.start + 1.minute, article: article2) - # revisions with nil and characters, to make sure this does not cause problems - create(:revision, mw_rev_id: 124, user:, date: course.start + 1.minute, article: article2, - characters: nil) - create(:revision, mw_rev_id: 125, user:, date: course.start + 1.minute, article: article2, - characters: -500) - end - - it 'creates a CSV with a header and a row of data for each revision' do - expect(subject.split("\n").count).to eq(3) - end -end