From bb65adfb61bced51b8f473b994a36faea6e18753 Mon Sep 17 00:00:00 2001 From: Oliver Gaskell Date: Sat, 1 Nov 2025 13:16:48 +0000 Subject: [PATCH] engine: add format_location, fix EncodedLocation type --- engine.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/engine.py b/engine.py index 0f811d9..46cad73 100755 --- a/engine.py +++ b/engine.py @@ -7,7 +7,7 @@ BRANDS: dict[str, str] = { "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]]: @@ -36,7 +36,10 @@ def encode(location: tuple[float, float]) -> EncodedLocation: """Encode a location.""" # Stub - return [] + return [ + (5., [1., 2., 3.]), + (6., [4., 5., 6.]), + ] def decode(location: EncodedLocation) -> tuple[float, float]: @@ -46,12 +49,19 @@ def decode(location: EncodedLocation) -> tuple[float, float]: 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(): """Testing.""" print("Running query...") greggs = fetch_data("greggs") print(f"Query done - got {len(greggs)} Greggs!") + print(format_location(encode((0.091659, 52.210796)))) + if __name__ == "__main__": main()