Skip to content

Commit

Permalink
add docs string revit class
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed May 8, 2024
1 parent 2b4e1db commit 8417962
Showing 1 changed file with 116 additions and 3 deletions.
119 changes: 116 additions & 3 deletions APSToolkitPython/src/aps_toolkit/ProDbReaderRevit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
from typing import List
import re
import pandas as pd
import json
import requests
from .PropReader import PropReader
from .ManifestItem import ManifestItem


class PropDbReaderRevit(PropReader):
"""
Class PropDbReaderRevit to read properties from Revit model
"""

def __int__(self, urn, token, region="US", manifest_item: [ManifestItem] = None):
super().__init__(urn, token, region, manifest_item)

Expand All @@ -39,6 +42,11 @@ def _get_recursive_child(self, output, id, name):
output[child] = property[0].strip()

def get_external_id(self, id) -> str:
"""
Get unique id of element in model from database id
:param id: The database id of element in model
:return: :class:`str` : Unique id of element in model
"""
return self.ids[id]

def get_document_info(self) -> pd.Series:
Expand Down Expand Up @@ -66,43 +74,78 @@ def _get_aec_model_data(self):
return json_response

def get_phases(self) -> List[str]:
"""
Get all phases in model
:return: :class:`list` : List contains all phases
"""
phases = []
json_response = self._get_aec_model_data()
for phase in json_response["phases"]:
phases.append(phase["name"])
return phases

def get_document_id(self) -> str:
"""
Get unique id of document in model
:return: :class:`str` : Document id
"""
json_response = self._get_aec_model_data()
return json_response["documentId"]

def get_levels(self) -> pd.DataFrame:
"""
Get levels in model
:return: :class:`pandas.DataFrame` : Dataframe contains levels
"""
json_response = self._get_aec_model_data()
levels = json_response["levels"]
df = pd.DataFrame(levels)
return df

def get_grids(self) -> pd.DataFrame:
"""
Get grids in model
:return: :class:`pandas.DataFrame` : Dataframe contains grids
"""
json_response = self._get_aec_model_data()
grids = json_response["grids"]
df = pd.DataFrame(grids)
return df

def get_linked_documents(self) -> list:
"""
Get linked documents in model
:return: :class:`list` : List contains linked documents
"""
json_response = self._get_aec_model_data()
linked_documents = json_response["linkedDocuments"]
return linked_documents

def get_ref_point_transformation(self) -> list:
"""
Get ref point transformation in model
:return: :class:`list` : List contains ref point transformation
"""
json_response = self._get_aec_model_data()
return json_response["refPointTransformation"]

def get_all_categories(self) -> dict:
"""
Get all categories in model
e.g: {1: "Walls", 2: "Doors", 3: "Windows", 4: "Furniture", 5: "Plumbing Fixtures", 6: "Electrical Fixtures"}
:return: :class:`dict` : Dictionary contains all categories, key is dbId, value is category name
"""
categories = {}
self._get_recursive_child(categories, 1, "_RC")
return categories

def get_all_data(self, is_get_sub_family=False, display_unit=False) -> pd.DataFrame:
"""
Get all data from model, include all categories
:param is_get_sub_family: the flag to get sub family or not, default is False
:param display_unit: the flag to display unit or not in value, default is False
:return: :class:`pandas.DataFrame` : Dataframe contains all data
"""
categories_dict = self.get_all_categories()
dbids = list(categories_dict.keys())
dataframe = pd.DataFrame()
Expand All @@ -112,16 +155,31 @@ def get_all_data(self, is_get_sub_family=False, display_unit=False) -> pd.DataFr
return dataframe

def get_all_families(self) -> dict:
"""
Get all families in model
:return: :class:`dict` : Dictionary contains all families, key is dbId, value is family name
"""
families = {}
self._get_recursive_child(families, 1, "_RFN")
return families

def get_all_families_types(self) -> dict:
"""
Get all families types in model
:return: :class:`dict` : Dictionary contains all families types, key is dbId, value is family type name
"""
families_types = {}
self._get_recursive_child(families_types, 1, "_RFT")
return families_types

