From e9a469b45513173bbb99b327b250a6235766f072 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Tue, 15 Sep 2015 12:45:48 -0300 Subject: [PATCH] adding followers --- lib/juventude_plugin/followers_job.rb | 34 ++++++++++++++++++++++++++++++++++ lib/juventude_plugin/report_job.rb | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 lib/juventude_plugin/followers_job.rb diff --git a/lib/juventude_plugin/followers_job.rb b/lib/juventude_plugin/followers_job.rb new file mode 100644 index 0000000..a9167a6 --- /dev/null +++ b/lib/juventude_plugin/followers_job.rb @@ -0,0 +1,34 @@ +# encoding: UTF-8 +class JuventudePlugin::FollowersJob < JuventudePlugin::ReportJob + + def perform + profile = Profile.find(profile_id) + report_folder = JuventudePlugin::ReportJob.create_report_path(profile, report_path) + create_followers_report(profile, report_folder) + end + + def create_followers_report(profile, report_folder) + proposals = ProposalsDiscussionPlugin::Proposal.all + filepath = "/tmp/#{report_path}/followers.csv" + CSV.open(filepath, 'w', {:col_sep => ';', :force_quotes => true} ) do |csv| + csv << ['Id Artigo Seguido','Id Pessoa que segue','Data'] + proposals.map do |proposal| + count = 0 + amount_proposal_followers = proposal.article_followers.count + proposal.article_followers.map do |article_follower| + count += 1 + puts "%s de %s: adicionando follower da proposta: %s" % [count, amount_proposal_followers, proposal.id ] + info = [] + => ArticleFollower(id: integer, person_id: integer, article_id: integer, since: datetime, created_at: datetime, updated_at: datetime) + + info.push(article_follower.article_id) + info.push(article_follower.person_id) + info.push(article_follower.created_at.strftime("%d/%m/%y %H:%M")) + csv << info + end + end + end + upload_file(compress_files('followers', 'followers.csv'), profile, report_folder) + end + +end diff --git a/lib/juventude_plugin/report_job.rb b/lib/juventude_plugin/report_job.rb index 009b4af..6395a0e 100644 --- a/lib/juventude_plugin/report_job.rb +++ b/lib/juventude_plugin/report_job.rb @@ -45,7 +45,7 @@ class JuventudePlugin::ReportJob < Struct.new(:profile_id, :report_path) info.push(proposal.title) info.push(proposal.abstract.present? ? proposal.abstract.gsub(/\s+/, ' ').strip : '') info.push(proposal.comments.count) - info.push(proposal.followers.count) + info.push(proposal.person_followers.count) info.push(proposal.votes_for) info.push(proposal.cities.map{|c|c.path}.join(',')) csv << info -- libgit2 0.21.2