From c2a11fa34e204e9360ac78e0986d7db2bc053cc6 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 22 Jul 2022 21:41:11 -0700 Subject: [PATCH] Fix footnotes on website --- selfdrive/car/docs.py | 41 +++++++++++-------------------- selfdrive/car/docs_definitions.py | 13 +++++++++- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/selfdrive/car/docs.py b/selfdrive/car/docs.py index 26f8949e8f..46b882ab47 100755 --- a/selfdrive/car/docs.py +++ b/selfdrive/car/docs.py @@ -2,29 +2,24 @@ import argparse import jinja2 import os -from enum import Enum from natsort import natsorted -from typing import Dict, List +from typing import 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 STAR_DESCRIPTIONS, StarColumns, TierColumns, CarInfo, Column, Star, get_all_footnotes 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() -> Dict[Enum, int]: - all_footnotes = [] - for footnotes in get_interface_attr("Footnote", ignore_none=True).values(): - all_footnotes += footnotes - return {fn: idx + 1 for idx, fn in enumerate(all_footnotes)} - - -ALL_FOOTNOTES: Dict[Enum, int] = get_all_footnotes() 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() -> List[CarInfo]: +def get_all_car_info(hide_cols=None) -> List[CarInfo]: + if hide_cols is None: + hide_cols = [] + all_footnotes = get_all_footnotes(hide_cols) + all_car_info: List[CarInfo] = [] for model, car_info in get_interface_attr("CAR_INFO", combine_brands=True).items(): # Hyundai exception: those with radar have openpilot longitudinal @@ -39,28 +34,21 @@ def get_all_car_info() -> List[CarInfo]: car_info = (car_info,) for _car_info in car_info: - all_car_info.append(_car_info.init(CP, ALL_FOOTNOTES)) + all_car_info.append(_car_info.init(CP, hide_cols, all_footnotes)) # Sort cars by make and model + year sorted_cars: List[CarInfo] = natsorted(all_car_info, key=lambda car: car.name.lower()) return sorted_cars -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, hide_cols: bool) -> 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 ALL_FOOTNOTES if fn.value.column in cols] - cars_md: str = template.render(all_car_info=all_car_info, - footnotes=footnotes, Star=Star, Column=cols, star_descriptions=STAR_DESCRIPTIONS) + cols = [c for c in Column if c not in hide_cols] + footnotes = [fn.value.text for fn in get_all_footnotes(hide_cols)] + cars_md: str = template.render(all_car_info=all_car_info, footnotes=footnotes, + Star=Star, Column=cols, star_descriptions=STAR_DESCRIPTIONS) return cars_md @@ -73,6 +61,7 @@ if __name__ == "__main__": parser.add_argument("--out", default=CARS_MD_OUT, help="Override default generated filename") args = parser.parse_args() + hide_cols = set(StarColumns) - set(TierColumns) if args.tier_columns else [] with open(args.out, 'w') as f: - f.write(generate_cars_md(get_all_car_info(), args.template, args.tier_columns)) + f.write(generate_cars_md(get_all_car_info(hide_cols), args.template, hide_cols)) print(f"Generated and written to {args.out}") diff --git a/selfdrive/car/docs_definitions.py b/selfdrive/car/docs_definitions.py index 01473e4cc3..a93de98d9b 100644 --- a/selfdrive/car/docs_definitions.py +++ b/selfdrive/car/docs_definitions.py @@ -5,6 +5,7 @@ from collections import namedtuple from dataclasses import dataclass from enum import Enum from typing import Dict, List, Optional, Tuple, Union, no_type_check +from selfdrive.car.interfaces import get_interface_attr GOOD_TORQUE_THRESHOLD = 1.0 # m/s^2 MODEL_YEARS_RE = r"(?<= )((\d{4}-\d{2})|(\d{4}))(,|$)" @@ -46,6 +47,13 @@ def get_footnote(footnotes: Optional[List[Enum]], column: Column) -> Optional[En return None +def get_all_footnotes(hide_cols) -> Dict[Enum, int]: + all_footnotes = [] + for footnotes in get_interface_attr("Footnote", ignore_none=True).values(): + all_footnotes.extend([fn for fn in footnotes if fn not in hide_cols]) + return {fn: idx + 1 for idx, fn in enumerate(all_footnotes)} + + def split_name(name: str) -> Tuple[str, str, str]: make, model = name.split(" ", 1) years = "" @@ -66,7 +74,7 @@ class CarInfo: min_enable_speed: Optional[float] = None harness: Optional[Enum] = None - def init(self, CP: car.CarParams, all_footnotes: Dict[Enum, int]): + def init(self, CP: car.CarParams, hide_cols, all_footnotes: Dict[Enum, int]): # TODO: set all the min steer speeds in carParams and remove this min_steer_speed = CP.minSteerSpeed if self.min_steer_speed is not None: @@ -110,6 +118,9 @@ class CarInfo: if footnote is not None and footnote.value.star is not None: self.row[column] = footnote.value.star + # Remove hidden columns + self.row = {c: self.row[c] for c in self.row if c not in hide_cols} + # openpilot ACC star doesn't count for tiers full_stars = [s for col, s in self.row.items() if col in TierColumns].count(Star.FULL) if full_stars == len(TierColumns):