def get_data_by_category(self, category, is_get_sub_family=False, display_unit=False) -> pd.DataFrame:
"""
Get data by category in model
:param category: the category name need get data, e.g: Walls, Doors, Windows, etc
:param is_get_sub_family: the flag to get sub family or not, default is False
:param display_unit: the flag to display unit or not in value, default is False
:return: :class:`pandas.DataFrame` : Dataframe contains data by category
"""
categories = self.get_all_categories()
# if category starts with Revit, remove it
if category.startswith("Revit"):
Expand All @@ -130,15 +188,31 @@ def get_data_by_category(self, category, is_get_sub_family=False, display_unit=F
dataframe = self._get_recursive_ids(category_id, is_get_sub_family, display_unit)
return dataframe

def get_data_by_categories(self, categories: List[str], is_get_sub_family=False) -> pd.DataFrame:
def get_data_by_categories(self, categories: List[str], is_get_sub_family=False,
display_unit=False) -> pd.DataFrame:
"""
Get data by list of categories in model
:param categories: the list of categories need get data, e.g: ["Walls", "Doors", "Windows"]
:param is_get_sub_family: the flag to get sub family or not, default is False
:param display_unit: the flag to display unit or not in value, default is False
:return: :class:`pandas.DataFrame` : Dataframe contains data by categories
"""
dataframe = pd.DataFrame()
for category in categories:
dataframe = pd.concat([dataframe, self.get_data_by_category(category, is_get_sub_family)],
dataframe = pd.concat([dataframe, self.get_data_by_category(category, is_get_sub_family, display_unit)],
ignore_index=True)
return dataframe

def get_data_by_categories_and_params(self, categories: List[str], params: List[str],
is_get_sub_family=False, display_unit=False) -> pd.DataFrame:
"""
Get data by list of categories and list of parameters in model
:param categories: the list of categories need get data, e.g: ["Walls", "Doors", "Windows"]
:param params: the list of parameters need get data, e.g: ["Name", "Area", "Volume", "Height"]
:param is_get_sub_family: the flag to get sub family or not, default is False
:param display_unit: the flag to display unit or not in value, default is False
:return: :class:`pandas.DataFrame` : Dataframe contains data by categories and parameters
"""
dataframe = pd.DataFrame()
all_categories = self.get_all_categories()
category_ids = [key for key, value in all_categories.items() if value in categories]
Expand All @@ -152,12 +226,26 @@ def get_data_by_categories_and_params(self, categories: List[str], params: List[
return dataframe

def get_data_by_family(self, family_name, is_get_sub_family=False, display_unit=False) -> pd.DataFrame:
"""
Get data by family name in model
:param family_name: the family name need get data, e.g: "Seating-LAMMHULTS-PENNE-Chair"
:param is_get_sub_family: the flag to get sub family or not, default is False
:param display_unit: the flag to display unit or not in value, default is False
:return: :class:`pandas.DataFrame` : Dataframe contains data by family name
"""
families = self.get_all_families()
category_id = [key for key, value in families.items() if value == family_name]
dataframe = self._get_recursive_ids(category_id, is_get_sub_family, display_unit)
return dataframe

def get_data_by_family_type(self, family_type, is_get_sub_family=False, display_unit=False) -> pd.DataFrame:
"""
Get data by family type in model
:param family_type: the family type name need get data, e.g: "Plastic-Seat"
:param is_get_sub_family: the flag to get sub family or not, default is False
:param display_unit: the flag to display unit or not in value, default is False
:return: :class:`pandas.DataFrame` : Dataframe contains data by family type
"""
family_types = self.get_all_families_types()
type_id = [key for key, value in family_types.items() if value == family_type]
dataframe = self._get_recursive_ids(type_id, is_get_sub_family, display_unit)
Expand Down Expand Up @@ -222,6 +310,14 @@ def _get_recursive_ids(self, db_ids: List[int], get_sub_family, display_unit=Fal

def _get_recursive_ids_prams(self, childs: List[int], params: List[str], get_sub_family,
display_unit=False) -> pd.DataFrame:
"""
Get recursive ids by list of parameters
:param childs: List of child ids, ids is database id
:param params: List of parameters need get data
:param get_sub_family: the flag to get sub family or not
:param display_unit: the flag to display unit or not in value
:return:
"""
dataframe = pd.DataFrame()
props_ignore = ['parent', 'instanceof_objid', 'child', "viewable_in"]
if len(childs) == 0:
Expand Down Expand Up @@ -292,6 +388,13 @@ def _get_recursive_ids_prams(self, childs: List[int], params: List[str], get_sub
return dataframe

def get_data_by_external_id(self, external_id, is_get_sub_family=False, display_unit=False) -> pd.DataFrame:
"""
Get data by external id(UniqueId Element) in model
:param external_id: The unique id of element in model
:param is_get_sub_family: the flag to get sub family or not, default is False
:param display_unit: the flag to display unit or not in value, default is False
:return: :class:`pandas.DataFrame` : Dataframe contains data by external id
"""
db_id = None
for idx in range(0, len(self.ids)):
if self.ids[idx] == external_id:
Expand All @@ -303,6 +406,11 @@ def get_data_by_external_id(self, external_id, is_get_sub_family=False, display_
return dataframe

def get_data_by_element_id(self, element_id) -> dict:
"""
Get data by element id in model
:param element_id: the element id of element in model. e.g: 9895625
:return: :class:`dict` : Dictionary contains data by element id
"""
rg = re.compile(r'^__\w+__$')
properties = {}
for i in range(0, len(self.ids)):
Expand All @@ -322,6 +430,11 @@ def get_data_by_element_id(self, element_id) -> dict:
return properties

def get_all_parameters(self) -> List:
"""
Get all parameters in model.
e.g: ["Area", "Volume", "Height", "Width", "Name", "Category", "ElementId", "IfcGUID"]
:return: :class:`list` : List contains all parameters.
"""
parameters = []
for id in range(0, len(self.ids)):
props_dict = self.get_properties(id)
Expand Down

0 comments on commit 8417962

Please sign in to comment.