diff --git a/APSToolkitPython/requirements.txt b/APSToolkitPython/requirements.txt index a94cf69..65a42be 100644 --- a/APSToolkitPython/requirements.txt +++ b/APSToolkitPython/requirements.txt @@ -1,2 +1,2 @@ requests -pandas \ No newline at end of file +pandas diff --git a/APSToolkitPython/setup.py b/APSToolkitPython/setup.py index 351d16f..7262965 100644 --- a/APSToolkitPython/setup.py +++ b/APSToolkitPython/setup.py @@ -6,7 +6,7 @@ setuptools.setup( name="aps-toolkit", - version="0.8.8", + version="0.8.9", author="chuong mep", author_email="chuongpqvn@gmail.com", description="A Toolkit Autodesk Platform Services for Python", diff --git a/APSToolkitPython/src/aps_toolkit/ProDbReaderRevit.py b/APSToolkitPython/src/aps_toolkit/ProDbReaderRevit.py index 78eaa4a..aa81a22 100644 --- a/APSToolkitPython/src/aps_toolkit/ProDbReaderRevit.py +++ b/APSToolkitPython/src/aps_toolkit/ProDbReaderRevit.py @@ -213,12 +213,13 @@ def _get_recursive_child_types(self, data_frame, id, name): data_frame.loc[len(data_frame)] = new_row def get_data_by_category(self, category: str, is_get_sub_family: bool = False, - display_unit: bool = False) -> pd.DataFrame: + display_unit: bool = False, is_add_family_name: bool = 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 + :param is_add_family_name: the flag to add family name or not, default is False :return: :class:`pandas.DataFrame` : Dataframe contains data by category """ categories = self.get_all_categories() @@ -227,10 +228,16 @@ def get_data_by_category(self, category: str, is_get_sub_family: bool = False, category = category[5:].strip() category_id = [key for key, value in categories.items() if value == category] dataframe = self._get_recursive_ids(category_id, is_get_sub_family, display_unit) + if dataframe.empty: + return dataframe + if (is_add_family_name): + # get name from family and get name by regex e.g "Seating-LAMMHULTS-PENNE-Chair [12143232]" -> + # "Seating-LAMMHULTS-PENNE-Chair" + dataframe["Family Name"] = dataframe["Name"].str.extract(r'(.*)\s\[') return dataframe def get_data_by_categories(self, categories: List[str], is_get_sub_family: bool = False, - display_unit: bool = False) -> pd.DataFrame: + display_unit: bool = False, is_add_family_name: bool = 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"] @@ -240,8 +247,9 @@ def get_data_by_categories(self, categories: List[str], is_get_sub_family: bool """ dataframe = pd.DataFrame() for category in categories: - dataframe = pd.concat([dataframe, self.get_data_by_category(category, is_get_sub_family, display_unit)], - ignore_index=True) + dataframe = pd.concat( + [dataframe, self.get_data_by_category(category, is_get_sub_family, display_unit, is_add_family_name)], + ignore_index=True) return dataframe def get_data_by_categories_and_params(self, categories: List[str], params: List[str], @@ -254,6 +262,9 @@ def get_data_by_categories_and_params(self, categories: List[str], params: List[ :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 """ + is_have_name = params in ["Name"] + if not is_have_name: + params.append("Name") dataframe = pd.DataFrame() all_categories = self.get_all_categories() category_ids = [key for key, value in all_categories.items() if value in categories] @@ -261,6 +272,12 @@ def get_data_by_categories_and_params(self, categories: List[str], params: List[ dataframe = pd.concat( [dataframe, self._get_recursive_ids_prams([category_id], params, is_get_sub_family, display_unit)], ignore_index=True) + if dataframe.empty: + return dataframe + if "Family Name" in params: + dataframe["Family Name"] = dataframe["Name"].str.extract(r'(.*)\s\[') + if not is_have_name: + dataframe = dataframe.drop(columns=["Name"]) # remove all row have all values is null, ignore dbId and external_id columns dataframe = dataframe.dropna(how='all', subset=[col for col in dataframe.columns if col not in ['dbId', 'external_id']]) @@ -293,6 +310,10 @@ def get_data_by_families(self, family_names: str, is_get_sub_family: bool = Fals families = self.get_all_families() cate_ids = [key for key, value in families.items() if value in family_names] dataframe = self._get_recursive_ids(cate_ids, is_get_sub_family, display_unit) + # add family name to dataframe + if dataframe.empty: + return dataframe + dataframe["Family Name"] = dataframe["Name"].str.extract(r'(.*)\s\[') return dataframe def get_data_by_family_type(self, family_type: str, is_get_sub_family: bool = False, @@ -308,6 +329,10 @@ def get_data_by_family_type(self, family_type: str, is_get_sub_family: bool = Fa 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) + # add family name to dataframe + if dataframe.empty: + return dataframe + dataframe["Family Name"] = dataframe["Name"].str.extract(r'(.*)\s\[') return dataframe def get_data_by_family_types(self, type_names: str, is_get_sub_family: bool = False, @@ -322,6 +347,10 @@ def get_data_by_family_types(self, type_names: str, is_get_sub_family: bool = Fa types = self.get_all_families_types() type_ids = [key for key, value in types.items() if value in type_names] dataframe = self._get_recursive_ids(type_ids, is_get_sub_family, display_unit) + # add family name to dataframe + if dataframe.empty: + return dataframe + dataframe["Family Name"] = dataframe["Name"].str.extract(r'(.*)\s\[') return dataframe def _get_recursive_ids(self, db_ids: List[int], get_sub_family: bool, display_unit: bool = False) -> pd.DataFrame: diff --git a/APSToolkitPython/src/test/test_prop_reader_revit.py b/APSToolkitPython/src/test/test_prop_reader_revit.py index 260ac8b..c44a161 100644 --- a/APSToolkitPython/src/test/test_prop_reader_revit.py +++ b/APSToolkitPython/src/test/test_prop_reader_revit.py @@ -7,7 +7,7 @@ class TestPropDbReaderRevit(TestCase): def setUp(self): self.token = Auth().auth2leg() - self.urn = "dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLnhXMnZPTVJzUTR1bXdmREd1UF9TSGc_dmVyc2lvbj0x" + self.urn = "dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLk9kOHR4RGJLU1NlbFRvVmcxb2MxVkE_dmVyc2lvbj0zMA" self.prop_reader = PropDbReaderRevit(self.urn, self.token) def test_get_document_info(self): @@ -52,13 +52,13 @@ def test_get_all_data(self): self.assertIsNotNone(data) def test_get_data_by_category(self): - df = self.prop_reader.get_data_by_category("Furniture", True, True) + df = self.prop_reader.get_data_by_category("Furniture", True, True, True) # check if dataframe have rows = 1 df_rows = df.shape[0] self.assertNotEquals(df_rows, 0) def test_get_data_by_categories(self): - df = self.prop_reader.get_data_by_categories(["Doors", "Windows"]) + df = self.prop_reader.get_data_by_categories(["Doors", "Windows"], is_add_family_name=True) self.assertNotEquals(df.empty, True) # noinspection PyInterpreter @@ -84,8 +84,8 @@ def test_get_data_by_family_types(self): def test_get_data_by_categories_and_params(self): df = self.prop_reader.get_data_by_categories_and_params(["Doors", "Windows"], - ["name", "Category", "ElementId", "Width", "Height", - "IfcGUID"], True, display_unit=True) + ["Name", "Category", "ElementId", "Width", "Height", + "IfcGUID","Family Name"], True, display_unit=True) self.assertNotEquals(df.empty, True) def test_get_data_by_external_id(self):