Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/chuongmep/aps-toolkit into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Mar 3, 2024
2 parents 4c71f43 + 7896865 commit 27d8b82
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 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="0.1.2",
version="0.1.3",
author="chuong mep",
author_email="[email protected]",
description="A Toolkit Autodesk Platform Services for Python",
Expand Down
8 changes: 8 additions & 0 deletions APSToolkitPython/src/aps_toolkit/ProDbReaderRevit.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def _get_recursive_child(self, output, id, name):
def get_external_id(self, id) -> str:
return self.ids[id]

def get_document_info(self) -> pd.Series:
properties = self.get_properties(1)
instances = self.get_instance(1)
for instance in instances:
types = self.get_properties(instance)
properties = {**properties, **types}
return pd.Series(properties)

def get_all_categories(self) -> dict:
categories = {}
self._get_recursive_child(categories, 1, "_RC")
Expand Down
26 changes: 19 additions & 7 deletions APSToolkitPython/src/aps_toolkit/PropReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, urn, token):
self.attrs = json.loads(codecs.decode(gzip.decompress(downloaded_files["objects_attrs.json.gz"]), 'utf-8'))
self.vals = json.loads(codecs.decode(gzip.decompress(downloaded_files["objects_vals.json.gz"]), 'utf-8'))

def enumerate_properties(self, id) ->list:
def enumerate_properties(self, id) -> list:
properties = []
if 0 < id < len(self.offsets):
av_start = 2 * self.offsets[id]
Expand Down Expand Up @@ -99,15 +99,27 @@ def enumerate_properties(self, id) ->list:
display_precision, forge_parameter_id, value))
return properties

def get_properties(self, id) ->dict:
"""
Get all properties exclude internal properties
"""
def get_properties(self, id) -> dict:
props = {}
rg = re.compile(r'^__\w+__$')
for prop in self.enumerate_properties(id):
if prop.category and not rg.match(prop.category):
props[prop.name] = prop.value
return props

def get_properties_group_by_category(self, id) ->dict:
"""
Get all properties include internal properties
"""
def get_all_properties(self, id) -> dict:
props = {}
for prop in self.enumerate_properties(id):
props[prop.name] = prop.value
return props

def get_properties_group_by_category(self, id) -> dict:
properties = {}
rg = re.compile(r'^__\w+__$')
categories = []
Expand All @@ -129,21 +141,21 @@ def get_properties_group_by_category(self, id) ->dict:

return properties

def get_children(self, id) ->list:
def get_children(self, id) -> list:
children = []
for prop in self.enumerate_properties(id):
if prop.category == "__child__":
children.append(int(prop.value))
return children

def get_parent(self, id) ->list:
def get_parent(self, id) -> list:
parent = []
for prop in self.enumerate_properties(id):
if prop.category == "__parent__":
parent.append(int(prop.value))
return parent

def get_instance(self, id) ->list:
def get_instance(self, id) -> list:
instance_of = []
for prop in self.enumerate_properties(id):
if prop.category == "__instanceof__":
Expand All @@ -152,7 +164,7 @@ def get_instance(self, id) ->list:


class Property():
def __init__(self, id =None, name =None, category=None, data_type=None, data_type_context=None, description=None,
def __init__(self, id=None, name=None, category=None, data_type=None, data_type_context=None, description=None,
display_name=None, flags=None,
display_precision=None, forge_parameter_id=None, value=None):
self.id = id,
Expand Down
30 changes: 26 additions & 4 deletions APSToolkitPython/src/test/test_prop_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,31 @@


class TestPropDbReader(TestCase):
def setUp(self):
self.urn = "dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLk9kOHR4RGJLU1NlbFRvVmcxb2MxVkE_dmVyc2lvbj0yNA"
self.token = Auth().auth2leg()
self.prop_reader = PropReader(self.urn, self.token)

def test_enumerate_properties(self):
token = Auth().auth2leg()
urn = "dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLjAtYnBtcEpXUWJTRUVNdUFac1VETWc_dmVyc2lvbj0yNQ"
prop_reader = PropReader(urn, token)
properties = prop_reader.enumerate_properties(1)
properties = self.prop_reader.enumerate_properties(1)
self.assertNotEquals(properties, 0)

def test_get_properties(self):
properties = self.prop_reader.get_properties(1)
self.assertNotEquals(properties, 0)

def test_get_all_properties(self):
properties = self.prop_reader.get_all_properties(1)
self.assertNotEquals(properties, 0)

def test_get_instance(self):
instance = self.prop_reader.get_instance(1)
self.assertEquals(len(instance), 0)

def test_get_children(self):
children = self.prop_reader.get_children(1)
self.assertNotEquals(len(children), 0)

def test_get_parent(self):
parent = self.prop_reader.get_parent(1)
self.assertEquals(len(parent), 0)
5 changes: 4 additions & 1 deletion APSToolkitPython/src/test/test_prop_reader_revit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def setUp(self):
self.urn = "dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLk9kOHR4RGJLU1NlbFRvVmcxb2MxVkE_dmVyc2lvbj0yNA"
self.prop_reader = PropDbReaderRevit(self.urn, self.token)

def test_get_document_info(self):
document_info = self.prop_reader.get_document_info()
self.assertNotEquals(document_info, 0)
def test_get_all_categories(self):
categories = self.prop_reader.get_all_categories()
print(categories)
Expand Down Expand Up @@ -50,4 +53,4 @@ def test_get_data_by_categories_and_params(self):
def test_get_data_by_external_id(self):
external_id = "31261f36-7edb-41d9-95bc-f8df75aec4c4-00005a5b"
df = self.prop_reader.get_data_by_external_id(external_id)
self.assertNotEquals(df.empty, True)
self.assertNotEquals(df.empty, True)

0 comments on commit 27d8b82

Please sign in to comment.