From 89fab9037b8a3214f89f26caa7b4a86dec12cc94 Mon Sep 17 00:00:00 2001 From: Zachary Tatlock Date: Tue, 2 Apr 2024 20:47:57 -0700 Subject: [PATCH] more route-db invariant checks, more routes --- _data/gpx/gas-works-locks-salmon-bay.gpx | 539 +++++++++++++++++++++++ _data/gpx/mb-lwb-cc.gpx | 249 +++++++++++ _data/gpx/northgate-carkeek-ob.gpx | 455 +++++++++++++++++++ _data/gpx/roosevelt-greenlake-loop.gpx | 306 +++++++++++++ _data/route-db-invariants.py | 81 +++- _data/route-db.csv | 16 +- 6 files changed, 1628 insertions(+), 18 deletions(-) create mode 100644 _data/gpx/gas-works-locks-salmon-bay.gpx create mode 100644 _data/gpx/mb-lwb-cc.gpx create mode 100644 _data/gpx/northgate-carkeek-ob.gpx create mode 100644 _data/gpx/roosevelt-greenlake-loop.gpx diff --git a/_data/gpx/gas-works-locks-salmon-bay.gpx b/_data/gpx/gas-works-locks-salmon-bay.gpx new file mode 100644 index 0000000..5c9ff8d --- /dev/null +++ b/_data/gpx/gas-works-locks-salmon-bay.gpx @@ -0,0 +1,539 @@ + + + + gas-works-locks-salmon-bay + Gas Works, Locks, Salmon Bay Loop + 8 + 250 + Gas Works + Gas Works + Loop + https://onthegomap.com/s/4fpqkgfr + Race Condition Running + + Race Condition Running + + + + 7.94 mi route + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/_data/gpx/mb-lwb-cc.gpx b/_data/gpx/mb-lwb-cc.gpx new file mode 100644 index 0000000..2f97940 --- /dev/null +++ b/_data/gpx/mb-lwb-cc.gpx @@ -0,0 +1,249 @@ + + + + mb-lwb-cc + Mount Bake, LWB, Columbia City + 3.3 + 261 + Mount Baker Station + Columbia City Station + P2P + https://onthegomap.com/s/3i1cco56 + Race Condition Running + + Race Condition Running + + + + 3.32 mi route + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/_data/gpx/northgate-carkeek-ob.gpx b/_data/gpx/northgate-carkeek-ob.gpx new file mode 100644 index 0000000..b509c66 --- /dev/null +++ b/_data/gpx/northgate-carkeek-ob.gpx @@ -0,0 +1,455 @@ + + + + northgate-carkeek-ob + OB: Northgate, Carkeek + 6.4 + 720 + Northgate Station + Northgate Station + OB + https://onthegomap.com/s/k15n5ruq + Race Condition Running + + Race Condition Running + + + + 6.4 mi route + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/_data/gpx/roosevelt-greenlake-loop.gpx b/_data/gpx/roosevelt-greenlake-loop.gpx new file mode 100644 index 0000000..97d73d1 --- /dev/null +++ b/_data/gpx/roosevelt-greenlake-loop.gpx @@ -0,0 +1,306 @@ + + + + roosevelt-greenlake-loop + Roosevelt, Green Lake Loop + 4.3 + 152 + Roosevelt Station + Roosevelt Station + Loop + https://onthegomap.com/s/dl3ne2h5 + Race Condition Running + + Race Condition Running + + + + 4.32 mi route + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/_data/route-db-invariants.py b/_data/route-db-invariants.py index 1f1a034..fa0950f 100644 --- a/_data/route-db-invariants.py +++ b/_data/route-db-invariants.py @@ -3,33 +3,90 @@ FIELDS = ['id', 'name', 'dist', 'elev', 'start', 'end', 'type', 'map'] TYPES = ['Loop', 'P2P', 'OB'] +LOCS = [ + 'Beacon', + 'CapHill', + 'ColCity', + 'CSE', + 'GasWorks', + 'JaysCafe', + 'Locks', + 'MtBaker', + 'Northgate', + 'Roosevelt', + 'SODO', + 'Westlake' +] # route-db.csv lives in the same directory as this script data_dir = os.path.dirname(os.path.realpath(__file__)) csv_path = os.path.join(data_dir, 'route-db.csv') gpx_dir = os.path.join(data_dir, 'gpx') +warnings = False +def warn(msg): + global warnings + warnings = True + print(f"WARNING! {msg}") + +def warn_rc(route, msg): + warn(f"route {route['id']}: {msg}") + +def check_route(route): + # all fields are set + for field in FIELDS: + if field not in route: # TODO need to see if blank! + warn_rc(route, f"no field {field}") + + # type is valid + if route['type'] not in TYPES: + warn_rc(route, f"invalid type {route['type']}") + + # start and end locations are valid + if route['start'] not in LOCS: + warn_rc(route, f"invalid start {route['start']}") + if route['end'] not in LOCS: + warn_rc(route, f"invalid end {route['end']}") + + # dist and elev are numbers + try: + float(route['dist']) + except ValueError: + warn_rc(route, f"invalid dist {route['dist']}") + try: + float(route['elev']) + except ValueError: + warn_rc(route, f"invalid elev {route['elev']}") + + # every route has a gpx + gpx_path = os.path.join(gpx_dir, route['id']) + '.gpx' + if not os.path.isfile(gpx_path): + warn_rc(route, f"no GPX file at {gpx_path}") + +# MAIN + # read routes with open(csv_path, 'r') as f: reader = csv.DictReader(f) routes = list(reader) -# ensure all fields set for all routes +# ensure all route ids unique +ids = set() for route in routes: - for field in FIELDS: - if field not in route: - print(f"WARNING: route {route['id']} has no field {field}") - if route['type'] not in TYPES: - print(f"WARNING: route {route['id']} has invalid type {route['type']}") + if route['id'] in ids: + warn(f"route {route['id']} is not unique") + ids.add(route['id']) -# ensure every route has a gpx +# check every route for route in routes: - gpx_path = os.path.join(gpx_dir, route['id']) + '.gpx' - if not os.path.isfile(gpx_path): - print(f"WARNING: route {route['id']} has no GPX file at {gpx_path}") + check_route(route) + +# bail if any warnings +if warnings: + exit(1) -# sort routes -routes.sort(key=lambda x: (x['start'], x['dist'], x['end'], x['type'], x['id'])) +# sort routes by start and increasing distance +routes.sort(key=lambda x: (x['start'], float(x['dist']), x['end'], x['type'], x['id'])) # write sorted routes back with open(csv_path, 'w') as f: diff --git a/_data/route-db.csv b/_data/route-db.csv index 3c974dd..dc88472 100644 --- a/_data/route-db.csv +++ b/_data/route-db.csv @@ -1,19 +1,23 @@ id,name,start,dist,elev,end,type,map beacon-i90-luther-burbank-ob,"OB: Beacon, I90, Luther Burbank",Beacon,13.1,1470,Beacon,OB,https://onthegomap.com/s/4kn8h5of -cse-jays-cafe,CSE to Jay's Cafe,CSE,11.2,410,JaysCafe,P2P,https://onthegomap.com/s/9au7h17i cse-lwb-cc,"CSE, LWB, Columbia City",CSE,8.8,650,ColCity,P2P,https://onthegomap.com/s/k3pikua1 cse-520-wetherill-ob,"OB: CSE, 520, Wetherill Preserve",CSE,9.8,710,CSE,OB,https://onthegomap.com/s/jssjhikb -cap-hill-i90-ob,"OB: Cap Hill, I90 Bridge",CapHill,10.7,1220,CapHill,OB,https://onthegomap.com/s/6qcstgh2 +cse-jays-cafe,CSE to Jay's Cafe,CSE,11.2,410,JaysCafe,P2P,https://onthegomap.com/s/9au7h17i cap-hill-volunteer-park-westlake,"Cap Hill, Volunteer Park, Westlake",CapHill,4.0,279,Westlake,P2P,https://onthegomap.com/s/b9i31iru -gas-works-kotkins-pier-salmon-bay,"Gas Works, Kotkins Pier, Salmon Bay Loop",GasWorks,10.2,320,GasWorks,Loop,https://onthegomap.com/s/oufhpc2l +cap-hill-i90-ob,"OB: Cap Hill, I90 Bridge",CapHill,10.7,1220,CapHill,OB,https://onthegomap.com/s/6qcstgh2 gas-works-lake-union-loop,"Gas Works, Lake Union Loop",GasWorks,6.3,303,GasWorks,Loop,https://onthegomap.com/s/oepno6ud +gas-works-locks-salmon-bay,"Gas Works, Locks, Salmon Bay Loop",GasWorks,8.0,250,GasWorks,Loop,https://onthegomap.com/s/4fpqkgfr +gas-works-kotkins-pier-salmon-bay,"Gas Works, Kotkins Pier, Salmon Bay Loop",GasWorks,10.2,320,GasWorks,Loop,https://onthegomap.com/s/oufhpc2l locks-discovery-salmon-bay-loop,"Locks, Discovery Park, Salmon Bay Loop",Locks,8.1,890,Locks,Loop,https://onthegomap.com/s/uop4tt1d -northgate-echo-lake-ob,"OB: Northgate, Interurban Trail, Echo Lake",Northgate,12.4,580,Northgate,OB,https://onthegomap.com/s/mqvelf8h +mb-lwb-cc,"Mount Bake, LWB, Columbia City",MtBaker,3.3,261,ColCity,P2P,https://onthegomap.com/s/3i1cco56 northgate-resevoirs-roosevelt,"Northgate, Resevoirs, Green Lake",Northgate,4.1,600,Roosevelt,P2P,https://onthegomap.com/s/2tmbpess +northgate-carkeek-ob,"OB: Northgate, Carkeek",Northgate,6.4,720,Northgate,OB,https://onthegomap.com/s/k15n5ruq northgate-carkeek-roosevelt,"Northgate, Carkeek, Roosevelt",Northgate,8.2,750,Roosevelt,P2P,https://onthegomap.com/s/i52u05p8 +northgate-echo-lake-ob,"OB: Northgate, Interurban Trail, Echo Lake",Northgate,12.4,580,Northgate,OB,https://onthegomap.com/s/mqvelf8h +roosevelt-greenlake-loop,"Roosevelt, Green Lake Loop",Roosevelt,4.3,152,Roosevelt,Loop,https://onthegomap.com/s/dl3ne2h5 roosevelt-green-lake-rose-gardens,"Roosevelt, Green Lake, Rose Gardens",Roosevelt,6.4,400,Roosevelt,Loop,https://onthegomap.com/s/4oft807m -sodo-alki-beach-ob,"OB: SODO, Alki Beach",SODO,12.0,370,SODO,OB,https://onthegomap.com/s/8seoc603 sodo-luna-pier-ob,"OB: SODO, Luna Pier",SODO,9.2,320,SODO,OB,https://onthegomap.com/s/cm9vrvku -westlake-sculpture-interbay-queen-anne,"Westlake, Sculpture Park, Interbay, Queen Anne Loop",Westlake,10.2,840,Westlake,Loop,https://onthegomap.com/s/pmmqj3t5 +sodo-alki-beach-ob,"OB: SODO, Alki Beach",SODO,12.0,370,SODO,OB,https://onthegomap.com/s/8seoc603 westlake-sculpture-park-ob,"OB: Westlake, Sculpture Park",Westlake,5.1,253,Westlake,OB,https://onthegomap.com/s/nfe3jmv0 westlake-sculpture-smith-cove-ob,"OB: Westlake, Sculpture Park, Smith Cove",Westlake,9.3,410,Westlake,OB,https://onthegomap.com/s/rm6intki +westlake-sculpture-interbay-queen-anne,"Westlake, Sculpture Park, Interbay, Queen Anne Loop",Westlake,10.2,840,Westlake,Loop,https://onthegomap.com/s/pmmqj3t5