engine_test: create testing script
This commit is contained in:
parent
2e83c934e9
commit
cc02dd122b
2 changed files with 43 additions and 0 deletions
42
engine_test.py
Executable file
42
engine_test.py
Executable file
|
|
@ -0,0 +1,42 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from engine import encode, decode, format_location, parse_location, spherical_dist, fetch_data
|
||||||
|
from tqdm import tqdm
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
DIST_THRESH = 0.1
|
||||||
|
|
||||||
|
|
||||||
|
def gen_locations() -> list[tuple[float, float]]:
|
||||||
|
"""Generate a list of locations for testing."""
|
||||||
|
# return [(52.210796, 0.091659)]
|
||||||
|
return fetch_data("tesco")
|
||||||
|
|
||||||
|
|
||||||
|
def test_encode_decode():
|
||||||
|
locations = gen_locations()
|
||||||
|
passed = 0
|
||||||
|
fails = 0
|
||||||
|
dists = []
|
||||||
|
|
||||||
|
try:
|
||||||
|
for loc in tqdm(locations):
|
||||||
|
encoded = format_location(encode(loc))
|
||||||
|
decoded = decode(parse_location(encoded))
|
||||||
|
dist = spherical_dist(np.array(loc), np.array(decoded))
|
||||||
|
dists.append(dist)
|
||||||
|
|
||||||
|
if dist > DIST_THRESH:
|
||||||
|
tqdm.write(f"FAIL:\n\tloc: {loc}\n\tdecoded: {decoded}\n\tdist: {dist}")
|
||||||
|
fails += 1
|
||||||
|
else:
|
||||||
|
passed += 1
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("KeyboardInterrupt - halting...")
|
||||||
|
|
||||||
|
avg_dist = sum(dists) / len(dists)
|
||||||
|
print(f"\nDONE. Passed: {passed}. Failed: {fails}. Average error: {avg_dist:.3f}m")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_encode_decode()
|
||||||
|
|
@ -3,3 +3,4 @@ django
|
||||||
numpy
|
numpy
|
||||||
pandas
|
pandas
|
||||||
scipy
|
scipy
|
||||||
|
tqdm
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue