Car docs: show more information about cars (#25415)

* back to actual information

* remove some star code

* round speeds

* Try out showing lateral acceleration

* remove that

* Fix speed units

* Add harness and try rounding to nearest half before scapping it

fix

^2

^2

* Add back steering torque star

* Fix static analysis

* auto-generate header

* fix static analysis. set to Harness.none by default

* rm
old-commit-hash: 747bcb013dabdb1f220dc97a37270b42cb4eae03
This commit is contained in:
Shane Smiskol
2022-08-18 15:12:18 -07:00
committed by GitHub
parent b13ebdbffe
commit 2f2016fda6
7 changed files with 270 additions and 353 deletions
+9 -19
View File
@@ -8,16 +8,15 @@ from natsort import natsorted
from typing import Dict, List
from common.basedir import BASEDIR
from selfdrive.car.docs_definitions import STAR_DESCRIPTIONS, StarColumns, TierColumns, CarInfo, Column, Star
from selfdrive.car.docs_definitions import CarInfo, Column
from selfdrive.car.car_helpers import interfaces, get_interface_attr
from selfdrive.car.hyundai.radar_interface import RADAR_START_ADDR as HKG_RADAR_START_ADDR
def get_all_footnotes(only_tier_cols: bool = False) -> Dict[Enum, int]:
def get_all_footnotes() -> Dict[Enum, int]:
all_footnotes = []
hide_cols = set(StarColumns) - set(TierColumns) if only_tier_cols else []
for footnotes in get_interface_attr("Footnote", ignore_none=True).values():
all_footnotes.extend([fn for fn in footnotes if fn.value.column not in hide_cols])
all_footnotes.extend(footnotes)
return {fn: idx + 1 for idx, fn in enumerate(all_footnotes)}
@@ -25,9 +24,9 @@ CARS_MD_OUT = os.path.join(BASEDIR, "docs", "CARS.md")
CARS_MD_TEMPLATE = os.path.join(BASEDIR, "selfdrive", "car", "CARS_template.md")
def get_all_car_info(only_tier_cols: bool = False) -> List[CarInfo]:
def get_all_car_info() -> List[CarInfo]:
all_car_info: List[CarInfo] = []
footnotes = get_all_footnotes(only_tier_cols)
footnotes = get_all_footnotes()
for model, car_info in get_interface_attr("CAR_INFO", combine_brands=True).items():
# Hyundai exception: those with radar have openpilot longitudinal
fingerprint = {0: {}, 1: {HKG_RADAR_START_ADDR: 8}, 2: {}, 3: {}}
@@ -57,21 +56,13 @@ def group_by_make(all_car_info: List[CarInfo]) -> Dict[str, List[CarInfo]]:
return dict(sorted_car_info)
def generate_cars_md(all_car_info: List[CarInfo], template_fn: str, only_tier_cols: bool) -> str:
def generate_cars_md(all_car_info: List[CarInfo], template_fn: str) -> str:
with open(template_fn, "r") as f:
template = jinja2.Template(f.read(), trim_blocks=True, lstrip_blocks=True)
cols = list(Column)
if only_tier_cols:
hide_cols = set(StarColumns) - set(TierColumns)
cols = [c for c in cols if c not in hide_cols]
for car in all_car_info:
for c in hide_cols:
del car.row[c]
footnotes = [fn.value.text for fn in get_all_footnotes(only_tier_cols)]
footnotes = [fn.value.text for fn in get_all_footnotes()]
cars_md: str = template.render(all_car_info=all_car_info, group_by_make=group_by_make,
footnotes=footnotes, Star=Star, Column=cols, STAR_DESCRIPTIONS=STAR_DESCRIPTIONS)
footnotes=footnotes, Column=Column)
return cars_md
@@ -79,11 +70,10 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Auto generates supported cars documentation",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--tier-columns", action="store_true", help="Include only columns that count in the tier")
parser.add_argument("--template", default=CARS_MD_TEMPLATE, help="Override default template filename")
parser.add_argument("--out", default=CARS_MD_OUT, help="Override default generated filename")
args = parser.parse_args()
with open(args.out, 'w') as f:
f.write(generate_cars_md(get_all_car_info(args.tier_columns), args.template, args.tier_columns))
f.write(generate_cars_md(get_all_car_info(), args.template))
print(f"Generated and written to {args.out}")