Skip to content

Commit

Permalink
add aec model
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Sep 10, 2024
1 parent caeda6c commit 01d94bb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 62 deletions.
112 changes: 56 additions & 56 deletions APSToolkitPython/src/aps_toolkit/AECDataModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,62 +200,62 @@ def get_element_by_category(self, elementGroupId: str, category: str) -> pd.Data
data_df = pd.concat([data_df, single_df], axis=0)
return data_df

def get_element_projects_by_parameters(self, projectId: str, parameters: list[str]) -> pd.DataFrame:
parameters_str = '","'.join(parameters)
query = f"""
query GetElementsInProject($projectId: ID!, $propertyFilter: String!) {{
elementsByProject(projectId: $projectId, filter: {{query: $propertyFilter}}) {{
pagination {{
cursor
}}
results {{
id
name
properties(
includeReferencesProperties: "Type"
filter: {{names: ["{parameters_str}"]}} # Dynamically insert parameters here
) {{
results {{
name
value
displayValue
definition {{
units {{
name
}}
}}
}}
}}
}}
}}
}}
"""

data = {
"query": query,
"variables": {
"projectId": projectId,
"propertyFilter": "'property.name.Element Context'==Instance"
}
}

# Execute the query
result = self.execute_query_variables(data['query'], data['variables'])

# Normalize the data into a pandas DataFrame
elements = result['data']['elementsByProject']['results']
df = pd.json_normalize(elements)

data_df = pd.DataFrame()
for i, row in df.iterrows():
props_dict = {}
single_df = pd.json_normalize(row['properties.results'])
for i in range(len(single_df)):
props_dict[single_df['name'][i]] = single_df['value'][i]
single_df = pd.DataFrame(props_dict, index=[0], dtype="object")
data_df = pd.concat([data_df, single_df], axis=0)

return data_df
# def get_element_projects_by_parameters(self, projectId: str, parameters: list[str]) -> pd.DataFrame:
# parameters_str = '","'.join(parameters)
# query = f"""
# query GetElementsInProject($projectId: ID!, $propertyFilter: String!) {{
# elementsByProject(projectId: $projectId, filter: {{query: $propertyFilter}}) {{
# pagination {{
# cursor
# }}
# results {{
# id
# name
# properties(
# includeReferencesProperties: "Type"
# filter: {{names: ["{parameters_str}"]}} # Dynamically insert parameters here
# ) {{
# results {{
# name
# value
# displayValue
# definition {{
# units {{
# name
# }}
# }}
# }}
# }}
# }}
# }}
# }}
# """
#
# data = {
# "query": query,
# "variables": {
# "projectId": projectId,
# "propertyFilter": "'property.name.Element Context'==Instance"
# }
# }
#
# # Execute the query
# result = self.execute_query_variables(data['query'], data['variables'])
#
# # Normalize the data into a pandas DataFrame
# elements = result['data']['elementsByProject']['results']
# df = pd.json_normalize(elements)
#
# data_df = pd.DataFrame()
# for i, row in df.iterrows():
# props_dict = {}
# single_df = pd.json_normalize(row['properties.results'])
# for i in range(len(single_df)):
# props_dict[single_df['name'][i]] = single_df['value'][i]
# single_df = pd.DataFrame(props_dict, index=[0], dtype="object")
# data_df = pd.concat([data_df, single_df], axis=0)
#
# return data_df

def get_elements_by_projects(self, projectId: str, cursor: str = None, is_recursive: bool = False) -> pd.DataFrame:
# Define the GraphQL query with the cursor as a dynamic variable
Expand Down
12 changes: 6 additions & 6 deletions APSToolkitPython/src/test/test_aec_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def test_get_element_by_category(self):
result = self.aec_data_model.get_element_by_category(self.group_id, "Doors")
self.assertIsNotNone(result)

def test_get_element_projects_by_parameters(self):
result = self.aec_data_model.get_element_projects_by_parameters(self.project_id,
["Name", "Revit Element ID", "Category",
"Width", "Height", "Element Context",
"Family Name", "Type Name", "Comments"])
self.assertIsNotNone(result)
# def test_get_element_projects_by_parameters(self):
# result = self.aec_data_model.get_element_projects_by_parameters(self.project_id,
# ["Name", "Revit Element ID", "Category",
# "Width", "Height", "Element Context",
# "Family Name", "Type Name", "Comments"])
# self.assertIsNotNone(result)

def test_get_elements_by_projects(self):
cursor = "YWRjdXJzfjB-NTB-NTA"
Expand Down

0 comments on commit 01d94bb

Please sign in to comment.