Skip to content

Commit

Permalink
update budgets to 2010
Browse files Browse the repository at this point in the history
  • Loading branch information
salicio committed Oct 31, 2011
1 parent a98dca7 commit 4ea6c57
Show file tree
Hide file tree
Showing 117 changed files with 14,336 additions and 407 deletions.
2 changes: 0 additions & 2 deletions app/models/municipio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class Municipio < ActiveRecord::Base
has_many :presupuestos
has_many :demograficas

validates_uniqueness_of :slug

def province_name
PROVINCES[provincia]
end
Expand Down
16 changes: 9 additions & 7 deletions app/views/municipios/evolution.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

<%= render :partial => 'shared/timeline', :locals => { :muni => @muni } %>

<% last_year = Date.today.year-1 %>

<script type="text/javascript" charset="utf-8">
var states = [1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009];
var states = [<%= (1985..last_year).to_a.join(',') %>];

window.onload = function () {
income_evolution();
Expand All @@ -23,10 +25,10 @@
};

var values = [
<% (1985..2009).each do |year| -%>
<% (1985..last_year).each do |year| -%>
<% budget = @muni.budget_for(year) -%>
<% if budget -%>
<%= budget.total_ingresos -%><%= year == 2009 ? "" : "," -%>
<%= budget.total_ingresos -%><%= year == last_year ? "" : "," -%>
<% else -%>0,<% end -%>
<% end -%>
];
Expand All @@ -44,10 +46,10 @@
};

var values = [
<% (1985..2009).each do |year| -%>
<% (1985..last_year).each do |year| -%>
<% budget = @muni.budget_for(year) -%>
<% if budget -%>
<%= budget.total_gastos -%><%= year == 2009 ? "" : "," -%>
<%= budget.total_gastos -%><%= year == last_year ? "" : "," -%>
<% else -%>0,<% end -%>
<% end -%>
];
Expand All @@ -65,10 +67,10 @@
};

var values = [
<% (1985..2009).each do |year| -%>
<% (1985..last_year).each do |year| -%>
<% demographic = @muni.demographics_for(year) -%>
<% if demographic -%>
<%= demographic.total -%><%= year == 2009 ? "" : "," -%>
<%= demographic.total -%><%= year == last_year ? "" : "," -%>
<% else -%>0,<% end -%>
<% end -%>
];
Expand Down
2 changes: 1 addition & 1 deletion app/views/municipios/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
<hr/>
Comparar con <input id="city_search" autofocus type='text' placeholder='Search inside'>
<hr/>
<% (1985..2009).each do |year| %>
<% (1985..Date.today.year-1).each do |year| %>
<%= link_to year, city_card_by_year_path(@muni, year) %>
<% end %>
<hr/>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_timeline.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p class="years_nav years_prev" id="mycarousel-prev"><a href="#">&larr; años anteriores</a></p>
<p class="years_nav years_next" id="mycarousel-next"><a href="#">años siguientes &rarr;</a></p>
<ul id="budget_timeline" class="timeline_years">
<% (1985..2009).each do |year| %>
<% (1985..Date.today.year-1).each do |year| %>
<li <%= (year == @year) ? "class='actual_year'": '' %>><%= link_to year, city_card_by_year_path(muni, year) %></li>
<% end %>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/views/static/about.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<h1>Lospresus.de qué van</h1>

<p>Lospresus.de es un sitio web con el que queremos analizar los ingresos y gastos municipales de todos los municipios de España basándonos en sus presupuestos oficiales. Estos presupuestos oficiales los obtenemos del <a href="http://www.dgal.map.es/cgi-bin/webapb/webdriver?MIval=presmun">Ministerio de Política Territorial</a>.</p>
<p>Lospresus.de es un sitio web con el que queremos analizar los ingresos y gastos municipales de todos los municipios de España basándonos en sus presupuestos oficiales. Estos presupuestos oficiales los obtenemos del <a href="http://cooplocal.mpt.es/cgi-bin/webapb/webdriver?MIval=presmun">Ministerio de Política Territorial</a>.</p>

<p>No es la fuente de datos ideal por dos cuestiones:</p>

Expand Down
24 changes: 24 additions & 0 deletions data/download_budgets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'net/http'

# download budgets
# http://cooplocal.mpt.es/cgi-bin/webapb/webdriver?MIval=presmun_fichero&anualidad=1985&prov=48

puts "Download budgets"
(1..52).each do |prov|
print "prov:#{prov}"
(1985..2010).each do |year|
begin
Net::HTTP.start("cooplocal.mpt.es") do |http|
resp = http.get("/cgi-bin/webapb/webdriver?MIval=presmun_fichero&anualidad=#{year}&prov=#{prov}")
open("presupuestos/#{prov}-#{year}.csv", "wb") do |file|
file.write(resp.body)
end
end
print "."
rescue Exception => e
print " ERROR:#{year} "
end
STDOUT.flush
end
puts ""
end
Loading

0 comments on commit 4ea6c57

Please sign in to comment.