started writing decoder

This commit is contained in:
Izzy Cole 2025-11-01 19:32:04 +00:00
parent 3255e2e30f
commit 29d89eb42e

View file

@ -108,6 +108,36 @@ def encode(location: tuple[float, float]) -> EncodedLocation:
def decode(location: EncodedLocation) -> tuple[float, float]: def decode(location: EncodedLocation) -> tuple[float, float]:
"""Decode into a location.""" """Decode into a location."""
#form the distances matrix
greggs = np.array(fetch_data("greggs"))
repeat_rows = np.tile(greggs, (len(greggs), 1, 1))
repeat_cols = np.transpose(repeat_rows, (1, 0, 2))
dist_matrix = spherical_dist(repeat_rows, repeat_cols)
#split the distances matrix into a list of series, which allows us to sort each row
dist_series_list = []
for i in dist_matrix:
dist_series_list.append(pd.Series(i).sort_values().head(len(location[0][1])+1)[1:])
#part 1: find the ID of each gregg's
closest_greggs = []
for i in range(len(location)):
dists = location[i][1]
errors = []
for j in dist_series_list:
errors.append(sum((j-dists)**2))
minerr = min(errors)
if minerr > 1:
print(f"warning: high error value of {minerr}")
closest_greggs = [errors.index(min(errors))]
#part 2: trilaterate
# Stub # Stub
return (0.091659, 52.210796) return (0.091659, 52.210796)
@ -141,7 +171,8 @@ def main():
#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((52.210796, 0.091659)))) outcome = encode((52.210796, 0.091659))
decode(outcome)
if __name__ == "__main__": if __name__ == "__main__":