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 | 7 | scripts = ['sent_event_report', 'sent_proposal_report'] |
| 8 | 8 | scripts.map do |script| |
| 9 | 9 | cmd = File.join(path,script) + ' ' + current_person.email.to_s |
| 10 | +#raise IO.popen(cmd).read.inspect | |
| 10 | 11 | fork {IO.popen(cmd).read} |
| 11 | 12 | end |
| 12 | 13 | session[:notice] = _("The report wil be sent to email #{current_person.email}") | ... | ... |
script/sent_event_report
| 1 | 1 | #!/usr/bin/env ruby |
| 2 | +# encoding: UTF-8 | |
| 2 | 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 | 12 | events = Event.all |
| 9 | 13 | events.map do |event| | ... | ... |
script/sent_proposal_report
| 1 | 1 | #!/usr/bin/env ruby |
| 2 | +# encoding: UTF-8 | |
| 2 | 3 | require_relative '../../../config/environment' |
| 3 | 4 | |
| 5 | +directory = File.join(Rails.root,'data') | |
| 6 | +Dir.mkdir(directory) unless File.exists?(directory) | |
| 7 | + | |
| 4 | 8 | emails = ['leandronunes@gmail.com', 'leandro.santos@serpro.gov.br'] + ARGV |
| 5 | 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 | 15 | tasks = ProposalsDiscussionPlugin::ProposalTask.all |
| 12 | 16 | count = 0 |
| ... | ... | @@ -41,8 +45,9 @@ file.close |
| 41 | 45 | ActionMailer::Base.logger = Logger.new(STDOUT) |
| 42 | 46 | class Sender < ActionMailer::Base |
| 43 | 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 | 51 | mail to: to, from: from, |
| 47 | 52 | subject: "Relatorio do Dialoga", body: "Segue em anexo os relatorios do Dialoga" |
| 48 | 53 | end | ... | ... |
| ... | ... | @@ -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 | ... | ... |