Skip to content

Commit

Permalink
moved the aliasing logic to an own processor
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Aug 7, 2024
1 parent 92f6d87 commit b419148
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
4 changes: 4 additions & 0 deletions data/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import processors.areatree.process as areatree
import processors.maps.process as maps
from processors import (
aliases,
coords,
export,
images,
Expand Down Expand Up @@ -115,6 +116,9 @@ def main() -> None:
logging.info("-- 97 Search: Get combined ranking")
search.add_ranking_combined(data)

logging.info("-- 98 Aliases: extract aliases")
aliases.add_aliases(data)

logging.info("-- 100 Export and generate Sitemap")
# the root entry is somewhat arbitrary
# leaving it here and thus having it delivered by the other apis leads to bad ergonomics
Expand Down
18 changes: 18 additions & 0 deletions data/processors/aliases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import Any



def extract_arch_name(entry: dict) -> str | None:
"""Extract the arch name from the entry"""
if entry["type"] == "building":
return f"@{entry['id']}"
return entry.get("tumonline_data", {}).get("arch_name", None)

def add_aliases(data: dict[str, dict[str, Any]]) -> None:
"""Add coordinates to all entries and check for issues"""

for _id, entry in data.items():
entry["aliases"] = []
if arch_name := extract_arch_name(entry):
entry["arch_name"] = arch_name,
entry["aliases"].append(arch_name)
14 changes: 1 addition & 13 deletions data/processors/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def export_for_search(data: dict) -> None:
"ms_id": _id.replace(".", "-"),
"id": _id, # not searchable
"name": entry["name"],
"arch_name": extract_arch_name(entry),
"arch_name": entry.get("arch_name"),
"type": entry["type"],
"type_common_name": entry["type_common_name"],
"facet": {
Expand Down Expand Up @@ -118,13 +118,6 @@ def extract_parent_building_names(data: dict, parents: list[str], building_paren
return short_names + long_names


def extract_arch_name(entry: dict) -> str | None:
"""Extract the arch name from the entry"""
if entry["type"] == "building":
return f"@{entry['id']}"
return entry.get("tumonline_data", {}).get("arch_name", None)


def _make_sure_is_safe(obj: object):
"""
Check if any of the specified names in removed_names are present
Expand Down Expand Up @@ -174,11 +167,6 @@ def export_for_api(data: dict) -> None:
export_data = []
for _id, entry in data.items():
entry.setdefault("maps", {})["default"] = "interactive"

entry["aliases"] = []
if arch_name := extract_arch_name(entry):
entry["aliases"].append(arch_name)

export_data.append(extract_exported_item(data, entry))

_make_sure_is_safe(export_data)
Expand Down

0 comments on commit b419148

Please sign in to comment.