Car docs diff: fix new platform detection (#25252)

* Fix new platform detection

* add some helpful comments and clean up

* slightly better
old-commit-hash: 3117c069d8
taco
Shane Smiskol 3 years ago committed by GitHub
parent d9f897ce31
commit 178d7fca52
  1. 16
      selfdrive/debug/print_docs_diff.py

@ -20,17 +20,18 @@ def load_base_car_info(path):
def match_cars(base_cars, new_cars): def match_cars(base_cars, new_cars):
"""Matches CarInfo by name similarity and finds additions and removals"""
changes = [] changes = []
additions = [] additions = []
for new in new_cars: for new in new_cars:
closest_match = difflib.get_close_matches(new.name, [b.name for b in base_cars], cutoff=0.)[0] # Addition if no close matches or close match already used
# Change if close match and not already used
if closest_match not in [c[1].name for c in changes]: matches = difflib.get_close_matches(new.name, [b.name for b in base_cars], cutoff=0.)
changes.append((new, next(car for car in base_cars if car.name == closest_match))) if not len(matches) or matches[0] in [c[1].name for c in changes]:
else:
additions.append(new) additions.append(new)
else:
changes.append((new, next(car for car in base_cars if car.name == matches[0])))
# Removal if base car not in changes
removals = [b for b in base_cars if b.name not in [c[1].name for c in changes]] removals = [b for b in base_cars if b.name not in [c[1].name for c in changes]]
return changes, additions, removals return changes, additions, removals
@ -62,6 +63,9 @@ def print_car_info_diff(path):
for car in get_all_car_info(): for car in get_all_car_info():
new_car_info[car.car_fingerprint].append(car) new_car_info[car.car_fingerprint].append(car)
# Add new platforms to base cars so we can detect additions and removals in one pass
base_car_info.update({car: [] for car in new_car_info if car not in base_car_info})
changes = defaultdict(list) changes = defaultdict(list)
for base_car_model, base_cars in base_car_info.items(): for base_car_model, base_cars in base_car_info.items():
# Match car info changes, and get additions and removals # Match car info changes, and get additions and removals

Loading…
Cancel
Save