From f21749aad96964fb5152418dfb811f77a413ca38 Mon Sep 17 00:00:00 2001 From: Sawy Date: Sun, 20 Oct 2024 19:13:48 +0300 Subject: [PATCH 1/2] CV2-5301: add a report published_at to CSV export file --- lib/check_search.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/check_search.rb b/lib/check_search.rb index 89bc0e067..0fbbf9005 100644 --- a/lib/check_search.rb +++ b/lib/check_search.rb @@ -345,7 +345,7 @@ def self.get_exported_data(query, team_id) if feed_sharing_only_fact_checks header = ['Fact-check title', 'Fact-check summary', 'Fact-check URL', 'Tags', 'Workspace', 'Updated at', 'Rating'] else - header = ['Claim', 'Item page URL', 'Status', 'Created by', 'Submitted at', 'Published at', 'Number of media', 'Tags'] + header = ['Claim', 'Item page URL', 'Status', 'Created by', 'Submitted at', 'Social Media Posted at', 'Report Published at', 'Number of media', 'Tags'] fields = team.team_tasks.sort fields.each { |tt| header << tt.label } end @@ -356,6 +356,12 @@ def self.get_exported_data(query, team_id) while !search_after.empty? result = $repository.search(_source: 'annotated_id', query: search.medias_query, sort: [{ annotated_id: { order: :asc } }], size: 10000, search_after: search_after).results ids = result.collect{ |i| i['annotated_id'] }.uniq.compact.map(&:to_i) + pm_report = {} + Dynamic.where(annotation_type: 'report_design', annotated_type: 'ProjectMedia', annotated_id: ids) + .find_each do |raw| + data = raw.data + pm_report[raw.annotated_id] = data['last_published'].to_i if data['state'] == 'published' + end # Iterate through each result and generate an output row for the CSV ProjectMedia.where(id: ids, team_id: search.team_condition(team_id)).find_each do |pm| @@ -371,6 +377,7 @@ def self.get_exported_data(query, team_id) pm.status ] else + report_published_at = pm_report[pm.id] ? Time.at(pm_report[pm.id]).strftime("%Y-%m-%d %H:%M:%S") : nil row = [ pm.claim_description&.description, pm.full_url, @@ -378,6 +385,7 @@ def self.get_exported_data(query, team_id) pm.author_name.to_s.gsub(/ \[.*\]$/, ''), pm.created_at.strftime("%Y-%m-%d %H:%M:%S"), pm.published_at&.strftime("%Y-%m-%d %H:%M:%S"), + report_published_at, pm.linked_items_count, pm.tags_as_sentence ] From e3e5b998f8a5de6796505a5425c0fd908d8c4188 Mon Sep 17 00:00:00 2001 From: Sawy Date: Mon, 21 Oct 2024 09:31:59 +0300 Subject: [PATCH 2/2] CV2-5301: fix tests and CC --- lib/check_search.rb | 73 ++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/lib/check_search.rb b/lib/check_search.rb index 0fbbf9005..135a9c2e9 100644 --- a/lib/check_search.rb +++ b/lib/check_search.rb @@ -342,6 +342,7 @@ def self.get_exported_data(query, team_id) # Prepare the export data = [] header = nil + fields = [] if feed_sharing_only_fact_checks header = ['Fact-check title', 'Fact-check summary', 'Fact-check URL', 'Tags', 'Workspace', 'Updated at', 'Rating'] else @@ -359,44 +360,12 @@ def self.get_exported_data(query, team_id) pm_report = {} Dynamic.where(annotation_type: 'report_design', annotated_type: 'ProjectMedia', annotated_id: ids) .find_each do |raw| - data = raw.data - pm_report[raw.annotated_id] = data['last_published'].to_i if data['state'] == 'published' + pm_report[raw.annotated_id] = raw.data['last_published'].to_i if raw.data['state'] == 'published' end # Iterate through each result and generate an output row for the CSV ProjectMedia.where(id: ids, team_id: search.team_condition(team_id)).find_each do |pm| - row = nil - if feed_sharing_only_fact_checks - row = [ - pm.fact_check_title, - pm.fact_check_summary, - pm.fact_check_url, - pm.tags_as_sentence, - pm.team_name, - pm.updated_at_timestamp, - pm.status - ] - else - report_published_at = pm_report[pm.id] ? Time.at(pm_report[pm.id]).strftime("%Y-%m-%d %H:%M:%S") : nil - row = [ - pm.claim_description&.description, - pm.full_url, - pm.status_i18n, - pm.author_name.to_s.gsub(/ \[.*\]$/, ''), - pm.created_at.strftime("%Y-%m-%d %H:%M:%S"), - pm.published_at&.strftime("%Y-%m-%d %H:%M:%S"), - report_published_at, - pm.linked_items_count, - pm.tags_as_sentence - ] - annotations = pm.get_annotations('task').map(&:load) - fields.each do |field| - annotation = annotations.find { |a| a.team_task_id == field.id } - answer = (annotation ? (begin annotation.first_response_obj.file_data[:file_urls].join("\n") rescue annotation.first_response.to_s end) : '') - answer = begin JSON.parse(answer).collect{ |x| x['url'] }.join(', ') rescue answer end - row << answer - end - end + row = self.get_exported_data_row(feed_sharing_only_fact_checks, pm, pm_report[pm.id], fields) data << row end @@ -406,6 +375,42 @@ def self.get_exported_data(query, team_id) data end + def self.get_exported_data_row(feed_sharing_only_fact_checks, pm, report_published_at, fields) + row = nil + if feed_sharing_only_fact_checks + row = [ + pm.fact_check_title, + pm.fact_check_summary, + pm.fact_check_url, + pm.tags_as_sentence, + pm.team_name, + pm.updated_at_timestamp, + pm.status + ] + else + report_published_at_value = report_published_at ? Time.at(report_published_at).strftime("%Y-%m-%d %H:%M:%S") : nil + row = [ + pm.claim_description&.description, + pm.full_url, + pm.status_i18n, + pm.author_name.to_s.gsub(/ \[.*\]$/, ''), + pm.created_at.strftime("%Y-%m-%d %H:%M:%S"), + pm.published_at&.strftime("%Y-%m-%d %H:%M:%S"), + report_published_at_value, + pm.linked_items_count, + pm.tags_as_sentence + ] + annotations = pm.get_annotations('task').map(&:load) + fields.each do |field| + annotation = annotations.find { |a| a.team_task_id == field.id } + answer = (annotation ? (begin annotation.first_response_obj.file_data[:file_urls].join("\n") rescue annotation.first_response.to_s end) : '') + answer = begin JSON.parse(answer).collect{ |x| x['url'] }.join(', ') rescue answer end + row << answer + end + end + row + end + private def adjust_es_window_size