Skip to content

Commit

Permalink
Merge pull request #215 from caciviclab/add-to-totals-json
Browse files Browse the repository at this point in the history
Add `largest_independent_expenditures` to totals.json
  • Loading branch information
tdooner authored Feb 26, 2020
2 parents 6c3afb2 + e7f9f10 commit 0066dfa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ cache:
addons:
postgresql: '9.6'
script:
- make clean download import process && ./bin/travis-deploy
- make clean download import process -j2 && ./bin/travis-deploy
2 changes: 1 addition & 1 deletion calculators/election_largest_independent_expenditure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def fetch
top_spenders = top_spenders_by_election[election.name]
next unless top_spenders

election.save_calculation(:largest_indpendent_expenditures, top_spenders)
election.save_calculation(:largest_independent_expenditures, top_spenders)
end
end
end
31 changes: 16 additions & 15 deletions process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
require 'i18n'
require 'open-uri'

# map of election_name => { hash including date }
ELECTIONS = ActiveRecord::Base.connection.execute(<<-SQL).index_by { |row| row['name'] }.transform_values(&:symbolize_keys)
SELECT * from elections;
SQL
# map of election_name => Election object
ELECTIONS = Election.all.index_by(&:name)

def build_file(filename, &block)
filename = File.expand_path('../build', __FILE__) + filename
Expand Down Expand Up @@ -215,9 +213,9 @@ def slugify(word)
end

# /_referendums/oakland/2018-11-06/oakland-childrens-initiative.md
build_file("/_referendums/#{locality}/#{election[:date]}/#{title}.md") do |f|
build_file("/_referendums/#{locality}/#{election.date}/#{title}.md") do |f|
f.puts(YAML.dump(
'election' => election[:date],
'election' => election.date,
'locality' => locality,
'number' => referendum['Measure_number'] =~ /PENDING/ ? nil : referendum['Measure_number'],
'title' => referendum['Short_Title'],
Expand All @@ -228,7 +226,7 @@ def slugify(word)
end

# /_data/referendum_supporting/oakland/2018-11-06/oakland-childrens-initiative.json
build_file("/_data/referendum_supporting/#{locality}/#{election[:date]}/#{title}.json") do |f|
build_file("/_data/referendum_supporting/#{locality}/#{election.date}/#{title}.json") do |f|
f.puts JSON.pretty_generate(referendum.as_json.merge(
contributions_by_region: referendum.calculation(:supporting_locales) || [],
contributions_by_type: referendum.calculation(:supporting_type) || [],
Expand All @@ -238,7 +236,7 @@ def slugify(word)
end

# /_data/referendum_opposing/oakland/2018-11-06/oakland-childrens-initiative.json
build_file("/_data/referendum_opposing/#{locality}/#{election[:date]}/#{title}.json") do |f|
build_file("/_data/referendum_opposing/#{locality}/#{election.date}/#{title}.json") do |f|
f.puts JSON.pretty_generate(referendum.as_json.merge(
contributions_by_region: referendum.calculation(:opposing_locales) || [],
contributions_by_type: referendum.calculation(:opposing_type) || [],
Expand All @@ -249,7 +247,16 @@ def slugify(word)
end

build_file('/_data/totals.json') do |f|
f.puts JSON.pretty_generate(Hash[ContributionsByOrigin.sort])
f.puts JSON.pretty_generate(
Hash[ELECTIONS.map do |election_name, election|
[
election_name,
ContributionsByOrigin.fetch(election_name, {}).merge(
largest_independent_expenditures: election.calculation(:largest_independent_expenditures)
)
]
end]
)
end

build_file('/_data/stats.json') do |f|
Expand All @@ -259,9 +266,3 @@ def slugify(word)
date_processed: date_processed.to_s
)
end

build_file('/_data/largest_indpendent_expenditures.json') do |f|
f.puts JSON.pretty_generate(Election.all.map do |e|
[e.name, e.calculation(:largest_indpendent_expenditures)]
end.to_h)
end

0 comments on commit 0066dfa

Please sign in to comment.