Commit f2c1a6f92d8aa578a5427e5ca9dc500196ee3c19
1 parent
b9826c1e
Exists in
master
adding ranking script
Showing
4 changed files
with
37 additions
and
6 deletions
Show diff stats
controllers/myprofile/dialoga_plugin_myprofile_controller.rb
@@ -7,6 +7,7 @@ class DialogaPluginMyprofileController < MyProfileController | @@ -7,6 +7,7 @@ class DialogaPluginMyprofileController < MyProfileController | ||
7 | scripts = ['sent_event_report', 'sent_proposal_report'] | 7 | scripts = ['sent_event_report', 'sent_proposal_report'] |
8 | scripts.map do |script| | 8 | scripts.map do |script| |
9 | cmd = File.join(path,script) + ' ' + current_person.email.to_s | 9 | cmd = File.join(path,script) + ' ' + current_person.email.to_s |
10 | +#raise IO.popen(cmd).read.inspect | ||
10 | fork {IO.popen(cmd).read} | 11 | fork {IO.popen(cmd).read} |
11 | end | 12 | end |
12 | session[:notice] = _("The report wil be sent to email #{current_person.email}") | 13 | session[:notice] = _("The report wil be sent to email #{current_person.email}") |
script/sent_event_report
1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
2 | +# encoding: UTF-8 | ||
2 | require_relative '../../../config/environment' | 3 | require_relative '../../../config/environment' |
3 | 4 | ||
4 | -puts 'Iniciando script' | 5 | +puts 'Iniciando script eventos' |
5 | 6 | ||
6 | -file = File.open(File.join(Rails.root,'event.csv'), 'w+') | 7 | +directory = File.join(Rails.root,'data') |
8 | +Dir.mkdir(directory) unless File.exists?(directory) | ||
9 | + | ||
10 | +file = File.open(File.join(directory,'event.csv'), 'w+') | ||
7 | 11 | ||
8 | events = Event.all | 12 | events = Event.all |
9 | events.map do |event| | 13 | events.map do |event| |
script/sent_proposal_report
1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
2 | +# encoding: UTF-8 | ||
2 | require_relative '../../../config/environment' | 3 | require_relative '../../../config/environment' |
3 | 4 | ||
5 | +directory = File.join(Rails.root,'data') | ||
6 | +Dir.mkdir(directory) unless File.exists?(directory) | ||
7 | + | ||
4 | emails = ['leandronunes@gmail.com', 'leandro.santos@serpro.gov.br'] + ARGV | 8 | emails = ['leandronunes@gmail.com', 'leandro.santos@serpro.gov.br'] + ARGV |
5 | emails.uniq! | 9 | emails.uniq! |
6 | 10 | ||
7 | -puts 'Iniciando script' | 11 | +puts 'Iniciando script propostas' |
8 | 12 | ||
9 | -file = File.open(File.join(Rails.root,'data.csv'), 'w+') | 13 | +file = File.open(File.join(directory,'data.csv'), 'w+') |
10 | 14 | ||
11 | tasks = ProposalsDiscussionPlugin::ProposalTask.all | 15 | tasks = ProposalsDiscussionPlugin::ProposalTask.all |
12 | count = 0 | 16 | count = 0 |
@@ -41,8 +45,9 @@ file.close | @@ -41,8 +45,9 @@ file.close | ||
41 | ActionMailer::Base.logger = Logger.new(STDOUT) | 45 | ActionMailer::Base.logger = Logger.new(STDOUT) |
42 | class Sender < ActionMailer::Base | 46 | class Sender < ActionMailer::Base |
43 | def send_report(to, from) | 47 | def send_report(to, from) |
44 | - attachments["eventos.csv"] = File.read("#{Rails.root}/event.csv") | ||
45 | - attachments["propostas.csv"] = File.read("#{Rails.root}/data.csv") | 48 | + directory = File.join(Rails.root,'data') |
49 | + attachments["eventos.csv"] = File.read("#{directory}/event.csv") | ||
50 | + attachments["propostas.csv"] = File.read("#{directory}/data.csv") | ||
46 | mail to: to, from: from, | 51 | mail to: to, from: from, |
47 | subject: "Relatorio do Dialoga", body: "Segue em anexo os relatorios do Dialoga" | 52 | subject: "Relatorio do Dialoga", body: "Segue em anexo os relatorios do Dialoga" |
48 | end | 53 | end |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +#!/usr/bin/env ruby | ||
2 | +# encoding: UTF-8 | ||
3 | + | ||
4 | +require_relative '../../../config/environment' | ||
5 | + | ||
6 | +puts 'Iniciando script ranking' | ||
7 | + | ||
8 | +directory = File.join(Rails.root,'data') | ||
9 | +Dir.mkdir(directory) unless File.exists?(directory) | ||
10 | + | ||
11 | +discussion = ProposalsDiscussionPlugin::Discussion.first | ||
12 | + | ||
13 | +articles = discussion.topics | ||
14 | +articles.each do |article| | ||
15 | + puts "#{article.slug}" | ||
16 | + ranking = article.ranking | ||
17 | + CSV.open(File.join(Rails.root,'data',"ranking_#{article.slug}.csv"), 'w' ) do |csv| | ||
18 | + csv << ['Posição', 'Id', 'Proposta', 'Positivo', 'Negativo', 'Exibições', 'Valor'] | ||
19 | + ranking.each_with_index {|r, i| csv << [i+1, r.values].flatten} | ||
20 | + end | ||
21 | +end |