Skip to content
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

4880 – Seeds Script: Create standalone claim descriptions and fact-checks #1956

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def open_file(file)

BLANK_PARAMS = Array.new(8, { type: 'Blank' })

STANDALONE_CLAIMS_FACT_CHECKS_PARAMS = (Array.new(8) do
{
description: Faker::Lorem.sentence,
context: Faker::Lorem.paragraph(sentence_count: 8)
}
end)

class Setup

private
Expand Down Expand Up @@ -323,7 +330,7 @@ def populate_projects

def publish_fact_checks
users.each_value do |user|
fact_checks = FactCheck.where(user: user).last(items_total/2)
fact_checks = user.claim_descriptions.where.not(project_media_id: nil).includes(:fact_check).map { |claim| claim.fact_check }.compact!.last(items_total/2)
fact_checks[0, (fact_checks.size/2)].each { |fact_check| verify_fact_check_and_publish_report(fact_check.project_media)}
end
end
Expand Down Expand Up @@ -419,6 +426,13 @@ def tipline_requests
end
end

def verified_standalone_claims_and_fact_checks
users.each_value do |user|
standalone_claims_and_fact_checks(user)
verify_standalone_claims_and_fact_checks(user)
end
end

private

def medias_params
Expand Down Expand Up @@ -707,6 +721,30 @@ def imported_fact_check_params(media_type)
def channel(media_type)
media_type == "Blank" ? { main: CheckChannels::ChannelCodes::FETCH } : { main: CheckChannels::ChannelCodes::MANUAL }
end

def standalone_claims_and_fact_checks(user)
STANDALONE_CLAIMS_FACT_CHECKS_PARAMS.each.with_index do |params, index|
claim_description_attributes = {
description: params[:description],
context: params[:context],
user: user,
team: user.teams[0],
fact_check_attributes: fact_check_params_for_half_the_claims(index, user),
}

ClaimDescription.create!(claim_description_attributes)
end
end

def verify_standalone_claims_and_fact_checks(user)
status = ['undetermined', 'not_applicable', 'in_progress', 'verified', 'false']

fact_checks = user.claim_descriptions.where(project_media_id: nil).includes(:fact_check).map { |claim| claim.fact_check }.compact! # some claims don't have fact checks, so they return nil
fact_checks.each do |fact_check|
fact_check.rating = status.sample
fact_check.save!
end
end
end

puts "If you want to create a new user: press enter"
Expand Down Expand Up @@ -747,10 +785,12 @@ def channel(media_type)
populated_workspaces.tipline_requests
puts 'Publishing half of each user\'s Fact Checks...'
populated_workspaces.publish_fact_checks
puts 'Creating Clusters'
puts 'Creating Clusters...'
populated_workspaces.clusters(feed_2)
puts 'Creating Explainers'
puts 'Creating Explainers...'
populated_workspaces.explainers
puts 'Creating Standalone Claims and FactChecks with different statuses...'
populated_workspaces.verified_standalone_claims_and_fact_checks
rescue RuntimeError => e
if e.message.include?('We could not parse this link')
puts "—————"
Expand Down
Loading