Skip to content

Commit

Permalink
Adding new columns to the feed export CSV. (#2131)
Browse files Browse the repository at this point in the history
New columns:

- Cluster URL
- Workspaces
- Ratings
- Date (first)
- Date (last)
- Extracted text as a fallback for description

Reference: CV2-5685.
  • Loading branch information
caiosba authored Nov 19, 2024
1 parent b6b8779 commit 5770afe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
12 changes: 12 additions & 0 deletions app/models/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ def import_medias_to_team(team, claim_title, claim_context, parent_id = nil)
parent
end

def full_url
"#{CheckConfig.get('checkdesk_client')}/#{self.feed.team.slug}/feed/#{self.feed_id}/#{self.project_media_id}"
end

def team_names
Team.where(id: self.team_ids.to_a).order('id ASC').map(&:name).uniq
end

def ratings
self.project_medias.order('team_id ASC').map(&:status_i18n).uniq
end

def self.import_other_medias_to_team(cluster_id, parent_id, max)
cluster = Cluster.find_by_id(cluster_id)
parent = ProjectMedia.find_by_id(parent_id)
Expand Down
5 changes: 3 additions & 2 deletions app/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ def saved_search_was
end

def get_exported_data(filters)
data = [['Title', 'Description', 'Number of media', 'Number of requests', 'Number of fact-checks']]
data = [['Title', 'Description', 'Date (first)', 'Date (last)', 'Number of media', 'Number of requests', 'Number of fact-checks', 'Cluster URL', 'Workspaces', 'Ratings']]
self.filtered_clusters(filters).find_each do |cluster|
data << [cluster.title, cluster.center.description, cluster.media_count, cluster.requests_count, cluster.fact_checks_count]
description = cluster.center.description.blank? ? cluster.center.extracted_text : cluster.center.description
data << [cluster.title, description, cluster.first_item_at, cluster.last_item_at, cluster.media_count, cluster.requests_count, cluster.fact_checks_count, cluster.full_url, cluster.team_names.join("\n"), cluster.ratings.join("\n")]
end
data
end
Expand Down
25 changes: 24 additions & 1 deletion test/models/cluster_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

class ClusterTest < ActiveSupport::TestCase
def setup
super
Sidekiq::Testing.fake!
Cluster.delete_all
User.current = Team.current = nil
end

def teardown
end

test "should create cluster" do
Expand Down Expand Up @@ -74,4 +78,23 @@ def setup
c.project_medias << create_project_media
assert_equal 2, c.size
end

test "should return full URL to cluster" do
c = create_cluster
assert_match /^http/, c.full_url
end

test "should return team names" do
t1 = create_team name: 'Foo'
t2 = create_team name: 'Bar'
c = create_cluster
c.update_column :team_ids, [t1.id, t2.id]
assert_equal ['Foo', 'Bar'], c.team_names
end

test "should return ratings" do
c = create_cluster
c.project_medias << create_project_media
assert_equal ['Unstarted'], c.ratings
end
end

0 comments on commit 5770afe

Please sign in to comment.