diff --git a/docs/vehicles.vue b/docs/vehicles.vue deleted file mode 100644 index 6658bbb65d..0000000000 --- a/docs/vehicles.vue +++ /dev/null @@ -1,1926 +0,0 @@ - - - - \ No newline at end of file diff --git a/scripts/count_cars.py b/scripts/count_cars.py index 3fdbe93860..b6b40a7f91 100755 --- a/scripts/count_cars.py +++ b/scripts/count_cars.py @@ -2,12 +2,12 @@ from collections import Counter from pprint import pprint -from selfdrive.car.docs import get_tier_car_rows +from selfdrive.car.docs import get_tier_car_info if __name__ == "__main__": - tiers = list(get_tier_car_rows()) + tiers = get_tier_car_info() cars = [car for tier_cars in tiers for car in tier_cars[1]] - make_count = Counter(l[0] for l in cars) + make_count = Counter(l.make for l in cars) print("\n", "*" * 20, len(cars), "total", "*" * 20, "\n") pprint(make_count) diff --git a/selfdrive/car/docs.py b/selfdrive/car/docs.py index 96a0fdc05e..8077bfb13b 100755 --- a/selfdrive/car/docs.py +++ b/selfdrive/car/docs.py @@ -3,16 +3,16 @@ import argparse import jinja2 import os from enum import Enum -from typing import Dict, Iterator, List, Tuple +from typing import Dict, List, Tuple from common.basedir import BASEDIR -from selfdrive.car.docs_definitions import Column, CarInfo, Star, Tier +from selfdrive.car.docs_definitions import CarInfo, Column, Star, Tier 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 from selfdrive.car.tests.routes import non_tested_cars -def get_all_footnotes(): +def get_all_footnotes() -> Dict[Enum, int]: all_footnotes = [] for _, footnotes in get_interface_attr("Footnote").items(): if footnotes is not None: @@ -25,7 +25,7 @@ CARS_MD_OUT = os.path.join(BASEDIR, "docs", "CARS.md") CARS_MD_TEMPLATE = os.path.join(BASEDIR, "selfdrive", "car", "CARS_template.md") -def get_tier_car_info() -> List[Tuple[Tier, List[CarInfo]]]: # TODO: update typing for all this +def get_tier_car_info() -> List[Tuple[Tier, List[CarInfo]]]: tier_car_info: Dict[Tier, list] = {tier: [] for tier in Tier} for models in get_interface_attr("CAR_INFO").values(): @@ -47,8 +47,8 @@ def get_tier_car_info() -> List[Tuple[Tier, List[CarInfo]]]: # TODO: update typ # Return tier enum and car rows for each tier tiers = [] - for tier, car_rows in tier_car_info.items(): - tiers.append((tier, sorted(car_rows, key=lambda x: x.make + x.model))) + for tier, cars in tier_car_info.items(): + tiers.append((tier, sorted(cars, key=lambda x: x.make + x.model))) return tiers @@ -57,7 +57,7 @@ def generate_cars_md(tier_car_info: List[Tuple[Tier, List[CarInfo]]], template_f template = jinja2.Template(f.read(), trim_blocks=True, lstrip_blocks=True) footnotes = [fn.value.text for fn in ALL_FOOTNOTES] - return template.render(tiers=tier_car_info, Star=Star, Column=Column, footnotes=footnotes) + return template.render(tiers=tier_car_info, footnotes=footnotes, Star=Star, Column=Column) if __name__ == "__main__": diff --git a/selfdrive/car/docs_definitions.py b/selfdrive/car/docs_definitions.py index 4952523721..e2cbdab832 100644 --- a/selfdrive/car/docs_definitions.py +++ b/selfdrive/car/docs_definitions.py @@ -1,7 +1,45 @@ +from cereal import car from collections import namedtuple from dataclasses import dataclass from enum import Enum -from typing import List, Optional +from typing import Dict, List, Optional, Union +import typing + + +class Tier(Enum): + GOLD = "The best openpilot experience. Great highway driving and beyond." + SILVER = "A solid highway driving experience, but is limited by stock longitudinal. May be upgraded in the future." + BRONZE = "A good highway experience, but may have limited performance in traffic and on sharp turns." + + +class Column(Enum): + MAKE = "Make" + MODEL = "Model" + PACKAGE = "Supported Package" + LONGITUDINAL = "openpilot ACC" + FSR_LONGITUDINAL = "Stop and Go" + FSR_STEERING = "Steer to 0" + STEERING_TORQUE = "Steering Torque" + MAINTAINED = "Actively Maintained" + + +class Star(Enum): + FULL = "full" + HALF = "half" + EMPTY = "empty" + + +StarColumns = list(Column)[3:] +CarFootnote = namedtuple("CarFootnote", ["text", "column", "star"], defaults=[None]) + + +def get_footnote(footnotes: Optional[List[Enum]], column: Column) -> Optional[Enum]: + # Returns applicable footnote given current column + if footnotes is not None: + for fn in footnotes: + if fn.value.column == column: + return fn + return None @dataclass @@ -14,7 +52,7 @@ class CarInfo: min_enable_speed: Optional[float] = None good_torque: bool = False - def init(self, CP, non_tested_cars, all_footnotes): + def init(self, CP: car.CarParams, non_tested_cars: List[str], 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: @@ -50,9 +88,10 @@ class CarInfo: self.tier = {5: Tier.GOLD, 4: Tier.SILVER}.get(list(self.row.values()).count(Star.FULL), Tier.BRONZE) - def get_column(self, column, star_icon, footnote_tag): - item = self.row[column] - if column in StarColumns: + @typing.no_type_check + def get_column(self, column: Column, star_icon: str, footnote_tag: str) -> str: + item: Union[str, Star] = self.row[column] + if item in StarColumns: item = star_icon.format(item.value) footnote = get_footnote(self.footnotes, column) @@ -60,39 +99,3 @@ class CarInfo: item += footnote_tag.format(self.all_footnotes[footnote]) return item - - -class Tier(Enum): - GOLD = "The best openpilot experience. Great highway driving and beyond." - SILVER = "A solid highway driving experience, but is limited by stock longitudinal. May be upgraded in the future." - BRONZE = "A good highway experience, but may have limited performance in traffic and on sharp turns." - - -class Column(Enum): - MAKE = "Make" - MODEL = "Model" - PACKAGE = "Supported Package" - LONGITUDINAL = "openpilot ACC" - FSR_LONGITUDINAL = "Stop and Go" - FSR_STEERING = "Steer to 0" - STEERING_TORQUE = "Steering Torque" - MAINTAINED = "Actively Maintained" - - -class Star(Enum): - FULL = "full" - HALF = "half" - EMPTY = "empty" - - -StarColumns = list(Column)[3:] -CarFootnote = namedtuple("CarFootnote", ["text", "column", "star"], defaults=[None]) - - -def get_footnote(footnotes: Optional[List[Enum]], column: Column) -> Optional[Enum]: - # Returns applicable footnote given current column - if footnotes is not None: - for fn in footnotes: - if fn.value.column == column: - return fn - return None diff --git a/selfdrive/car/tests/test_docs.py b/selfdrive/car/tests/test_docs.py index 33ca9a192e..05c65fa3d8 100755 --- a/selfdrive/car/tests/test_docs.py +++ b/selfdrive/car/tests/test_docs.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 import unittest -from selfdrive.car.docs import CARS_MD_OUT, CARS_MD_TEMPLATE, generate_cars_md, get_tier_car_rows +from selfdrive.car.docs import CARS_MD_OUT, CARS_MD_TEMPLATE, generate_cars_md, get_tier_car_info class TestCarDocs(unittest.TestCase): def test_car_docs(self): - generated_cars_md = generate_cars_md(get_tier_car_rows(), CARS_MD_TEMPLATE) + generated_cars_md = generate_cars_md(get_tier_car_info(), CARS_MD_TEMPLATE) with open(CARS_MD_OUT, "r") as f: current_cars_md = f.read()