Commit e9a469b45513173bbb99b327b250a6235766f072
1 parent
bd930037
Exists in
master
adding followers
Showing
2 changed files
with
35 additions
and
1 deletions
Show diff stats
... | ... | @@ -0,0 +1,34 @@ |
1 | +# encoding: UTF-8 | |
2 | +class JuventudePlugin::FollowersJob < JuventudePlugin::ReportJob | |
3 | + | |
4 | + def perform | |
5 | + profile = Profile.find(profile_id) | |
6 | + report_folder = JuventudePlugin::ReportJob.create_report_path(profile, report_path) | |
7 | + create_followers_report(profile, report_folder) | |
8 | + end | |
9 | + | |
10 | + def create_followers_report(profile, report_folder) | |
11 | + proposals = ProposalsDiscussionPlugin::Proposal.all | |
12 | + filepath = "/tmp/#{report_path}/followers.csv" | |
13 | + CSV.open(filepath, 'w', {:col_sep => ';', :force_quotes => true} ) do |csv| | |
14 | + csv << ['Id Artigo Seguido','Id Pessoa que segue','Data'] | |
15 | + proposals.map do |proposal| | |
16 | + count = 0 | |
17 | + amount_proposal_followers = proposal.article_followers.count | |
18 | + proposal.article_followers.map do |article_follower| | |
19 | + count += 1 | |
20 | + puts "%s de %s: adicionando follower da proposta: %s" % [count, amount_proposal_followers, proposal.id ] | |
21 | + info = [] | |
22 | + => ArticleFollower(id: integer, person_id: integer, article_id: integer, since: datetime, created_at: datetime, updated_at: datetime) | |
23 | + | |
24 | + info.push(article_follower.article_id) | |
25 | + info.push(article_follower.person_id) | |
26 | + info.push(article_follower.created_at.strftime("%d/%m/%y %H:%M")) | |
27 | + csv << info | |
28 | + end | |
29 | + end | |
30 | + end | |
31 | + upload_file(compress_files('followers', 'followers.csv'), profile, report_folder) | |
32 | + end | |
33 | + | |
34 | +end | ... | ... |
lib/juventude_plugin/report_job.rb
... | ... | @@ -45,7 +45,7 @@ class JuventudePlugin::ReportJob < Struct.new(:profile_id, :report_path) |
45 | 45 | info.push(proposal.title) |
46 | 46 | info.push(proposal.abstract.present? ? proposal.abstract.gsub(/\s+/, ' ').strip : '') |
47 | 47 | info.push(proposal.comments.count) |
48 | - info.push(proposal.followers.count) | |
48 | + info.push(proposal.person_followers.count) | |
49 | 49 | info.push(proposal.votes_for) |
50 | 50 | info.push(proposal.cities.map{|c|c.path}.join(',')) |
51 | 51 | csv << info | ... | ... |