diff --git a/APSToolkitPython/src/aps_toolkit/ProDbReaderRevit.py b/APSToolkitPython/src/aps_toolkit/ProDbReaderRevit.py index f02daaa..4bf7b2e 100644 --- a/APSToolkitPython/src/aps_toolkit/ProDbReaderRevit.py +++ b/APSToolkitPython/src/aps_toolkit/ProDbReaderRevit.py @@ -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) @@ -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: @@ -66,6 +74,10 @@ 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"]: @@ -73,36 +85,67 @@ def get_phases(self) -> List[str]: 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() @@ -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"): @@ -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] @@ -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) @@ -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: @@ -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: @@ -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)): @@ -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)