From f2c1a6f92d8aa578a5427e5ca9dc500196ee3c19 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Thu, 6 Aug 2015 19:51:18 -0300 Subject: [PATCH] adding ranking script --- controllers/myprofile/dialoga_plugin_myprofile_controller.rb | 1 + script/sent_event_report | 8 ++++++-- script/sent_proposal_report | 13 +++++++++---- script/sent_ranking | 21 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100755 script/sent_ranking diff --git a/controllers/myprofile/dialoga_plugin_myprofile_controller.rb b/controllers/myprofile/dialoga_plugin_myprofile_controller.rb index 67f0eb3..409f640 100644 --- a/controllers/myprofile/dialoga_plugin_myprofile_controller.rb +++ b/controllers/myprofile/dialoga_plugin_myprofile_controller.rb @@ -7,6 +7,7 @@ class DialogaPluginMyprofileController < MyProfileController scripts = ['sent_event_report', 'sent_proposal_report'] scripts.map do |script| cmd = File.join(path,script) + ' ' + current_person.email.to_s +#raise IO.popen(cmd).read.inspect fork {IO.popen(cmd).read} end session[:notice] = _("The report wil be sent to email #{current_person.email}") diff --git a/script/sent_event_report b/script/sent_event_report index 1e7968b..60756b8 100755 --- a/script/sent_event_report +++ b/script/sent_event_report @@ -1,9 +1,13 @@ #!/usr/bin/env ruby +# encoding: UTF-8 require_relative '../../../config/environment' -puts 'Iniciando script' +puts 'Iniciando script eventos' -file = File.open(File.join(Rails.root,'event.csv'), 'w+') +directory = File.join(Rails.root,'data') +Dir.mkdir(directory) unless File.exists?(directory) + +file = File.open(File.join(directory,'event.csv'), 'w+') events = Event.all events.map do |event| diff --git a/script/sent_proposal_report b/script/sent_proposal_report index f05e9fe..63bafed 100755 --- a/script/sent_proposal_report +++ b/script/sent_proposal_report @@ -1,12 +1,16 @@ #!/usr/bin/env ruby +# encoding: UTF-8 require_relative '../../../config/environment' +directory = File.join(Rails.root,'data') +Dir.mkdir(directory) unless File.exists?(directory) + emails = ['leandronunes@gmail.com', 'leandro.santos@serpro.gov.br'] + ARGV emails.uniq! -puts 'Iniciando script' +puts 'Iniciando script propostas' -file = File.open(File.join(Rails.root,'data.csv'), 'w+') +file = File.open(File.join(directory,'data.csv'), 'w+') tasks = ProposalsDiscussionPlugin::ProposalTask.all count = 0 @@ -41,8 +45,9 @@ file.close ActionMailer::Base.logger = Logger.new(STDOUT) class Sender < ActionMailer::Base def send_report(to, from) - attachments["eventos.csv"] = File.read("#{Rails.root}/event.csv") - attachments["propostas.csv"] = File.read("#{Rails.root}/data.csv") + directory = File.join(Rails.root,'data') + attachments["eventos.csv"] = File.read("#{directory}/event.csv") + attachments["propostas.csv"] = File.read("#{directory}/data.csv") mail to: to, from: from, subject: "Relatorio do Dialoga", body: "Segue em anexo os relatorios do Dialoga" end diff --git a/script/sent_ranking b/script/sent_ranking new file mode 100755 index 0000000..f9783b5 --- /dev/null +++ b/script/sent_ranking @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby +# encoding: UTF-8 + +require_relative '../../../config/environment' + +puts 'Iniciando script ranking' + +directory = File.join(Rails.root,'data') +Dir.mkdir(directory) unless File.exists?(directory) + +discussion = ProposalsDiscussionPlugin::Discussion.first + +articles = discussion.topics +articles.each do |article| + puts "#{article.slug}" + ranking = article.ranking + CSV.open(File.join(Rails.root,'data',"ranking_#{article.slug}.csv"), 'w' ) do |csv| + csv << ['Posição', 'Id', 'Proposta', 'Positivo', 'Negativo', 'Exibições', 'Valor'] + ranking.each_with_index {|r, i| csv << [i+1, r.values].flatten} + end +end -- libgit2 0.21.2