Skip to content

feat: add route request generator#4

Open
Sherley-Sonali wants to merge 1 commit into
mainfrom
feat/request-builder
Open

feat: add route request generator#4
Sherley-Sonali wants to merge 1 commit into
mainfrom
feat/request-builder

Conversation

@Sherley-Sonali
Copy link
Copy Markdown
Collaborator

Adds the route request generator - random coordinate pairs within the Switzerland polygon with a single hardcoded auto costing request for now. Costing randomization comes in the next PR once the OpenAPI spec lands.

Switzerland polygon sourced from Natural Earth 110m, vendored as data/switzerland.geojson.

closes #2

AI Usage: Used AI for implementation and test design. All changes were reviewed, tested, and understood.

Copy link
Copy Markdown
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a good start. on the weekend I'll come up with more issues for next week to discuss.

Comment thread data/switzerland.geojson
@@ -0,0 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"featurecla":"Admin-0 country","scalerank":1,"LABELRANK":4,"SOVEREIGNT":"Switzerland","SOV_A3":"CHE","ADM0_DIF":0,"LEVEL":2,"TYPE":"Sovereign country","TLC":"1","ADMIN":"Switzerland","ADM0_A3":"CHE","GEOU_DIF":0,"GEOUNIT":"Switzerland","GU_A3":"CHE","SU_DIF":0,"SUBUNIT":"Switzerland","SU_A3":"CHE","BRK_DIFF":0,"NAME":"Switzerland","NAME_LONG":"Switzerland","BRK_A3":"CHE","BRK_NAME":"Switzerland","BRK_GROUP":null,"ABBREV":"Switz.","POSTAL":"CH","FORMAL_EN":"Swiss Confederation","FORMAL_FR":null,"NAME_CIAWF":"Switzerland","NOTE_ADM0":null,"NOTE_BRK":null,"NAME_SORT":"Switzerland","NAME_ALT":null,"MAPCOLOR7":5,"MAPCOLOR8":2,"MAPCOLOR9":7,"MAPCOLOR13":3,"POP_EST":8574832,"POP_RANK":13,"POP_YEAR":2019,"GDP_MD":703082,"GDP_YEAR":2019,"ECONOMY":"2. Developed region: nonG7","INCOME_GRP":"1. High income: OECD","FIPS_10":"SZ","ISO_A2":"CH","ISO_A2_EH":"CH","ISO_A3":"CHE","ISO_A3_EH":"CHE","ISO_N3":"756","ISO_N3_EH":"756","UN_A3":"756","WB_A2":"CH","WB_A3":"CHE","WOE_ID":23424957,"WOE_ID_EH":23424957,"WOE_NOTE":"Exact WOE match as country","ADM0_ISO":"CHE","ADM0_DIFF":null,"ADM0_TLC":"CHE","ADM0_A3_US":"CHE","ADM0_A3_FR":"CHE","ADM0_A3_RU":"CHE","ADM0_A3_ES":"CHE","ADM0_A3_CN":"CHE","ADM0_A3_TW":"CHE","ADM0_A3_IN":"CHE","ADM0_A3_NP":"CHE","ADM0_A3_PK":"CHE","ADM0_A3_DE":"CHE","ADM0_A3_GB":"CHE","ADM0_A3_BR":"CHE","ADM0_A3_IL":"CHE","ADM0_A3_PS":"CHE","ADM0_A3_SA":"CHE","ADM0_A3_EG":"CHE","ADM0_A3_MA":"CHE","ADM0_A3_PT":"CHE","ADM0_A3_AR":"CHE","ADM0_A3_JP":"CHE","ADM0_A3_KO":"CHE","ADM0_A3_VN":"CHE","ADM0_A3_TR":"CHE","ADM0_A3_ID":"CHE","ADM0_A3_PL":"CHE","ADM0_A3_GR":"CHE","ADM0_A3_IT":"CHE","ADM0_A3_NL":"CHE","ADM0_A3_SE":"CHE","ADM0_A3_BD":"CHE","ADM0_A3_UA":"CHE","ADM0_A3_UN":-99,"ADM0_A3_WB":-99,"CONTINENT":"Europe","REGION_UN":"Europe","SUBREGION":"Western Europe","REGION_WB":"Europe & Central Asia","NAME_LEN":11,"LONG_LEN":11,"ABBREV_LEN":6,"TINY":-99,"HOMEPART":1,"MIN_ZOOM":0,"MIN_LABEL":4,"MAX_LABEL":9,"LABEL_X":7.463965,"LABEL_Y":46.719114,"NE_ID":1159320491,"WIKIDATAID":"Q39","NAME_AR":"\u0633\u0648\u064a\u0633\u0631\u0627","NAME_BN":"\u09b8\u09c1\u0987\u099c\u09be\u09b0\u09b2\u09cd\u09af\u09be\u09a8\u09cd\u09a1","NAME_DE":"Schweiz","NAME_EN":"Switzerland","NAME_ES":"Suiza","NAME_FA":"\u0633\u0648\u0626\u06cc\u0633","NAME_FR":"Suisse","NAME_EL":"\u0395\u03bb\u03b2\u03b5\u03c4\u03af\u03b1","NAME_HE":"\u05e9\u05d5\u05d5\u05d9\u05d9\u05e5","NAME_HI":"\u0938\u094d\u0935\u093f\u091f\u094d\u091c\u093c\u0930\u0932\u0948\u0923\u094d\u0921","NAME_HU":"Sv\u00e1jc","NAME_ID":"Swiss","NAME_IT":"Svizzera","NAME_JA":"\u30b9\u30a4\u30b9","NAME_KO":"\uc2a4\uc704\uc2a4","NAME_NL":"Zwitserland","NAME_PL":"Szwajcaria","NAME_PT":"Su\u00ed\u00e7a","NAME_RU":"\u0428\u0432\u0435\u0439\u0446\u0430\u0440\u0438\u044f","NAME_SV":"Schweiz","NAME_TR":"\u0130svi\u00e7re","NAME_UK":"\u0428\u0432\u0435\u0439\u0446\u0430\u0440\u0456\u044f","NAME_UR":"\u0633\u0648\u06cc\u0679\u0632\u0631\u0644\u06cc\u0646\u0688","NAME_VI":"Th\u1ee5y S\u0129","NAME_ZH":"\u745e\u58eb","NAME_ZHT":"\u745e\u58eb","FCLASS_ISO":"Admin-0 country","TLC_DIFF":null,"FCLASS_TLC":"Admin-0 country","FCLASS_US":null,"FCLASS_FR":null,"FCLASS_RU":null,"FCLASS_ES":null,"FCLASS_CN":null,"FCLASS_TW":null,"FCLASS_IN":null,"FCLASS_NP":null,"FCLASS_PK":null,"FCLASS_DE":null,"FCLASS_GB":null,"FCLASS_BR":null,"FCLASS_IL":null,"FCLASS_PS":null,"FCLASS_SA":null,"FCLASS_EG":null,"FCLASS_MA":null,"FCLASS_PT":null,"FCLASS_AR":null,"FCLASS_JP":null,"FCLASS_KO":null,"FCLASS_VN":null,"FCLASS_TR":null,"FCLASS_ID":null,"FCLASS_PL":null,"FCLASS_GR":null,"FCLASS_IT":null,"FCLASS_NL":null,"FCLASS_SE":null,"FCLASS_BD":null,"FCLASS_UA":null},"bbox":[6.022609,45.776948,10.442701,47.830828],"geometry":{"type":"Polygon","coordinates":[[[9.594226,47.525058],[9.632932,47.347601],[9.47997,47.10281],[9.932448,46.920728],[10.442701,46.893546],[10.363378,46.483571],[9.922837,46.314899],[9.182882,46.440215],[8.966306,46.036932],[8.489952,46.005151],[8.31663,46.163642],[7.755992,45.82449],[7.273851,45.776948],[6.843593,45.991147],[6.5001,46.429673],[6.022609,46.27299],[6.037389,46.725779],[6.768714,47.287708],[6.736571,47.541801],[7.192202,47.449766],[7.466759,47.620582],[8.317301,47.61358],[8.522612,47.830828],[9.594226,47.525058]]]}}]} No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove all the properties (but one, like name_english or so)

