Skip to content

Commit aafa1b9

Browse files
c-melluehMoult
andauthored
bSDD Add new class properties and relations API Endpoints (#7502)
* black . * add typing * move function * add get_class_relations * add test for class relation --------- Co-authored-by: Dion Moult <dionmoult@gmail.com>
1 parent f89cf88 commit aafa1b9

2 files changed

Lines changed: 138 additions & 0 deletions

File tree

src/bsdd/bsdd.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,78 @@ class ClassPropertyContractV1(TypedDict):
184184
qudtCodes: NotRequired[list[str]]
185185

186186

187+
class ClassRelationItemContractV1(TypedDict):
188+
relationType: str
189+
classUri: str
190+
className: NotRequired[str]
191+
fraction: NotRequired[float]
192+
dictionaryUri: NotRequired[str]
193+
194+
195+
class ClassRelationsContractV1(TypedDict):
196+
totalCount: NotRequired[int]
197+
offset: NotRequired[int]
198+
count: NotRequired[int]
199+
classUri: NotRequired[str]
200+
areReversedRelations: NotRequired[bool]
201+
classRelations: NotRequired[list[ClassRelationItemContractV1]]
202+
203+
204+
class ClassPropertiesContractV1(TypedDict):
205+
classUri: NotRequired[str]
206+
totalCount: NotRequired[int]
207+
offset: NotRequired[int]
208+
count: NotRequired[int]
209+
classProperties: list[ClassPropertyContractV1]
210+
211+
212+
class ClassPropertyItemContractV1(TypedDict):
213+
name: str
214+
propertySet: str
215+
uri: str
216+
description: NotRequired[str]
217+
definition: NotRequired[str]
218+
dataType: NotRequired[str]
219+
dimension: NotRequired[str]
220+
dimensionLength: NotRequired[int]
221+
dimensionMass: NotRequired[int]
222+
dimensionTime: NotRequired[int]
223+
dimensionElectricCurrent: NotRequired[int]
224+
dimensionThermodynamicTemperature: NotRequired[int]
225+
dimensionAmountOfSubstance: NotRequired[int]
226+
dimensionLuminousIntensity: NotRequired[int]
227+
dynamicParameterPropertyCodes: NotRequired[list[str]]
228+
example: NotRequired[str]
229+
isDynamic: NotRequired[bool]
230+
isRequired: NotRequired[bool]
231+
isWritable: NotRequired[bool]
232+
maxExclusive: NotRequired[float]
233+
maxInclusive: NotRequired[float]
234+
minExclusive: NotRequired[float]
235+
minInclusive: NotRequired[float]
236+
pattern: NotRequired[str]
237+
physicalQuantity: NotRequired[str]
238+
allowedValues: NotRequired[list[ClassPropertyValueItemContractV1]]
239+
predefinedValue: NotRequired[str]
240+
propertyCode: NotRequired[str]
241+
propertyDictionaryName: NotRequired[str]
242+
propertyDictionaryUri: NotRequired[str]
243+
propertyUri: NotRequired[str]
244+
propertyStatus: NotRequired[str]
245+
propertyValueKind: NotRequired[str]
246+
symbol: NotRequired[str]
247+
units: NotRequired[list[str]]
248+
qudtCodes: NotRequired[list[str]]
249+
250+
251+
class ClassPropertyValueItemContractV1(TypedDict):
252+
uri: NotRequired[str]
253+
code: NotRequired[str]
254+
value: str
255+
description: NotRequired[str]
256+
sortNumber: NotRequired[int]
257+
258+
187259
class PropertyContractV5(TypedDict):
188260
dictionaryUri: NotRequired[str]
189261
activationDateUtc: str
@@ -710,6 +782,56 @@ def get_class(
710782
params = {k: v for k, v in params.items() if v is not None}
711783
return self.get(endpoint, params)
712784

785+
def get_class_relations(
786+
self,
787+
class_uri: str,
788+
get_reverse_relations: bool = False,
789+
search_text: str = "",
790+
offset: int = 0,
791+
limit: int = 1000,
792+
language_code: str = "",
793+
version=1,
794+
) -> ClassRelationsContractV1:
795+
"""
796+
Get class relations or reverse relations (paginated)
797+
"""
798+
endpoint = f"Class/Relations/v{version}"
799+
params = {
800+
"ClassUri": class_uri,
801+
"GetReverseRelations": get_reverse_relations,
802+
"SearchText": search_text,
803+
"Offset": offset,
804+
"Limit": limit,
805+
"languageCode": language_code,
806+
}
807+
return self.get(endpoint, params)
808+
809+
def get_class_properties(
810+
self,
811+
class_uri: str,
812+
property_set: str = "",
813+
property_code: str = "",
814+
search_text: str = "",
815+
offset: int = 0,
816+
limit: int = 1000,
817+
language_code: str = "",
818+
version=1,
819+
) -> ClassPropertiesContractV1:
820+
"""
821+
Get class properties (paginated)
822+
"""
823+
endpoint = f"Class/Properties/v{version}"
824+
params = {
825+
"ClassUri": class_uri,
826+
"PropertySet": property_set,
827+
"PropertyCode": property_code,
828+
"SearchText": search_text,
829+
"Offset": offset,
830+
"Limit": limit,
831+
"languageCode": language_code,
832+
}
833+
return self.get(endpoint, params)
834+
713835
def get_property(self, uri, language_code="", version: int = 5) -> PropertyContractV5:
714836
"""
715837
Get Property details.

src/bsdd/tests/test_bsdd.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ def test_get_class():
3737
]
3838

3939

40+
def test_get_class_relations():
41+
uri_light_fixture = next(l for l in get_ifc_classes()["classes"] if "IfcLightFixture" == l["code"])["uri"]
42+
ifc4x3_light_fixture_relations = client.get_class_properties(uri_light_fixture, True)
43+
assert "Electrical unit for light-line system" and "Tubelight system" in [
44+
r["className"] for r in ifc4x3_light_fixture_relations["classRelations"]
45+
]
46+
47+
48+
def test_get_class_properties():
49+
uri_light_fixture = next(l for l in get_ifc_classes()["classes"] if "IfcLightFixture" == l["code"])["uri"]
50+
ifc4x3_light_fixture_properties = client.get_class_properties(uri_light_fixture)
51+
assert "Maintenance Factor" and "Light Fixture Mounting Type" in [
52+
l["name"] for l in ifc4x3_light_fixture_properties["classProperties"]
53+
]
54+
55+
4056
def test_search_class():
4157
ss_heat_pump_sys = client.search_class("Ss_60_40_36", [nbs_uri])
4258
li = [l + "source heat pump systems" for l in ["Air ", "Ground ", "Water "]]

0 commit comments

Comments
 (0)