Skip to content

Commit 7e64f6f

Browse files
authored
Merge pull request #157 from Datenschule/lat-lon
Fix swapped latitude and longitude for BY and NW
2 parents d6609f1 + 943ae8a commit 7e64f6f

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2025-04-30
4+
- [BY]: Latitude and Longitude were swapped in the database. This has been fixed.
5+
- [NW]: Latitude and Longitude were swapped in the database. This has been fixed.
6+
37
## 2025-04-22
48
- [HH]: The data now includes the location information from the WFS, filling the `location` field in the database
59
for the city of Hamburg for the first time

jedeschule/spiders/bayern.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def parse_resource(self, response, feature):
3535

3636
for entry in school:
3737
if entry.tag == "{http://gdi.bayern/brbschul}geometry":
38-
lat, lon = entry.findtext(
38+
lon, lat = entry.findtext(
3939
"gml:Point/gml:pos", namespaces=namespaces
4040
).split(" ")
4141
data_elem["lat"] = lat

jedeschule/spiders/nordrhein_westfalen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def normalize(item: Item) -> School:
4444
source_crs = item.get("EPSG")
4545
if source_crs == "null":
4646
source_crs = "EPSG:25832"
47-
transformer = Transformer.from_crs(source_crs, "EPSG:4326")
47+
transformer = Transformer.from_crs(source_crs, "EPSG:4326", always_xy=True)
4848
lon, lat = transformer.transform(right, high)
4949

5050
return School(

test_changes.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,39 @@ def fetch_data(school_id):
1515
return response.json()
1616

1717

18-
def sort_dict(data):
19-
return {key: value for key, value in sorted(data.items(), key=lambda k: k[0])}
20-
21-
2218
def get_clean_item(data):
23-
return set(
24-
{
19+
return {
2520
key: value
2621
for key, value in data.items()
2722
if value is not None and key != "update_timestamp"
2823
}
29-
)
3024

3125

32-
def compare_schools(new_school, old_school):
33-
new_school = sort_dict(new_school)
34-
old_school = sort_dict(old_school)
26+
def dict_diff(dict1, dict2):
27+
all_keys = set(dict1.keys()) | set(dict2.keys())
28+
29+
differences = {}
30+
for key in all_keys:
31+
val1 = dict1.get(key, None)
32+
val2 = dict2.get(key, None)
3533

34+
if val1 != val2:
35+
differences[key] = (val1, val2)
36+
37+
return differences
38+
39+
40+
def compare_schools(new_school, old_school):
3641
new_values = get_clean_item(new_school)
3742
old_values = get_clean_item(old_school)
3843

39-
differences = new_values ^ old_values
40-
if not differences:
44+
differences = dict_diff(new_values, old_values)
45+
if len(differences) == 0:
4146
print(" no changes \n")
4247
return
4348

44-
print(f"Difference: {differences}")
45-
print(f"Old: {old_school}")
46-
print(f"New: {new_school}")
49+
print(f"Difference found:")
50+
print(json.dumps(differences, indent=2))
4751

4852

4953
def main():

0 commit comments

Comments
 (0)