New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Download Wikidata stats for a campaign #4803
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
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" | ||
|
||
class CampaignCsvBuilder | ||
def initialize(campaign) | ||
|
@@ -44,6 +45,11 @@ def revisions_to_csv | |
CSV.generate { |csv| csv_data.each { |line| csv << line } } | ||
end | ||
|
||
def wikidata_to_csv | ||
courses = @campaign.courses.joins(:course_stat) | ||
CourseWikidataCsvBuilder.new(courses).generate_csv | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer this to follow the same pattern as the other methods like Making The problem with that approach is that, unlike the other CSV builders, the output for the Wikidata one isn't a format that is suitable to that aggregation strategy. I think the best way around that will be to change the output format of the Wikidata CSV builder. Currently, it uses headers of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went with the join so I do not have to loop, but I can change to the So, if I understand well, your format proposal for campaign is: Also, do you want me to change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's correct, except that |
||
end | ||
|
||
class AllCourses | ||
def self.courses | ||
Course.all | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
# == Schema Information | ||
# | ||
# Table name: course_stats | ||
|
||
FactoryBot.define do | ||
factory :course_stats, class: 'CourseStat' do | ||
nil | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require "#{Rails.root}/lib/analytics/course_wikidata_csv_builder.rb" | ||
|
||
describe CourseWikidataCsvBuilder do | ||
let(:course) { create(:course) } | ||
let(:another_course) { create(:course, slug: 'myschool/mycourse') } | ||
let(:builder) { described_class.new(course) } | ||
let(:campaign_builder) { described_class.new(ActiveRecord::Relation.new(Course)) } | ||
let(:create_course_stat) do | ||
create(:course_stats, | ||
stats_hash: { 'www.wikidata.org' => { 'claims created' => 2 } }, course_id: course.id) | ||
end | ||
let(:create_another_course_stat) do | ||
create(:course_stats, | ||
stats_hash: { 'www.wikidata.org' => { 'claims created' => 9 } }, | ||
course_id: another_course.id) | ||
end | ||
|
||
context 'when no course_stat' do | ||
it 'generates only headers' do | ||
expect(builder.generate_csv).to eq "revision_type,count\ntotal revisions,0\n" | ||
end | ||
end | ||
|
||
context 'when course_stat exists' do | ||
before do | ||
create_course_stat | ||
end | ||
|
||
it 'generates csv data' do | ||
expect(builder.generate_csv).to eq "revision_type,count\nclaims created,2\n" | ||
end | ||
end | ||
|
||
# generate_csv also used in campaign context | ||
# see controller campaign and CSV actions | ||
# see also campaigns_controller_spec | ||
context 'when multiple courses in a campaign' do | ||
before do | ||
create_course_stat | ||
create_another_course_stat | ||
end | ||
|
||
# Since 2 + 9 = 11 | ||
it 'generates csv of aggregated data' do | ||
expect(campaign_builder.generate_csv).to eq "revision_type,count\nclaims created,11\n" | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to limit this based on
Features.wikiEd
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that, because there is this limit in the course version (
app/assets/javascripts/components/overview/course_stats_download_modal.jsx
So I implied it would be the same for a campaign. I will remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! We should change that limitation on CourseStatsDownloadModal... now it should check for whether the
course
object has acourse_stats
property. @1v4n4's project made the wikidata stats data available without the Wiki Ed restriction.