Skip to content

Commit

Permalink
added pseudospline export and prognoz export to codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
bentut committed Dec 7, 2012
1 parent 03b1197 commit 01d313f
Show file tree
Hide file tree
Showing 14 changed files with 1,394 additions and 698 deletions.
7 changes: 7 additions & 0 deletions app/controllers/prognoz_data_files_controller.rb
Expand Up @@ -59,5 +59,12 @@ def write_xls
@output_file.write_export @output_file.write_export
redirect_to :action => 'index' redirect_to :action => 'index'
end end

def send_prognoz_export
@recipients = ["btrevino@hawaii.edu","icintina@hawaii.edu", "james29@hawaii.edu"]
PrognozDataFile.send_prognoz_update(@recipients)
flash[:notice] = "Zipped Export was sent to [#{@recipients.join(", ")}]. Comparison files were updated in /data/prognoz_export."
redirect_to :action => 'index'
end


end end
8 changes: 8 additions & 0 deletions app/mailers/packager_mailer.rb
Expand Up @@ -49,4 +49,12 @@ def website_post_notification(post_name, post_address, new_data_series, created)
@new_data_series = new_data_series @new_data_series = new_data_series
mail(:to => ["btrevino@hawaii.edu","james29@hawaii.edu", "icintina@gmail.com", "bonham@hawaii.edu"], :subject => subject) #{}) mail(:to => ["btrevino@hawaii.edu","james29@hawaii.edu", "icintina@gmail.com", "bonham@hawaii.edu"], :subject => subject) #{})
end end

def prognoz_notification(recipients, send_edition)
path = "/Volumes/UHEROwork/data/prognoz_export/ready_to_send_zip_files/"
filename = send_edition + ".zip"
attachments[filename] = File.read(path+filename)
subject = "Prognoz Export"
mail(:to => recipients, :subject => subject)
end
end end
26 changes: 26 additions & 0 deletions app/models/prognoz_data_file.rb
@@ -1,6 +1,32 @@
class PrognozDataFile < ActiveRecord::Base class PrognozDataFile < ActiveRecord::Base
serialize :series_loaded, Hash serialize :series_loaded, Hash


def PrognozDataFile.send_prognoz_update(recipients = ["btrevino@hawaii.edu"])
folder = "/Volumes/UHEROwork/data/prognoz_export/"
filenames = ["Agriculture.xls", "CAFRCounties.xls", "Kauai.xls", "metatable_isdi.xls", "SourceDoc.xls", "TableTemplate.xls"]
filenames.map! {|elem| folder+elem}

send_edition = Time.now.strftime("%yM%mD%d_%H%M%S")


retired_path = "/Volumes/UHEROwork/data/prognoz_export/exports/retired_official_versions/" + send_edition
Dir.mkdir(retired_path) unless File.directory?(retired_path)

self.all.each do |pdf|
puts pdf.filename
updated_file = pdf.filename.gsub("/prognoz_export/","/prognoz_export/exports/")
original_file = pdf.filename
FileUtils.mv(original_file, retired_path+"/"+pdf.filename.split("/")[-1])
FileUtils.cp(updated_file, original_file)
filenames.push pdf.filename
end

Zip::ZipFile.open(folder + "ready_to_send_zip_files/" + send_edition + ".zip", Zip::ZipFile::CREATE) do |zipfile|
filenames.each {|fname| zipfile.add(fname.split("/")[-1], fname)}
end

PackagerMailer.prognoz_notification(recipients, send_edition).deliver
end


def update_spreadsheet def update_spreadsheet
os = UpdateSpreadsheet.new filename os = UpdateSpreadsheet.new filename
Expand Down
3 changes: 1 addition & 2 deletions app/views/prognoz_data_files/index.html.erb
Expand Up @@ -9,9 +9,8 @@
div#all_charts {clear:both;} div#all_charts {clear:both;}
</style> </style>



<p class="notice"><%= notice %></p>
<h1>Prognoz Output Files</h2> <h1>Prognoz Output Files</h2>
<p><%= link_to "Export" , "/send_prognoz_export" %></p>
<p> <p>
<% @output_files.each do |data_file| %> <% @output_files.each do |data_file| %>
<%= link_to data_file.name , {:action => 'show', :id => data_file.id} %> | <%= link_to data_file.name , {:action => 'show', :id => data_file.id} %> |
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -65,6 +65,7 @@
resources :data_lists resources :data_lists




