Skip to content

Commit

Permalink
Add code to export csv for voting visualisation
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed May 16, 2022
1 parent b24c978 commit 1d75545
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ coverage

# Ignore the images generated by the rake task application:generate:cards
public/cards

# Ignore output of "export" rake tasks
distances.csv
people.csv
21 changes: 21 additions & 0 deletions lib/tasks/application.rake
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,25 @@ namespace :application do
CardScreenshotter::PoliciesCategory.run
end
end

namespace :export do
# Data required for visualisation at https://github.com/openaustralia/visualise-votes-mds/blob/main/notebook.ipynb
desc "Export csv files required for voting visualisation"
task voting_visualisation: :environment do
# Export distances.csv
p = Member.current.where(house: "representatives").pluck(:person_id)
d = PeopleDistance.where(person1: p, person2: p).pluck(:person1_id, :person2_id, :distance_b)
File.open("distances.csv", "w") do |f|
f.write(%w[person1_id person2_id distance_b].to_csv)
d.each { |l| f.write(l.to_csv) }
end

# Export people.csv
info = Member.current.where(house: "representatives").map { |m| [m.person.id, m.person.name, m.person.latest_member.party] }
File.open("people.csv", "w") do |f|
f.write(%w[id name party].to_csv)
info.each { |l| f.write(l.to_csv) }
end
end
end
end

0 comments on commit 1d75545

Please sign in to comment.