Skip to content
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

Bugfix/fix country code in osm mapping #64

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions charging_stations_pipelines/pipelines/de/bna_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ def map_address_bna(row, station_id) -> Address:
if len(postcode) == 4:
postcode = "0" + postcode
if len(postcode) != 5:
logger.warning(
logger.debug(
f"Failed to process postcode {postcode}! Will set postcode to None!"
)
postcode = None
if len(town) < 2:
logger.warning(f"Failed to process town {town}! Will set town to None!")
logger.debug(f"Failed to process town {town}! Will set town to None!")
town = None
map_address = Address()
map_address.street = (street,)
Expand Down
5 changes: 3 additions & 2 deletions charging_stations_pipelines/pipelines/osm/osm_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@
]


def map_station_osm(entry: JSON) -> Station:
def map_station_osm(entry: JSON, country_code: str) -> Station:
"""Maps an entry from OpenStreetMap to a Station object.

:param entry: The entry from OpenStreetMap to be mapped.
:param country_code: The country code for which this mapping is executed.
:return: The mapped Station object.
"""
lat = check_coordinates(entry.get("lat"))
lon = check_coordinates(entry.get("lon"))

new_station = Station()
new_station.country_code = str_strip_whitespace(entry.get("country_code")) or None
new_station.country_code = country_code
new_station.source_id = entry.get("id") or None
new_station.operator = (
str_strip_whitespace(entry.get("tags", {}).get("operator")) or None
Expand Down
3 changes: 1 addition & 2 deletions test/pipelines/osm/test_osm_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
[
(
{
"country_code": "FR",
"id": 2144376575,
"lat": 48.0449426,
"lon": -1.602638,
Expand Down Expand Up @@ -57,7 +56,7 @@
],
)
def test_station_mapping(test_data, expected):
s = osm_mapper.map_station_osm(test_data)
s = osm_mapper.map_station_osm(test_data, "FR")
assert s.country_code == expected["country_code"]
assert s.source_id == expected["source_id"]
assert s.operator == expected["operator"]
Expand Down
Loading