Skip to content

Commit

Permalink
some depth first graph traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
bentut committed Feb 27, 2013
1 parent 4267fee commit 0f86d12
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 474 deletions.
21 changes: 21 additions & 0 deletions app/models/series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ def scaled_data_no_pseudo_history(round_to = 3)
data_hash
end

def Series.new_from_data(frequency, data)
Series.new_transformation("One off data", data, frequency)
end

def Series.new_transformation(name, data, frequency)
Series.new(
:name => name,
Expand Down Expand Up @@ -779,6 +783,23 @@ def last_data_added_string
last_data_added.strftime("%B %e, %Y")
end

def Series.run_all_dependencies(series_list, already_run)
series_list.each do |s_name|
next unless already_run.index(s_name).nil?
s = s_name.ts
begin
already_run = Series.run_all_dependencies(s.new_dependencies, already_run)
rescue
puts "THIS IS THE ONE THAT BROKE"
puts s.id
puts s.name
end
s.reload_sources
already_run.push(s_name)
end
return already_run
end

def Series.smart_update(series_names_finished = [], series_to_finish = Series.all, depth = 0 )
return series_to_finish if series_to_finish.count == 0 or depth == 25
series_to_finish_new = []
Expand Down
1 change: 0 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
Chart Boards: 
<a href="/construction">Construction (M)</a> |
<a href="/construction_q">Construction (Q)</a> |
<a href="/permits">Permits</a> |
<a href="/hbr_mbr">HBR / MBR</a> |
<a href="/prudential">Prudential</a> |
<a href="/employment">Employment (HI)</a> |
Expand Down
2 changes: 1 addition & 1 deletion app/views/series/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ google.visualization.events.addListener(chart, 'select', function() {
<%= link_to 'Blog Chart', :action => 'blog_graph', :id => @series %>

<div id="chart_div"></div>

<div id="notes"><p><%= @series.investigation_notes %></p></div>

</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions config/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@

#alternatives in case of emergency

# every 1.day, :at => "12:00 pm" do
# every 1.day, :at => "12:05 pm" do
# rake "update_bea_links"
# end
#
# every 1.day, :at => "12:00 pm" do
# every 1.day, :at => "12:05 pm" do
# rake "jp_upd_a"
# rake "jp_upd_q"
# rake "jp_upd_m"
Expand Down
18 changes: 13 additions & 5 deletions lib/series_relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ def Series.find_first_order_circular
#puts series.name
fod = series.first_order_dependencies
fod.each do |dependent_series|
circular_series.push(dependent_series) unless dependent_series.ts.first_order_dependencies.index(series.name).nil?
begin
circular_series.push(dependent_series) unless dependent_series.ts.first_order_dependencies.index(series.name).nil?
rescue
puts "THIS BROKE"
puts dependent_series
puts series.name
puts series.id
end
end
end

Expand Down Expand Up @@ -120,10 +127,11 @@ def Series.print_multi_sources

def reload_sources
begin
self.data_sources_by_last_run.each do |ds|
ds.print_eval_statement
ds.reload_source
end
puts self.name
# self.data_sources_by_last_run.each do |ds|
# ds.print_eval_statement
# ds.reload_source
# end
return 0
rescue Exception
puts "SOMETHING BROKE -----------------------------------------------"
Expand Down
8 changes: 5 additions & 3 deletions lib/tasks/MISC.rake
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ end
task :const_upd_q => :environment do
t = Time.now
const_q = {

"KNRSDNS@HON.Q" => %Q|Series.load_from_download "QSER_G@hawaii.gov", { :file_type => "xls", :start_date => "1993-01-01", :sheet => "G-25", :row => "block:6:1:4", :col => "repeat:2:5", :frequency => "Q" }|,
"KNRSDNS@HAW.Q" => %Q|Series.load_from_download "QSER_G@hawaii.gov", { :file_type => "xls", :start_date => "1993-01-01", :sheet => "G-26", :row => "block:5:1:4", :col => "repeat:2:5", :frequency => "Q" }|,
"KNRSDNS@MAU.Q" => %Q|Series.load_from_download "QSER_G@hawaii.gov", { :file_type => "xls", :start_date => "1993-01-01", :sheet => "G-27", :row => "block:5:1:4", :col => "repeat:2:5", :frequency => "Q" }|,
"KNRSDNS@KAU.Q" => %Q|Series.load_from_download "QSER_G@hawaii.gov", { :file_type => "xls", :start_date => "1993-01-01", :sheet => "G-28", :row => "block:5:1:4", :col => "repeat:2:5", :frequency => "Q" }|,
"KPGOVNS@HI.Q" => %Q|Series.load_from_download "QSER_E@hawaii.gov", { :file_type => "xls", :start_date => "1998-01-01", :sheet => "E-1", :row => "increment:38:1", :col => 7, :frequency => "Q" }|,
"KPGOVNS@HI.Q" => %Q|Series.load_from_download "QSER_E@hawaii.gov", { :file_type => "xls", :start_date => "1998-01-01", :sheet => "E-1", :row => "increment:39:1", :col => 7, :frequency => "Q" }|,
"KNRSDNS@HI.Q" => %Q|Series.load_from_download "QSER_E@hawaii.gov", { :file_type => "xls", :start_date => "1982-01-01", :sheet => "E-3", :row => "block:5:1:4", :col => "repeat:2:5", :frequency => "Q" }|,
"KNRSDSGFNS@HI.Q" => %Q|Series.load_from_download "QSER_E@hawaii.gov", { :file_type => "xls", :start_date => "1982-01-01", :sheet => "E-4", :row => "block:5:1:4", :col => "repeat:2:5", :frequency => "Q" }|,
"KNRSDMLTNS@HI.Q" => %Q|Series.load_from_download "QSER_E@hawaii.gov", { :file_type => "xls", :start_date => "1982-01-01", :sheet => "E-5", :row => "block:5:1:4", :col => "repeat:2:5", :frequency => "Q" }|,
Expand Down Expand Up @@ -378,8 +379,9 @@ task :const_identities => :environment do

"PMKBSGF@HON.Q".ts_eval= %Q|"PMKBSGF@HON.M".ts.aggregate(:quarter, :average)|
"PMKBCON@HON.Q".ts_eval= %Q|"PMKBCON@HON.M".ts.aggregate(:quarter, :average)|
"PMKBSGF@HON.Q".ts_eval= %Q|"PMKBSGF@HON.Q".ts.trim("1980-01-01","1986-12-01")|
"PMKBCON@HON.Q".ts_eval= %Q|"PMKBCON@HON.Q".ts.trim("1980-01-01","1986-12-01")|
# Not sure why these were even here. Just circular references
# "PMKBSGF@HON.Q".ts_eval= %Q|"PMKBSGF@HON.Q".ts.trim("1980-01-01","1986-12-01")|
# "PMKBCON@HON.Q".ts_eval= %Q|"PMKBCON@HON.Q".ts.trim("1980-01-01","1986-12-01")|
"PMKRCON@HON.Q".ts_eval=%Q|"PMKRCON@HON.Q".ts.load_mean_corrected_sa_from "/Volumes/UHEROwork/data/misc/prud/seasadj/prud_sa.xls", "prud_sa" |
"PMKRSGF@HON.Q".ts_eval=%Q|"PMKRSGF@HON.Q".ts.load_mean_corrected_sa_from "/Volumes/UHEROwork/data/misc/prud/seasadj/prud_sa.xls", "prud_sa" |

Expand Down
Loading

0 comments on commit 0f86d12

Please sign in to comment.