Commit d3e59ff7da949cf01cf659d8d4e8aaae3060a121

Authored by Leandro Santos
1 parent 9cf3e36c
Exists in master

refactoring event report

lib/dialoga_plugin/event_job.rb
@@ -11,21 +11,19 @@ class DialogaPlugin::EventJob < DialogaPlugin::ReportJob @@ -11,21 +11,19 @@ class DialogaPlugin::EventJob < DialogaPlugin::ReportJob
11 events = Event.where(:profile_id => profile.id) 11 events = Event.where(:profile_id => profile.id)
12 events.map do |event| 12 events.map do |event|
13 filepath = "/tmp/#{report_path}/evento-#{event.slug}.csv" 13 filepath = "/tmp/#{report_path}/evento-#{event.slug}.csv"
14 - file = File.open(File.join(filepath), 'w+')  
15 - file.write(event.name+ "\n")  
16 - header = "'Nome';'Email'\n"  
17 - file.write(header)  
18 count = 0 14 count = 0
19 - event.person_followers.map do |person|  
20 - count += 1  
21 - puts "%s de %s: adicionando evento: %s" % [count, event.person_followers.count, event.id ]  
22 - info = []  
23 - info.push(person.name)  
24 - info.push(person.email)  
25 - file.write(info.map{|i| "'" + i.to_s + "'"}.join(";"))  
26 - file.write("\n") 15 + CSV.open(filepath, 'w', {:col_sep => ';', :force_quotes => true} ) do |csv|
  16 + csv << [event.name]
  17 + csv << ['Nome', 'Email']
  18 + event.person_followers.map do |person|
  19 + count += 1
  20 + puts "%s de %s: adicionando evento: %s" % [count, event.person_followers.count, event.id ]
  21 + info = []
  22 + info.push(person.name)
  23 + info.push(person.email)
  24 + csv << info
  25 + end
27 end 26 end
28 - file.close  
29 end 27 end
30 upload_file(compress_files('eventos', 'evento-*'), profile, report_folder) 28 upload_file(compress_files('eventos', 'evento-*'), profile, report_folder)
31 end 29 end
lib/dialoga_plugin/ranking_job.rb
@@ -17,7 +17,7 @@ class DialogaPlugin::RankingJob &lt; DialogaPlugin::ReportJob @@ -17,7 +17,7 @@ class DialogaPlugin::RankingJob &lt; DialogaPlugin::ReportJob
17 next if ranking.empty? 17 next if ranking.empty?
18 18
19 filepath = "/tmp/#{report_path}/ranking-#{discussion.slug}_#{article.slug}.csv" 19 filepath = "/tmp/#{report_path}/ranking-#{discussion.slug}_#{article.slug}.csv"
20 - CSV.open(filepath, 'w' ) do |csv| 20 + CSV.open(filepath, 'w', {:col_sep => ';', :force_quotes => true}) do |csv|
21 csv << ['Posição', 'Id', 'Proposta', 'Positivo', 'Negativo', 'Exibições', 'Valor'] 21 csv << ['Posição', 'Id', 'Proposta', 'Positivo', 'Negativo', 'Exibições', 'Valor']
22 ranking.each_with_index {|r, i| csv << [i+1, r.values].flatten} 22 ranking.each_with_index {|r, i| csv << [i+1, r.values].flatten}
23 end 23 end
lib/dialoga_plugin/report_job.rb
@@ -30,7 +30,7 @@ class DialogaPlugin::ReportJob &lt; Struct.new(:profile_id, :report_path) @@ -30,7 +30,7 @@ class DialogaPlugin::ReportJob &lt; Struct.new(:profile_id, :report_path)
30 def create_proposals_report(profile, report_folder) 30 def create_proposals_report(profile, report_folder)
31 filepath = "/tmp/#{report_path}/propostas.csv" 31 filepath = "/tmp/#{report_path}/propostas.csv"
32 32
33 - CSV.open(filepath, 'w', {:col_sep => ';'} ) do |csv| 33 + CSV.open(filepath, 'w', {:col_sep => ';', :force_quotes => true} ) do |csv|
34 tasks = ProposalsDiscussionPlugin::ProposalTask.all 34 tasks = ProposalsDiscussionPlugin::ProposalTask.all
35 count = 0 35 count = 0
36 csv << ['Tema', 'Origem', 'Status', 'Criada em', 'Moderado por', 'Data de Moderado', 'Validado por', 'Data de Validado', 'Autor', 'Proposta', 'Categorias'] 36 csv << ['Tema', 'Origem', 'Status', 'Criada em', 'Moderado por', 'Data de Moderado', 'Validado por', 'Data de Validado', 'Autor', 'Proposta', 'Categorias']