Comment on lines +17 to +26
# ---------------------------------------------------------------------------
# Costing bundles
# ---------------------------------------------------------------------------
# Each bundle is one complete set of costing parameters. For each coordinate
# pair we generate, we emit one request per bundle - so total lines in the
# output is n_pairs * len(COSTING_BUNDLES).
#
# These are intentionally minimal and hardcoded for now. Once the Valhalla
# OpenAPI spec lands, we'll replace/extend this with
# spec-driven randomized costing options.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is too much AI slop for comments :D just say: "temp until costing options are randomized". code comments need to be succinct, this takes away way too much attention for no benefit

# ---------------------------------------------------------------------------


def load_switzerland_polygon():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to do mypy-style, but let's keep the minimum of type annotations

Comment on lines +32 to +34
# ---------------------------------------------------------------------------
# Polygon loading
# ---------------------------------------------------------------------------
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, serves no purpose

Comment on lines +50 to +52
# ---------------------------------------------------------------------------
# Coordinate sampling
# ---------------------------------------------------------------------------
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same.. I mean, this is not even somehow serial processing, where sectioning comments would kinda make sense. please be more mindful about your code comment hygiene

Comment thread route_generator/main.py
Comment on lines +34 to +39
parser.add_argument(
"--seed",
type=int,
default=None,
help="Optional random seed for reproducible output",
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for seed, let's randomize it

Comment thread route_generator/main.py
"--count",
type=int,
default=1000,
help="Number of origin/destination coordinate pairs to generate (default: 1000)",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
help="Number of origin/destination coordinate pairs to generate (default: 1000)",
help="Number of route requests to generate (default: 1000)",

Comment thread route_generator/main.py
from route_generator.generator import build_requests, load_switzerland_polygon, write_jsonl


def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't need a function, this can live freely

Comment thread route_generator/main.py
uv run route-generator [--output PATH] [--count N] [--seed INT]
"""

from __future__ import annotations
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this really do? doesn't seem like it's used anywhere but imported everywhere.. some magic happening in the import?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be fair, I never really used anything from __future__

Comment thread pyproject.toml
@@ -7,7 +7,9 @@ license = "MIT"
license-files = ["LICENSE"]

requires-python = ">=3.11"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I didn't catch that before: doesn't matter much really, just curious, why 3.11?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add request builder script

2 participants