diff --git a/src/strava_gear/cli.py b/src/strava_gear/cli.py index 49f22a4..ec2e31f 100644 --- a/src/strava_gear/cli.py +++ b/src/strava_gear/cli.py @@ -4,6 +4,7 @@ import click from .core import apply_rules +from .core import warn_unknown_bikes from .input.activities import read_input_csv from .input.activities import read_strava_offline from .input.rules import read_rules @@ -54,6 +55,7 @@ def main(rules, csv, strava_database, output, report, tablefmt, show_name, show_ rules = read_rules(rules, aliases=aliases) res = apply_rules(rules, activities) reports[report](res, output=output, tablefmt=tablefmt, show_name=show_name, show_first_last=show_first_last) + warn_unknown_bikes(rules, activities) if __name__ == "__main__": diff --git a/src/strava_gear/core.py b/src/strava_gear/core.py index f7e68fe..f8a8e69 100644 --- a/src/strava_gear/core.py +++ b/src/strava_gear/core.py @@ -3,6 +3,7 @@ from typing import Dict from typing import Iterable from typing import List +from warnings import warn from .data import Result from .data import Rule @@ -59,3 +60,12 @@ def merge_asof(activities: Iterable[Dict], rules: Iterable[Rule]): rule_cur, rule_next = rule_next, next(rules, None) yield activity, rule_cur + + +def warn_unknown_bikes(rules: Rules, activities: List[Dict]) -> None: + known_bikes = set(rules.bike_names.keys()) + used_gear = set(activity['gear_id'] for activity in activities if activity['gear_id']) + + unknown_bikes = rules.all_rule_bike_ids() - known_bikes - used_gear + if unknown_bikes: + warn(f"Unknown bikes in rules, possibly a typo: {unknown_bikes}") diff --git a/src/strava_gear/data.py b/src/strava_gear/data.py index a70a0b4..3c0423b 100644 --- a/src/strava_gear/data.py +++ b/src/strava_gear/data.py @@ -157,6 +157,9 @@ class Rules: components: List[Component] rules: List[Rule] + def all_rule_bike_ids(self) -> Set[BikeId]: + return set(b for r in self.rules for b in r.bikes.keys()) + @dataclass class Usage: