Skip to content

Commit

Permalink
add unit mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Oct 15, 2024
1 parent 11bc516 commit 9c4f560
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion APSToolkitPython/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name="aps-toolkit",
version="1.0.8",
version="1.0.9",
author="chuong mep",
author_email="[email protected]",
description="A Toolkit Autodesk Platform Services for Python",
Expand Down
41 changes: 41 additions & 0 deletions APSToolkitPython/src/aps_toolkit/ProDbReaderRevit.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,44 @@ def get_all_parameters(self) -> List:
parameters = list(set(parameters))
parameters.sort()
return parameters

def get_units_mapping(self) -> pd.DataFrame:
"""
Get all units mapping in model
Return a dataframe contains all units mapping include name, category, data_type, data_type_context, description, display_name, flags, display_precision, forge_parameter, symbol_unit, data_type_string
:return: :class:`pandas.DataFrame` : Dataframe contains all units
"""
df = pd.DataFrame(columns=["name", "category", "data_type","data_type_context","description","display_name","flags","display_precision","forge_parameter"])
# get from atts
for i in range(1,len(self.attrs)):
name = self.attrs[i][0]
category = self.attrs[i][1]
data_type = self.attrs[i][2]
data_type_context = self.attrs[i][3]
description = self.attrs[i][4]
display_name = self.attrs[i][5]
flags = self.attrs[i][6]
display_precision = self.attrs[i][7]
forge_parameter = self.attrs[i][8]
new_row = {"name": name, "category": category, "data_type": data_type, "data_type_context": data_type_context,
"description": description, "display_name": display_name, "flags": flags, "display_precision": display_precision,
"forge_parameter": forge_parameter}
df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True)
# insert column symbol_unit = self.units.parse_symbol(<value from data_type_context>)
df["symbol_unit"] = df["data_type_context"].apply(lambda x: self.units.parse_symbol(x))
# enum map : https://stackoverflow.com/questions/76973784/how-to-get-string-type-of-data-type-from-autodesk-platform-services
enum_mapping = {
0: "Unknown",
1: "Boolean",
2: "Integer",
3: "Double",
10: "Blob",
11: "DbKey",
20: "String",
21: "LocalizableString",
22: "DateTime",
23: "GeoLocation",
24: "Position"
}
df["data_type_string"] = df["data_type"].map(enum_mapping)
return df
9 changes: 7 additions & 2 deletions APSToolkitPython/src/aps_toolkit/units/DisplayUnits.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@ def _read_units_local(self):
print(f"Error decoding JSON file: {e}")

def parse_symbol(self, type_id: str):
type_id = type_id.split("-")[0]
return self.units.get(type_id, "")
if type_id is None:
return ""
if "-" in type_id:
type_id = type_id.split("-")[0]
return self.units.get(type_id, "")
else:
return ""
6 changes: 5 additions & 1 deletion APSToolkitPython/src/test/test_prop_reader_revit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class TestPropDbReaderRevit(TestCase):
def setUp(self):
self.token = Auth().auth2leg()
self.urn = "dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLkotQ2laSHpGVEd5LUEwLVJmaEVVTVE_dmVyc2lvbj04"
self.urn = "dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLk9kOHR4RGJLU1NlbFRvVmcxb2MxVkE_dmVyc2lvbj0zMg"
self.prop_reader = PropDbReaderRevit(self.urn, self.token)
# pass

Expand Down Expand Up @@ -121,3 +121,7 @@ def test_get_data_by_element_id(self):
def test_get_all_parametes(self):
parameters = self.prop_reader.get_all_parameters()
self.assertNotEquals(parameters, 0)

def test_get_units_mapping(self):
units = self.prop_reader.get_units_mapping()
self.assertNotEquals(units, 0)

0 comments on commit 9c4f560

Please sign in to comment.