Skip to content

Commit

Permalink
4880 – Seeds Script: Create standalone claim descriptions and fact-ch…
Browse files Browse the repository at this point in the history
…ecks (#1956)

This creates both standalone claim descriptions and standalone claim descriptions with fact checks. Though only the second is visible in the UI. We also:

- verify the fact checks with a random status ('undetermined', 'not_applicable', 'in_progress', 'verified' or 'false')
- add a link to half of the standalone fact checks

Note: I also had to update how we were verifying and publishing the fact-checks that are related to a project media. It was breaking since now we can have claim_descriptions with nil project_media_id. (check-api/db/seeds.rb: line 333)

References: 4880
PR: 1956
  • Loading branch information
vasconsaurus authored Jul 16, 2024
1 parent 46fc1fd commit 734f949
Showing 1 changed file with 43 additions and 3 deletions.
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

0 comments on commit 734f949

Please sign in to comment.