engine: add format_location, fix EncodedLocation type
This commit is contained in:
parent
f1afe22bac
commit
bb65adfb61
1 changed files with 12 additions and 2 deletions
14
engine.py
14
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue