engine: add format_location, fix EncodedLocation type

This commit is contained in:
Oliver Gaskell 2025-11-01 13:16:48 +00:00
parent f1afe22bac
commit bb65adfb61
No known key found for this signature in database
GPG key ID: F971A08925FCC0AD

View file

@ -7,7 +7,7 @@ BRANDS: dict[str, str] = {
"greggs": "[\"brand:wikidata\"=\"Q3403981\"]", "greggs": "[\"brand:wikidata\"=\"Q3403981\"]",
} }
EncodedLocation = list[float, list[float]] EncodedLocation = list[tuple[float, list[float]]]
def fetch_data(brand: str) -> list[tuple[float | None, float | None]]: def fetch_data(brand: str) -> list[tuple[float | None, float | None]]:
@ -36,7 +36,10 @@ def encode(location: tuple[float, float]) -> EncodedLocation:
"""Encode a location.""" """Encode a location."""
# Stub # Stub
return [] return [
(5., [1., 2., 3.]),
(6., [4., 5., 6.]),
]
def decode(location: EncodedLocation) -> tuple[float, float]: def decode(location: EncodedLocation) -> tuple[float, float]:
@ -46,12 +49,19 @@ def decode(location: EncodedLocation) -> tuple[float, float]:
return (0.091659, 52.210796) return (0.091659, 52.210796)
def format_location(location: EncodedLocation) -> str:
"""Format an encoded location as a string."""
return ";".join([f"{a}:{','.join(map(str, b))}" for (a, b) in location])
def main(): def main():
"""Testing.""" """Testing."""
print("Running query...") print("Running query...")
greggs = fetch_data("greggs") greggs = fetch_data("greggs")
print(f"Query done - got {len(greggs)} Greggs!") print(f"Query done - got {len(greggs)} Greggs!")
print(format_location(encode((0.091659, 52.210796))))
if __name__ == "__main__": if __name__ == "__main__":
main() main()