Skip to content

Commit

Permalink
[#35] Add str and repr functions to Trace and NXMap
Browse files Browse the repository at this point in the history
  • Loading branch information
machallboyd committed Jun 23, 2022
1 parent 4229bd2 commit 68eb738
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mappymatch/constructs/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ def __add__(self, other: Trace) -> Trace:
def __len__(self):
return len(self._frame)

def __str__(self):
output_lines = [
"Mappymatch Trace object",
f'coords_list: {self.coords_list if hasattr(self, "coords_list") else None}',
f'frame: {self._frame if hasattr(self, "_frame") else None}',
]
return "\n".join(output_lines)

def __repr__(self):
return self.__str__()

@property
def index(self) -> pd.Index:
return self._frame.index
Expand Down
11 changes: 11 additions & 0 deletions mappymatch/maps/nx/nx_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ def _build_rtree(self) -> List[Road]:
self.rtree = idx
return road_lookup

def __str__(self):
output_lines = [
"Mappymatch NxMap object",
f"roads: {len(self._roads)} Road objects",
f"graph: {self.g}",
]
return "\n".join(output_lines)

def __repr__(self):
return self.__str__()

@property
def roads(self) -> List[Road]:
return self._roads
Expand Down

0 comments on commit 68eb738

Please sign in to comment.