From b6ed5651ad7dd7b442ad2ea929d07c9cd8735c2c Mon Sep 17 00:00:00 2001 From: Matthew Boyd Date: Tue, 10 May 2022 23:04:42 -0700 Subject: [PATCH] [#35] Formatting, clean up lcss representation --- mappymatch/maps/nx/nx_map.py | 16 +++++++++------- mappymatch/matchers/lcss/lcss.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/mappymatch/maps/nx/nx_map.py b/mappymatch/maps/nx/nx_map.py index 7556372..62353e1 100644 --- a/mappymatch/maps/nx/nx_map.py +++ b/mappymatch/maps/nx/nx_map.py @@ -54,18 +54,20 @@ def __init__(self, graph: nx.MultiDiGraph): self._roads = self._build_rtree() def _strip_verbose_data(self): - too_verbose = ('_nodes', '_roads') - base_dict = {k: v for k, v in self.__dict__.items() if not k in too_verbose} + too_verbose = ("_nodes", "_roads") + base_dict = { + k: v for k, v in self.__dict__.items() if not k in too_verbose + } for label in too_verbose: - member_len = len(eval(f'self.{label}')) - base_dict[label] = f'list of {member_len} elements' - return ', '.join(f'{k}: {v}' for k, v in base_dict.items()) + member_len = len(eval(f"self.{label}")) + base_dict[label] = f"list of {member_len} elements" + return ", ".join(f"{k}: {v}" for k, v in base_dict.items()) def __str__(self): - return 'NXMap(' + self._strip_verbose_data() + ')' + return "NXMap(" + self._strip_verbose_data() + ")" def __repr__(self): - return 'NXMap(' + self._strip_verbose_data() + ')' + return "NXMap(" + self._strip_verbose_data() + ")" def _build_rtree(self) -> List[Road]: road_lookup = [] diff --git a/mappymatch/matchers/lcss/lcss.py b/mappymatch/matchers/lcss/lcss.py index a1a3dfe..a9a2496 100644 --- a/mappymatch/matchers/lcss/lcss.py +++ b/mappymatch/matchers/lcss/lcss.py @@ -54,11 +54,18 @@ def __init__( self.random_cuts = random_cuts self.distance_threshold = distance_threshold + def _string_rep(self): + return ( + "LCSSMatcher(" + + ", ".join(f"{k}: {v}" for k, v in self.__dict__.items()) + + ")" + ) + def __repr__(self): - return(repr(self.__dict__)) + return self._string_rep() def __str__(self): - return(str(self.__dict__)) + return self._string_rep() def match_trace(self, trace: Trace) -> MatchResult: def _join_segment(a: TrajectorySegment, b: TrajectorySegment):