match 'send_prognoz_export' => 'prognoz_data_files#send_prognoz_export'
match 'investigate' => 'dashboards#investigate' match 'investigate' => 'dashboards#investigate'
match 'investigate_visual' => 'dashboards#investigate_visual' match 'investigate_visual' => 'dashboards#investigate_visual'
match 'investigate_no_source' => 'dashboards#investigate_no_source' match 'investigate_no_source' => 'dashboards#investigate_no_source'
Expand Down
15 changes: 1 addition & 14 deletions lib/tasks/INVESTIGATE.rake
Expand Up @@ -23,40 +23,27 @@ task :gen_prognoz_diffs => :environment do
t = Time.now t = Time.now
diff_data = [] diff_data = []


folder = "/Volumes/UHEROwork/data/prognoz_export/"
filenames = ["Agriculture.xls", "CAFRCounties.xls", "Kauai.xls", "metatable_isdi.xls", "SourceDoc.xls", "TableTemplate.xls"]
filenames.map! {|elem| folder+elem}


PrognozDataFile.all.each do |pdf| PrognozDataFile.all.each do |pdf|
t1 = Time.now t1 = Time.now
os = UpdateSpreadsheet.new pdf.filename os = UpdateSpreadsheet.new pdf.filename
os.headers_with_frequency_code.each do |header| os.headers_with_frequency_code.each do |header|
#puts "checking #{header}"
diff_data.push({:pdf_id => pdf.id, :id => 0, :name => header, :display_array => [-1]}) if header.ts.nil? diff_data.push({:pdf_id => pdf.id, :id => 0, :name => header, :display_array => [-1]}) if header.ts.nil?
next if header.ts.nil? next if header.ts.nil?
ddiff = header.ts.data_diff(os.series(header.split(".")[0]), 3) ddiff = header.ts.data_diff(os.series(header.split(".")[0]), 3)
#next if ddiff[:diffs].count == 0
diff_hash = ddiff[:display_array] diff_hash = ddiff[:display_array]
diff_data.push({:pdf_id => pdf.id, :id => header.ts.id, :name => header, :display_array => diff_hash}) if diff_hash.count > 0 diff_data.push({:pdf_id => pdf.id, :id => header.ts.id, :name => header, :display_array => diff_hash}) if diff_hash.count > 0
end end
filenames.push pdf.filename.gsub("/prognoz_export/","/prognoz_exports/exports")
pdf.write_export pdf.write_export
puts "#{"%.2f" %(Time.now - t1)} | #{pdf.filename}" puts "#{"%.2f" %(Time.now - t1)} | #{pdf.filename}"
end end


Zip::ZipFile.open(folder + "ready_to_send_zip_files/" + Date.today.strftime("%yM%mD%d") + ".zip", Zip::ZipFile::CREATE) do |zipfile|
filenames.each {|fname| zipfile.add(fname.split("/")[-1], fname)}
end

CSV.open("public/prognoz_diffs.csv", "wb") do |csv| CSV.open("public/prognoz_diffs.csv", "wb") do |csv|
diff_data.each do |dd| diff_data.each do |dd|
csv << [dd[:pdf_id]]+[dd[:name]] + [dd[:id]] + dd[:display_array] csv << [dd[:pdf_id]]+[dd[:name]] + [dd[:id]] + dd[:display_array]
end end
end end


# PrognozDataFile.all.each do |pdf|
# pdf.write_export
# end
CSV.open("public/rake_time.csv", "a") {|csv| csv << ["gen_prognoz_diffs", "%.2f" % (Time.now - t) , t.to_s, Time.now.to_s] } CSV.open("public/rake_time.csv", "a") {|csv| csv << ["gen_prognoz_diffs", "%.2f" % (Time.now - t) , t.to_s, Time.now.to_s] }
end end


Expand Down
6 changes: 6 additions & 0 deletions lib/tasks/exports.rake
Expand Up @@ -10,6 +10,12 @@ task :aremos_exports => :environment do


#BLS #BLS
DataList.write "bls_job_m", "/Volumes/UHEROwork/data/udaman/bls_job_m_UDA.xls" #25.5 DataList.write "bls_job_m", "/Volumes/UHEROwork/data/udaman/bls_job_m_UDA.xls" #25.5

#pseudo spline
DataList.write "famsize_q", "/Volumes/UHEROwork/data/udaman/famsize_q.xls" # 1.05
DataList.write "famsize_a", "/Volumes/UHEROwork/data/udaman/famsize_a.xls" #0.1


CSV.open("public/rake_time.csv", "a") {|csv| csv << ["aremos_exports", "%.2f" % (Time.now - t) , t.to_s, Time.now.to_s] } CSV.open("public/rake_time.csv", "a") {|csv| csv << ["aremos_exports", "%.2f" % (Time.now - t) , t.to_s, Time.now.to_s] }
end end


Expand Down

0 comments on commit 01d313f

Please sign in to comment.