-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements to Mapit::Wrapper and Mapit::Place #87
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bed4b3a
Rename Mapit::Place's 'place' instance variable to 'mapit_area_data'
mhl b57da5c
Remove hardcoded area types from Mapit::Wrapper
mhl 35a7e2d
Simplify Mapit::Wrapper and make it more efficient
mhl 01c4c92
Add current nigeria.mapit.mysociety.org data for FED, SEN and STA
mhl a53b196
Use the full MapIt data in tests rather than the reduced fixtures
mhl fdeb31c
Switch to using the local copy of the MapIt Area data
mhl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,35 @@ | ||
# frozen_string_literal: true | ||
module Mapit | ||
class Place | ||
def initialize(place:, mapit_ids_to_pombola_slugs:, baseurl:) | ||
@place = place | ||
@mapit_ids_to_pombola_slugs = mapit_ids_to_pombola_slugs | ||
attr_accessor :parent | ||
|
||
def initialize(mapit_area_data:, pombola_slug:, baseurl:, parent: nil) | ||
@mapit_area_data = mapit_area_data | ||
@pombola_slug = pombola_slug | ||
@baseurl = baseurl | ||
@parent = parent | ||
end | ||
|
||
def id | ||
place['id'] | ||
mapit_area_data['id'] | ||
end | ||
|
||
def name | ||
place['name'] | ||
mapit_area_data['name'] | ||
end | ||
|
||
def type_name | ||
place['type_name'] | ||
mapit_area_data['type_name'] | ||
end | ||
|
||
def parent_name | ||
place['parent_name'] | ||
end | ||
alias_method :is_child_area?, :parent | ||
|
||
def url | ||
build_url(place['id']) if place['id'] | ||
end | ||
|
||
def parent_url | ||
build_url(place['parent_id']) if place['parent_id'] | ||
end | ||
|
||
def is_child_area? | ||
!place['parent_name'].nil? | ||
"#{baseurl}#{pombola_slug}/" | ||
end | ||
|
||
private | ||
|
||
attr_reader :place, :mapit_ids_to_pombola_slugs, :baseurl | ||
|
||
def build_url(id) | ||
"#{baseurl}#{pombola_slug(id)}/" | ||
end | ||
|
||
def pombola_slug(id) | ||
mapit_ids_to_pombola_slugs[id.to_s] | ||
end | ||
attr_reader :mapit_area_data, :pombola_slug, :baseurl | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"2": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 2, "codes": {"poll_unit": "AB"}, "name": "Abia", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "3": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 3, "codes": {"poll_unit": "AD"}, "name": "Adamawa", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "4": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 4, "codes": {"poll_unit": "AK"}, "name": "Akwa Ibom", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "5": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 5, "codes": {"poll_unit": "AN"}, "name": "Anambra", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "6": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 6, "codes": {"poll_unit": "BA"}, "name": "Bauchi", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "7": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 7, "codes": {"poll_unit": "BY"}, "name": "Bayelsa", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "8": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 8, "codes": {"poll_unit": "BE"}, "name": "Benue", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "9": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 9, "codes": {"poll_unit": "BO"}, "name": "Borno", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "10": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 10, "codes": {"poll_unit": "CR"}, "name": "Cross River", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "11": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 11, "codes": {"poll_unit": "DE"}, "name": "Delta", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "12": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 12, "codes": {"poll_unit": "EB"}, "name": "Ebonyi", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "13": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 13, "codes": {"poll_unit": "ED"}, "name": "Edo", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "14": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 14, "codes": {"poll_unit": "EK"}, "name": "Ekiti", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "15": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 15, "codes": {"poll_unit": "EN"}, "name": "Enugu", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "16": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 16, "codes": {"poll_unit": "FC"}, "name": "Federal Capital Territory", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "17": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 17, "codes": {"poll_unit": "GO"}, "name": "Gombe", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "18": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 18, "codes": {"poll_unit": "IM"}, "name": "Imo", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "19": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 19, "codes": {"poll_unit": "JI"}, "name": "Jigawa", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "20": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 20, "codes": {"poll_unit": "KD"}, "name": "Kaduna", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "21": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 21, "codes": {"poll_unit": "KN"}, "name": "Kano", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "22": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 22, "codes": {"poll_unit": "KT"}, "name": "Katsina", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "23": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 23, "codes": {"poll_unit": "KE"}, "name": "Kebbi", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "24": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 24, "codes": {"poll_unit": "KO"}, "name": "Kogi", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "25": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 25, "codes": {"poll_unit": "KW"}, "name": "Kwara", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "26": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 26, "codes": {"poll_unit": "LA"}, "name": "Lagos", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "27": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 27, "codes": {"poll_unit": "NA"}, "name": "Nassarawa", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "28": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 28, "codes": {"poll_unit": "NI"}, "name": "Niger", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "29": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 29, "codes": {"poll_unit": "OG"}, "name": "Ogun", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "30": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 30, "codes": {"poll_unit": "ON"}, "name": "Ondo", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "31": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 31, "codes": {"poll_unit": "OS"}, "name": "Osun", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "32": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 32, "codes": {"poll_unit": "OY"}, "name": "Oyo", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "33": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 33, "codes": {"poll_unit": "PL"}, "name": "Plateau", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "34": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 34, "codes": {"poll_unit": "RI"}, "name": "Rivers", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "35": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 35, "codes": {"poll_unit": "SO"}, "name": "Sokoto", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "36": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 36, "codes": {"poll_unit": "TA"}, "name": "Taraba", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "37": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 37, "codes": {"poll_unit": "YO"}, "name": "Yobe", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}, "38": {"parent_area": null, "generation_high": 1, "all_names": {}, "id": 38, "codes": {"poll_unit": "ZA"}, "name": "Zamfara", "country": "N", "type_name": "State", "generation_low": 1, "country_name": "Nigeria", "type": "STA"}} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are building these hashes, it may be a better idea to use symbols for the hash key. This is a common practice in Ruby as symbols are more performant than strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I know that's often done, but I don't think that's worth it in this case. Area type codes often come from MapIt calls, which will return them from JSON strings, and when you use them in queries to MapIt, you need them to be strings then as well. Transforming those strings to and from symbols for any input and output like that seems unnecessary, given that the performance impact from using strings instead of hash keys in going to be tiny in this app.