Skip to content

Commit

Permalink
Added project ID parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ppizarror committed Jan 21, 2024
1 parent 7ee5a25 commit 4c20ee5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion MLStructFP/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
__description__ = 'Machine learning structural floor plan dataset'
__keywords__ = ['ml', 'ai', 'dataset', 'calc', 'matrix analysis', 'cnn', 'structural analysis', 'structural design']
__email__ = '[email protected]'
__version__ = '0.4.0'
__version__ = '0.4.1'

# URL
__url__ = 'https://github.com/MLSTRUCT/MLSTRUCT-FP'
Expand Down
26 changes: 19 additions & 7 deletions MLStructFP/db/_db_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ def __init__(self, db: str) -> None:

# Assemble objects
for f_id in data['floor']:
f_data = data['floor'][f_id]
f_data: dict = data['floor'][f_id]
self.floor[int(f_id)] = Floor(
floor_id=int(f_id),
image_path=os.path.join(self._path, f_data['image']),
image_scale=f_data['scale']
image_scale=f_data['scale'],
project_id=f_data['project'] if 'project' in f_data else -1
)
for rect_id in data['rect']:
rect_data = data['rect'][rect_id]
rect_data: dict = data['rect'][rect_id]
rect_a = rect_data['angle']
Rect(
rect_id=int(rect_id),
Expand All @@ -65,7 +66,7 @@ def __init__(self, db: str) -> None:
line_theta=rect_data['line'][2] # Theta
)
for slab_id in data['slab']:
slab_data = data['slab'][slab_id]
slab_data: dict = data['slab'][slab_id]
Slab(
slab_id=int(slab_id),
floor=self.floor[slab_data['floorID']],
Expand All @@ -78,17 +79,28 @@ def floors(self) -> Tuple['Floor', ...]:
# noinspection PyTypeChecker
return tuple(self.floor.values())

def tabulate(self, limit: int = 0) -> None:
def tabulate(self, limit: int = 0, show_project_id: bool = False) -> None:
"""
Tabulates each floor, with their file and number of rects.
:param limit: Limit the number of items
:param show_project_id: Show project ID (if exists)
"""
assert isinstance(limit, int) and limit >= 0, 'Limit must be an integer greater or equal than zero'
table = [['#', 'Floor ID', 'No. rects', 'No. slabs', 'Floor image path']]
theads = ['#']
if show_project_id:
theads.append('Project ID')
for t in ('Floor ID', 'No. rects', 'No. slabs', 'Floor image path'):
theads.append(t)
table = [theads]
for j in range(len(self.floors)):
f: 'Floor' = self.floors[j]
table.append([j, f.id, len(f.rect), len(f.slab), f.image_path])
table_data = [j]
if show_project_id:
table_data.append(f.project_id)
for i in (f.id, len(f.rect), len(f.slab), f.image_path):
table_data.append(i)
table.append(table_data)
if 0 < limit - 1 <= j:
break
display(HTML(tabulate.tabulate(
Expand Down
5 changes: 4 additions & 1 deletion MLStructFP/db/_floor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,24 @@ class Floor(object):
id: int
image_path: str
image_scale: float
project_id: int

def __init__(self, floor_id: int, image_path: str, image_scale: NumberType) -> None:
def __init__(self, floor_id: int, image_path: str, image_scale: NumberType, project_id: int = -1) -> None:
"""
Constructor.
:param floor_id: Floor ID
:param image_path: Image path
:param image_scale: Image scale (px to units)
:param project_id: Project ID (default: -1)
"""
assert isinstance(floor_id, int) and floor_id > 0
assert os.path.isfile(image_path), f'Image file {image_path} does not exist'
assert isinstance(image_scale, NumberInstance) and image_scale > 0
self.id = floor_id
self.image_path = image_path
self.image_scale = float(image_scale)
self.project_id = project_id
self._bb = None
self._last_mutation = None
self._rect = {}
Expand Down

0 comments on commit 4c20ee5

Please sign in to comment.