Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4803 from cyrillefr/add_download_option_for_wikid…
…ata_stats_to_entire_campagin_4345 Download Wikidata stats for a campaign
- Loading branch information
Showing
12 changed files
with
152 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require "#{Rails.root}/lib/analytics/course_wikidata_csv_builder.rb" | ||
|
||
describe CourseWikidataCsvBuilder do | ||
let(:wikidata) { Wiki.get_or_create(language: nil, project: 'wikidata') } | ||
let(:course) { create(:course, home_wiki: wikidata) } | ||
let(:builder) { described_class.new(course) } | ||
let(:create_course_stat) do | ||
create(:course_stats, | ||
stats_hash: { 'www.wikidata.org' => { 'claims created' => 2 } }, course_id: course.id) | ||
end | ||
|
||
before { stub_wiki_validation } | ||
|
||
context 'when no course_stat' do | ||
it 'generates only headers' do | ||
expect(builder.generate_csv).to start_with('course name,') | ||
expect(builder.generate_csv.lines.count).to eq(1) | ||
end | ||
end | ||
|
||
context 'when course_stat exists' do | ||
before do | ||
create_course_stat | ||
end | ||
|
||
it 'generates csv data' do | ||
expect(builder.generate_csv.lines.first).to start_with('course name,claims created') | ||
expect(builder.generate_csv.lines.last).to start_with(course.title + ',2') | ||
expect(builder.generate_csv.lines.count).to eq 2 | ||
end | ||
end | ||
end |
wrong placement of these two lines: this splits the message before in two parts. The last part was on a continuation line, which is then interpreted as no longer be part of the message before, but belonging to the last inserted message.
Beware with continuation lines in YML:
YML is cool for human edit (one file at a time), but not for automated edits (e.g. with sed/bash scripts, processing many files line per line to find the location for inserting/replacing/deleting messages (and ignoring the possibility of continuation lines in this YML format, or similar formats, or even in Python source files, that don't have statement terminators).
JSON is safer than YML if you intend to manage hundreds of locales with hundreds of message files: This bug should have not happened if the JSON format was used, as the syntax error would have been detected early (for mismatched quotation marks). JSON is still readable (ans it is natively supported in all modern languages or libraries). Alternative: the INI format (even simpler), or the XML syntax (but hard to read by humans).
But if you use YML, avoid using any continuation line, even if lines are longer than your convention in your favorite text editor: message files should be comparable side-by-side, allowing matching messages entirely line by line, and in the same order (possibly the same number of lines; only 1 line per message, escaping linebreaks if needed; however for translatability, they should not be arbitrarily long parageraphs or lists, and should avoid breaking sentences: this will ease the maintenance and review).