govkit-ca 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gov_kit-ca/represent.rb +30 -0
- data/lib/gov_kit-ca/version.rb +1 -1
- data/tasks/tasks.rb +4 -16
- metadata +2 -3
- data/USAGE +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 552c21addb48040ade097636fd88ec1e60464d4b
|
4
|
+
data.tar.gz: 4a99ef183fefcddfdd06516aaaf968c8bcb55f03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 964b1d7bfb550b526a8ed5cc7cd7f093aab3d2f096f182abe41a492e867fcf43ab31d115051f53968665da977cdc07abb95c41e50de1dc533f79b66be9d082ea
|
7
|
+
data.tar.gz: e9f9c2b9923969bbdf265a5fcef8d376058fcd87ed067e22068137a800f88786c5f7e0c09ba5da825cc3efc2c1c4e3efefffb90cd425b4f8a0caa97ff90c86e9
|
data/lib/gov_kit-ca/represent.rb
CHANGED
@@ -73,6 +73,17 @@ module GovKit
|
|
73
73
|
request ['representative-sets', opts.delete(:representative_set)], opts
|
74
74
|
end
|
75
75
|
|
76
|
+
# Get elections.
|
77
|
+
#
|
78
|
+
# @param [Hash] opts optional arguments
|
79
|
+
# @option opts [String] :election an election
|
80
|
+
# @option opts [Integer] :limit
|
81
|
+
# @option opts [Integer] :offset
|
82
|
+
# @see https://represent.opennorth.ca/api/#election
|
83
|
+
def elections(opts = {})
|
84
|
+
request ['elections', opts.delete(:election)], opts
|
85
|
+
end
|
86
|
+
|
76
87
|
# Get representatives.
|
77
88
|
#
|
78
89
|
# @param [Hash] opts optional arguments
|
@@ -92,6 +103,25 @@ module GovKit
|
|
92
103
|
request(['representatives', opts.delete(:representative_set)], opts)
|
93
104
|
end
|
94
105
|
|
106
|
+
# Get candidates.
|
107
|
+
#
|
108
|
+
# @param [Hash] opts optional arguments
|
109
|
+
# @option opts [String] :electon an election
|
110
|
+
# @option opts [Array<Float>,String] :point a comma-separated latitude and longitude
|
111
|
+
# @option opts [Array<Strong>,String] :districts a comma-separated list of boundaries
|
112
|
+
# @option opts [Integer] :limit
|
113
|
+
# @option opts [Integer] :offset
|
114
|
+
# @see https://represent.opennorth.ca/api/#candidate
|
115
|
+
def candidates(opts = {})
|
116
|
+
if Array === opts[:point]
|
117
|
+
opts[:point] = opts[:point].join(',')
|
118
|
+
end
|
119
|
+
if Array === opts[:districts]
|
120
|
+
opts[:districts] = opts[:districts].join(',')
|
121
|
+
end
|
122
|
+
request(['candidates', opts.delete(:candidate)], opts)
|
123
|
+
end
|
124
|
+
|
95
125
|
private
|
96
126
|
|
97
127
|
def request(parts, opts)
|
data/lib/gov_kit-ca/version.rb
CHANGED
data/tasks/tasks.rb
CHANGED
@@ -1,20 +1,7 @@
|
|
1
1
|
require File.expand_path('../../lib/gov_kit-ca', __FILE__)
|
2
2
|
|
3
|
-
# The following file maps 629,605 postal codes to electoral districts:
|
4
|
-
# https://github.com/danielharan/canadian-postal-code-to-electoral-districts/raw/master/pc_edid.yml
|
5
|
-
# However, it contains invalid postal codes, such as M5V1L6, and doesn't contain
|
6
|
-
# every electoral district, such as 35061 (postal code L1H1X8).
|
7
|
-
#
|
8
|
-
# http://www.digital-copyright.ca/pcfrf/pcfrf.tgz contains
|
9
|
-
# postal-code-for-districts.csv, "which is 308 postal codes that should map to
|
10
|
-
# each of the 308 different electoral districts." However, six of them do not
|
11
|
-
# exist (G0A2C0, J8M1R8, J0W1B0, J0B1H0, L0J1B0, N2A1A3), 14 are duplicate, and
|
12
|
-
# the remaining 294 map to 246 electoral districts.
|
13
|
-
#
|
14
|
-
# The included tasks/postal-code-for-districts.csv covers 275 electoral
|
15
|
-
# districts at the time of writing.
|
16
3
|
desc "Picks the set cover for postal codes to electoral districts"
|
17
|
-
task :
|
4
|
+
task :set_cover, :file do |t,args|
|
18
5
|
abort "Usage: rake #{t.name}[postal-code-for-districts.csv]" unless args[:file]
|
19
6
|
|
20
7
|
# Get the electoral districts that each postal code covers
|
@@ -23,12 +10,13 @@ task :trim_postal_codes, :file do |t,args|
|
|
23
10
|
postal_to_edid[postal_code] = GovKit::CA::PostalCode.find_electoral_districts_by_postal_code(postal_code)
|
24
11
|
end
|
25
12
|
|
13
|
+
# Report how many electoral districts are covered.
|
26
14
|
size = postal_to_edid.values.flatten.uniq.size
|
27
15
|
if size < 308
|
28
|
-
puts "Postal codes cover #{size}
|
16
|
+
puts "Postal codes cover #{size} electoral districts."
|
29
17
|
end
|
30
18
|
|
31
|
-
# Get the minimum number of postal codes to cover
|
19
|
+
# Get the minimum number of postal codes to cover the electoral districts.
|
32
20
|
# This is an instance of the set cover problem, which is NP-complete. Use the
|
33
21
|
# greedy algorithm, which is the best-possible polynomial time approximation
|
34
22
|
# algorithm for set cover. https://en.wikipedia.org/wiki/Set_cover_problem
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govkit-ca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Open North
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -138,7 +138,6 @@ files:
|
|
138
138
|
- LICENSE
|
139
139
|
- README.md
|
140
140
|
- Rakefile
|
141
|
-
- USAGE
|
142
141
|
- govkit-ca.gemspec
|
143
142
|
- lib/gov_kit-ca.rb
|
144
143
|
- lib/gov_kit-ca/postal_code.rb
|
data/USAGE
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
See README.md for full usage details.
|