Skip to content

Commit

Permalink
fixed a shortcoming in the parsing of visible_id vs id vs type
Browse files Browse the repository at this point in the history
…in the areatree
  • Loading branch information
CommanderStorm committed Feb 26, 2024
1 parent 5920337 commit b5ec87a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data/processors/areatree/config.areatree
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@
5142:Parkhaus P1:
-5143:Versorgungsstation:
5160:UCN-Testanlage (Container):
:Max-Planck-Institut Garching:mpg[site],mpi # manually added, see NAT merger
:Max-Planck-Institut Garching:mpi,mpg[site] # manually added, see NAT merger
:Max-Planck-Institut für Plasmaphysik:ipp[building]
:Max-Planck-Institut für Astrophysik:mpa[building]
:Max-Planck-Institut für Biochemie:mpb[building]
Expand Down
4 changes: 4 additions & 0 deletions data/processors/areatree/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def _extract_id_and_type(internal_id: str, b_prefix: str | list[str] | None) ->
results: models.IdType = {"id": "", "type": ""}
if "[" in internal_id:
internal_id, results["type"] = internal_id.removesuffix("]").split("[")
if "," in results["type"]:
raise RuntimeError(f"can't parse {internal_id}."
f"The type has to be specified after specifying visible_ids."
f"try :id,visible_ids[type] instead")
if "," in internal_id:
ids = internal_id.split(",")
if len(ids) != 2:
Expand Down
10 changes: 10 additions & 0 deletions data/processors/areatree/test_areatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ def test_specified_type() -> None:
assert _extract_id_and_type("abc[building]", "cdf") == expected


def test_comma_specified_type() -> None:
"""If the building id is separated by a comma, it is split into a list"""

expected = {"id": "abc", "type": "building", 'visible_id': 'bcd'}
with pytest.raises(RuntimeError):
assert _extract_id_and_type("abc[building],bcd", None)
assert _extract_id_and_type("abc,bcd[building]", None) == expected
assert _extract_id_and_type("abc,bcd[building]", "cdf") == expected


def test_comma() -> None:
"""If the id is inferable from the line, it is returned"""
expected = {"id": "123", "visible_id": "visible_id", "type": "area"}
Expand Down
2 changes: 2 additions & 0 deletions data/processors/nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def _infer_internal_id(building, data):
if building.b_code.startswith("X"):
if building.b_code == "XUCL":
building.b_id = "origins-cluster"
elif building.b_code == "XMPG":
building.b_id = "mpi"
else:
building.b_id = building.b_code[1:].lower()

Expand Down

0 comments on commit b5ec87a

Please sign in to comment.