|
| 1 | +--- |
| 2 | +name: add-component-extractor |
| 3 | +description: Add or modify a rocket component extractor in the serialization pipeline (motor, fins, nose cone, parachute, transition, environment, flight, stored results, etc.). Use when a parameter is missing from parameters.json, when supporting a new OpenRocket feature, or when editing anything under rocketserializer/components/ or ork_extractor.py. |
| 4 | +--- |
| 5 | + |
| 6 | +# Adding a component extractor |
| 7 | + |
| 8 | +The serializer builds `parameters.json` in `ork_extractor.ork_extractor()` by calling one |
| 9 | +`search_*` function per rocket concern from `rocketserializer/components/`. To add or extend |
| 10 | +a component, follow the existing pattern exactly. |
| 11 | + |
| 12 | +## Anatomy of a component module |
| 13 | +Each `components/<thing>.py`: |
| 14 | +- Starts with `import logging` and `logger = logging.getLogger(__name__)`. |
| 15 | +- Exposes `search_<thing>(bs, ...)` returning a **dict or list of dicts** (never prints; |
| 16 | + logs instead). |
| 17 | +- Uses NumPy-style docstrings (Parameters / Returns). |
| 18 | +- Reads scalars from the BeautifulSoup tree `bs`; reads geometry/positions from the |
| 19 | + `elements` map produced by `open_rocket_wrangler.process_elements_position` (which needs |
| 20 | + the Java `ork` document). See `nose_cone.py` and `fins.py` for the `elements` pattern. |
| 21 | + |
| 22 | +## Wiring it into the pipeline |
| 23 | +In `ork_extractor.py`: |
| 24 | +1. Import your function at the top with the other `from .components.<x> import ...` lines. |
| 25 | +2. Call it through the local `_safe_search(func, default_ret, *args)` wrapper so a failure |
| 26 | + logs and returns the default instead of aborting the whole extraction. Choose a sensible |
| 27 | + default (`{}`, `[]`, or a minimal dict) matching the shape callers expect. |
| 28 | +3. Assign the result into `settings["<key>"]`. The top-level keys are a **contract** with |
| 29 | + `nb_builder.py` and the acceptance golden files — don't rename existing keys casually. |
| 30 | + |
| 31 | +Current keys: `id`, `environment`, `rocket`, `nosecones`, `trapezoidal_fins`, |
| 32 | +`elliptical_fins`, `tails`, `parachutes`, `rail_buttons`, `motors`, `flight`, |
| 33 | +`stored_results` (plus `rocket.drag_curve` and `motors.thrust_source` which point to CSVs |
| 34 | +written into the output folder). |
| 35 | + |
| 36 | +## If the notebook must use the new value |
| 37 | +Add/adjust the matching `build_*` method in `nb_builder.NotebookBuilder` so the value flows |
| 38 | +into the generated RocketPy notebook. The builder reads only from `parameters.json`. |
| 39 | + |
| 40 | +## Validate the change |
| 41 | +1. `make format && make lint` |
| 42 | +2. Run the pipeline on an example that exercises the component: |
| 43 | + `ork2json --filepath "examples/EPFL--BellaLui--2020/rocket.ork" --verbose` |
| 44 | + and inspect the resulting `parameters.json`. |
| 45 | +3. `pytest tests/acceptance/test_ork_extractor.py -v`. Acceptance tests compare against |
| 46 | + committed `examples/<name>/parameters.json`. If your change **intentionally** alters |
| 47 | + output, regenerate those golden files and review the diff carefully before committing. |
| 48 | +4. Add unit coverage under `tests/unit/` when practical. |
| 49 | + |
| 50 | +## Remember the input limitations |
| 51 | +The pipeline assumes a single stage, single motor, and single nose cone, and English-only |
| 52 | +`.ork` files with at least one run simulation. Don't silently break these assumptions. |
0 commit comments