Commit 14be0204f5e11b822f2fa257e687efa417bfec37
1 parent
e9a469b4
Exists in
master
adding votes info
Showing
2 changed files
with
35 additions
and
1 deletions
Show diff stats
lib/juventude_plugin/followers_job.rb
@@ -22,7 +22,7 @@ class JuventudePlugin::FollowersJob < JuventudePlugin::ReportJob | @@ -22,7 +22,7 @@ class JuventudePlugin::FollowersJob < JuventudePlugin::ReportJob | ||
22 | => ArticleFollower(id: integer, person_id: integer, article_id: integer, since: datetime, created_at: datetime, updated_at: datetime) | 22 | => ArticleFollower(id: integer, person_id: integer, article_id: integer, since: datetime, created_at: datetime, updated_at: datetime) |
23 | 23 | ||
24 | info.push(article_follower.article_id) | 24 | info.push(article_follower.article_id) |
25 | - info.push(article_follower.person_id) | 25 | + info.push(article_follower.person.identifier) |
26 | info.push(article_follower.created_at.strftime("%d/%m/%y %H:%M")) | 26 | info.push(article_follower.created_at.strftime("%d/%m/%y %H:%M")) |
27 | csv << info | 27 | csv << info |
28 | end | 28 | end |
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +# encoding: UTF-8 | ||
2 | +class JuventudePlugin::VotesJob < 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_votes_report(profile, report_folder) | ||
8 | + end | ||
9 | + | ||
10 | + def create_votes_report(profile, report_folder) | ||
11 | + proposals = ProposalsDiscussionPlugin::Proposal.all | ||
12 | + filepath = "/tmp/#{report_path}/votes.csv" | ||
13 | + CSV.open(filepath, 'w', {:col_sep => ';', :force_quotes => true} ) do |csv| | ||
14 | + csv << ['Id Artigo Votado','Id Pessoa que votou','Data'] | ||
15 | + proposals.map do |proposal| | ||
16 | + count = 0 | ||
17 | + amount_proposal_votes = proposal.votes.count | ||
18 | + proposal.votes.map do |vote| | ||
19 | + count += 1 | ||
20 | + puts "%s de %s: adicionando voto da proposta: %s" % [count, amount_proposal_votes, 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(vote.voteable_id) | ||
25 | + info.push(vote.voter.identifier) | ||
26 | + info.push(vote.created_at.strftime("%d/%m/%y %H:%M")) | ||
27 | + csv << info | ||
28 | + end | ||
29 | + end | ||
30 | + end | ||
31 | + upload_file(compress_files('votes', 'votes.csv'), profile, report_folder) | ||
32 | + end | ||
33 | + | ||
34 | +end |