Skip to content

Commit

Permalink
[#35] Clean up NXMap string functions
Browse files Browse the repository at this point in the history
  • Loading branch information
machallboyd committed May 11, 2022
1 parent ef21784 commit 734ed13
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mappymatch/maps/nx/nx_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ def __init__(self, graph: nx.MultiDiGraph):
self._nodes = [nid for nid in self.g.nodes()]
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}
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())

def __str__(self):
return 'NXMap(' + self._strip_verbose_data() + ')'

def __repr__(self):
return 'NXMap(' + self._strip_verbose_data() + ')'

def _build_rtree(self) -> List[Road]:
road_lookup = []

Expand Down

0 comments on commit 734ed13

Please sign in to comment.