pyrulefilter 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,94 @@
1
+ from pyrulefilter.schemas import Rule, RuleSet
2
+ from pyrulefilter.enums import FilterCategoriesEnum, OperatorsEnum, RuleSetType
3
+ from pyrulefilter.operators import MAP_OPERATORS
4
+ import typing as ty
5
+ import logging
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+ __all__ = [
10
+ "Rule",
11
+ "RuleSet",
12
+ "RuleSetType",
13
+ "FilterCategoriesEnum",
14
+ "OperatorsEnum",
15
+ ]
16
+
17
+ def get_param_value(
18
+ property_data: dict, param: str, pass_if_not_exist: bool = False
19
+ ) -> ty.Optional[ty.Any]:
20
+ is_param = param in property_data
21
+ if pass_if_not_exist and not is_param:
22
+ raise ValueError(f"{param} : must be in data keys")
23
+ if not pass_if_not_exist and not is_param:
24
+ return None
25
+ return property_data[param]
26
+
27
+
28
+ def operate_rule_on_value(value, rule: Rule):
29
+ try:
30
+ vtype = type(value)
31
+ rvalue = vtype(rule.value) # evaluate the rule value to the same type
32
+ operator = MAP_OPERATORS[rule.operator]
33
+ return operator(value, rvalue)
34
+ except Exception:
35
+ msg = f"Cannot evaluate rule {rule} on value {value!r} of type {vtype!s}"
36
+ logger.warning(msg)
37
+ return False
38
+
39
+
40
+
41
+ def rule_check_category(category, rule: Rule):
42
+ return category in rule.categories
43
+
44
+
45
+ def rule_check_dict(property_data: dict, rule: Rule, category=None) -> bool:
46
+ if category is not None and not rule_check_category(category, rule):
47
+ return False
48
+ value = get_param_value(property_data, rule.parameter)
49
+ if value is None:
50
+ return False
51
+ return operate_rule_on_value(value, rule)
52
+
53
+
54
+ def ruleset_check_dict(
55
+ property_data: dict, rule_set: RuleSet, category: ty.Union[None, str] = None
56
+ ) -> bool:
57
+ li = [rule_check_dict(property_data, r, category=category) for r in rule_set.rule]
58
+ if rule_set.set_type == RuleSetType.AND:
59
+ return False not in li
60
+ if rule_set.set_type == RuleSetType.OR:
61
+ return True in li
62
+ msg = "RuleSetType must be AND or OR"
63
+ raise ValueError(msg)
64
+
65
+
66
+ def ruleset_check_dicts(
67
+ li_property_data: list[dict],
68
+ rule_set: RuleSet,
69
+ li_categories: None | list = None,
70
+ ) -> list[bool]:
71
+ if li_categories is None:
72
+ li_categories = [None] * len(li_property_data)
73
+ elif len(li_categories) != len(li_property_data):
74
+ msg = "len(li_categories) != len(li_property_data):"
75
+ raise ValueError(msg)
76
+ else:
77
+ pass
78
+ return [
79
+ ruleset_check_dict(x, rule_set, category=li_categories[n])
80
+ for n, x in enumerate(li_property_data)
81
+ ]
82
+
83
+
84
+ # def operate_ruleset_on_value(value, rule_set: RuleSet):
85
+ # li = [operate_rule_on_value(value, r) for r in rule_set.rules]
86
+ # fn_or = lambda li: False if False in li else True
87
+ # fn_and = lambda li: True if True in li else False
88
+
89
+ # if rule_set.set_type == RuleSetType.AND:
90
+ # return fn_and(li)
91
+ # elif rule_set.set_type == RuleSetType.OR:
92
+ # return fn_or(li)
93
+ # else:
94
+ # raise ValueError("RuleSetType must be AND or OR")
@@ -0,0 +1,21 @@
1
+ # file generated by setuptools-scm
2
+ # don't change, don't track in version control
3
+
4
+ __all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
5
+
6
+ TYPE_CHECKING = False
7
+ if TYPE_CHECKING:
8
+ from typing import Tuple
9
+ from typing import Union
10
+
11
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
12
+ else:
13
+ VERSION_TUPLE = object
14
+
15
+ version: str
16
+ __version__: str
17
+ __version_tuple__: VERSION_TUPLE
18
+ version_tuple: VERSION_TUPLE
19
+
20
+ __version__ = version = '0.5.0'
21
+ __version_tuple__ = version_tuple = (0, 5, 0)
@@ -0,0 +1,189 @@
1
+ Category,Name,Include
2
+ OST_AbutmentFoundations,Abutment Foundations,0
3
+ OST_AbutmentPiles,Abutment Piles,0
4
+ OST_AbutmentWalls,Abutment Walls,0
5
+ OST_Alignments,Alignments,0
6
+ OST_AnalyticSpaces,Analytical Spaces,1
7
+ OST_AnalyticSurfaces,Analytical Surfaces,1
8
+ OST_AnalyticalNodes,Analytical Nodes,0
9
+ OST_AnalyticalPipeConnections,Analytical Pipe Connections,0
10
+ OST_ApproachSlabs,Approach Slabs,0
11
+ OST_AreaLoads,Area Loads,1
12
+ OST_AreaRein,Structural Area Reinforcement,0
13
+ OST_Areas,Areas,1
14
+ OST_Assemblies,Assemblies,1
15
+ OST_AudioVisualDevices,Audio Visual Devices,1
16
+ OST_BeamAnalytical,Analytical Beams,0
17
+ OST_BraceAnalytical,Analytical Braces,0
18
+ OST_BridgeAbutments,Abutments,0
19
+ OST_BridgeArches,Arches,0
20
+ OST_BridgeBearings,Bearings,0
21
+ OST_BridgeCables,Bridge Cables,0
22
+ OST_BridgeDecks,Bridge Decks,0
23
+ OST_BridgeFoundations,Pier Foundations,0
24
+ OST_BridgeFraming,Bridge Framing,0
25
+ OST_BridgeFramingCrossBracing,Cross Bracing,0
26
+ OST_BridgeFramingDiaphragms,Diaphragms,0
27
+ OST_BridgeFramingTrusses,Trusses,0
28
+ OST_BridgeGirders,Primarys,0
29
+ OST_BridgePiers,Piers,0
30
+ OST_BridgeTowers,Pier Towers,0
31
+ OST_BuildingPad,Pads,0
32
+ OST_CLines,Reference Planes,0
33
+ OST_CableTray,Cable Trays,1
34
+ OST_CableTrayFitting,Cable Tray Fittings,1
35
+ OST_Callouts,Callouts,1
36
+ OST_Casework,Casework,0
37
+ OST_Ceilings,Ceilings,0
38
+ OST_ColumnAnalytical,Analytical Columns,0
39
+ OST_Columns,Columns,0
40
+ OST_CommunicationDevices,Communication Devices,1
41
+ OST_Conduit,Conduits,1
42
+ OST_ConduitFitting,Conduit Fittings,1
43
+ OST_Coupler,Structural Rebar Couplers,0
44
+ OST_CurtaSystem,Curtain Systems,0
45
+ OST_CurtainWallMullions,Curtain Wall Mullions,0
46
+ OST_CurtainWallPanels,Curtain Panels,0
47
+ OST_DataDevices,Data Devices,1
48
+ OST_DetailComponents,Detail Items,1
49
+ OST_Doors,Doors,0
50
+ OST_DuctAccessory,Duct Accessories,1
51
+ OST_DuctCurves,Ducts,1
52
+ OST_DuctFitting,Duct Fittings,1
53
+ OST_DuctInsulations,Duct Insulations,1
54
+ OST_DuctLinings,Duct Linings,1
55
+ OST_DuctSystem,Duct Systems,1
56
+ OST_DuctTerminal,Air Terminals,1
57
+ OST_EdgeSlab,Slab Edges,0
58
+ OST_ElectricalEquipment,Electrical Equipment,1
59
+ OST_ElectricalFixtures,Electrical Fixtures,1
60
+ OST_Elev,Elevations,0
61
+ OST_Entourage,Entourage,0
62
+ OST_ExpansionJoints,Expansion Joints,0
63
+ OST_FabricAreas,Structural Fabric Areas,0
64
+ OST_FabricReinforcement,Structural Fabric Reinforcement,0
65
+ OST_FabricationContainment,MEP Fabrication Containment,1
66
+ OST_FabricationDuctwork,MEP Fabrication Ductwork,1
67
+ OST_FabricationDuctworkInsulation,Insulation,1
68
+ OST_FabricationDuctworkLining,Lining,1
69
+ OST_FabricationHangers,MEP Fabrication Hangers,1
70
+ OST_FabricationPipework,MEP Fabrication Pipework,1
71
+ OST_FabricationPipeworkInsulation,Insulation,1
72
+ OST_Fascia,Fascias,0
73
+ OST_FireAlarmDevices,Fire Alarm Devices,1
74
+ OST_FireProtection,Fire Protection,1
75
+ OST_FlexDuctCurves,Flex Ducts,1
76
+ OST_FlexPipeCurves,Flex Pipes,1
77
+ OST_FloorAnalytical,Analytical Floors,1
78
+ OST_Floors,Floors,0
79
+ OST_FoodServiceEquipment,Food Service Equipment,1
80
+ OST_FoundationSlabAnalytical,Analytical Foundation Slabs,0
81
+ OST_Furniture,Furniture,0
82
+ OST_FurnitureSystems,Furniture Systems,0
83
+ OST_GenericModel,Generic Models,1
84
+ OST_GridChains,Multi-segmented Grid,1
85
+ OST_Grids,Grids,1
86
+ OST_Gutter,Gutters,1
87
+ OST_HVAC_Zones,HVAC Zones,1
88
+ OST_Hardscape,Hardscape,0
89
+ OST_InternalAreaLoads,Internal Area Loads,0
90
+ OST_InternalLineLoads,Internal Line Loads,0
91
+ OST_InternalPointLoads,Internal Point Loads,0
92
+ OST_IsolatedFoundationAnalytical,Analytical Isolated Foundations,0
93
+ OST_Levels,Levels,0
94
+ OST_LightingDevices,Lighting Devices,1
95
+ OST_LightingFixtures,Lighting Fixtures,1
96
+ OST_LineLoads,Line Loads,0
97
+ OST_LinksAnalytical,Analytical Links,1
98
+ OST_MEPAnalyticalAirLoop,Air Systems,1
99
+ OST_MEPAnalyticalWaterLoop,Water Loops,1
100
+ OST_MEPSpaces,Spaces,1
101
+ OST_MEPSystemZone,System-Zones,1
102
+ OST_Mass,Mass,0
103
+ OST_MassExteriorWall,Mass Exterior Wall,0
104
+ OST_MassFloor,Mass Floor,0
105
+ OST_MassGlazing,Mass Glazing,0
106
+ OST_MassInteriorWall,Mass Interior Wall,0
107
+ OST_MassOpening,Mass Opening,0
108
+ OST_MassRoof,Mass Roof,0
109
+ OST_MassSkylights,Mass Skylight,0
110
+ OST_MassZone,Mass Zone,0
111
+ OST_MechanicalEquipment,Mechanical Equipment,1
112
+ OST_MedicalEquipment,Medical Equipment,1
113
+ OST_NurseCallDevices,Nurse Call Devices,1
114
+ OST_Parking,Parking,0
115
+ OST_Parts,Parts,0
116
+ OST_PathOfTravelLines,<Path of Travel Lines>,0
117
+ OST_PathRein,Structural Path Reinforcement,0
118
+ OST_PierCaps,Pier Caps,0
119
+ OST_PierColumns,Pier Columns,0
120
+ OST_PierPiles,Pier Piles,0
121
+ OST_PierWalls,Pier Walls,0
122
+ OST_PipeAccessory,Pipe Accessories,1
123
+ OST_PipeCurves,Pipes,1
124
+ OST_PipeFitting,Pipe Fittings,1
125
+ OST_PipeInsulations,Pipe Insulations,1
126
+ OST_PipingSystem,Piping Systems,1
127
+ OST_PlaceHolderDucts,Duct Placeholders,1
128
+ OST_PlaceHolderPipes,Pipe Placeholders,1
129
+ OST_Planting,Planting,0
130
+ OST_PlumbingFixtures,Plumbing Fixtures,1
131
+ OST_PointLoads,Point Loads,1
132
+ OST_RailingHandRail,Handrails,0
133
+ OST_RailingSupport,Supports,0
134
+ OST_RailingTermination,Terminations,0
135
+ OST_RailingTopRail,Top Rails,0
136
+ OST_Ramps,Ramps,0
137
+ OST_Rebar,Structural Rebar,0
138
+ OST_ReferenceLines,Reference Lines,1
139
+ OST_Roads,Roads,0
140
+ OST_Roofs,Roofs,0
141
+ OST_Rooms,Rooms,1
142
+ OST_Sections,Sections,1
143
+ OST_SecurityDevices,Security Devices,1
144
+ OST_ShaftOpening,Shaft Openings,0
145
+ OST_Signage,Signage,0
146
+ OST_Site,Site,0
147
+ OST_SiteProperty,Property Lines,0
148
+ OST_SitePropertyLineSegment,Property Line Segments,0
149
+ OST_SpecialityEquipment,Specialty Equipment,0
150
+ OST_Sprinklers,Sprinklers,1
151
+ OST_Stairs,Stairs,0
152
+ OST_StairsLandings,Landings,0
153
+ OST_StairsRailing,Railings,0
154
+ OST_StairsRailingBaluster,Balusters,0
155
+ OST_StairsRuns,Runs,0
156
+ OST_StairsStringerCarriage,Supports,0
157
+ OST_StructConnectionAnchors,Anchors,0
158
+ OST_StructConnectionBolts,Bolts,0
159
+ OST_StructConnectionHoles,Holes,0
160
+ OST_StructConnectionModifiers,Modifiers,0
161
+ OST_StructConnectionOthers,Others,0
162
+ OST_StructConnectionPlates,Plates,0
163
+ OST_StructConnectionProfiles,Profiles,0
164
+ OST_StructConnectionShearStuds,Shear Studs,0
165
+ OST_StructConnectionSymbol,Symbol,0
166
+ OST_StructConnectionWelds,Welds,0
167
+ OST_StructConnections,Structural Connections,0
168
+ OST_StructSubConnections,None,0
169
+ OST_StructuralColumns,Structural Columns,0
170
+ OST_StructuralFoundation,Structural Foundations,0
171
+ OST_StructuralFraming,Structural Framing,0
172
+ OST_StructuralFramingSystem,Structural Beam Systems,0
173
+ OST_StructuralStiffener,Structural Stiffeners,0
174
+ OST_StructuralTendons,Structural Tendons,0
175
+ OST_StructuralTruss,Structural Trusses,0
176
+ OST_SwitchSystem,Switch System,1
177
+ OST_TelephoneDevices,Telephone Devices,1
178
+ OST_TemporaryStructure,Temporary Structures,0
179
+ OST_Topography,Topography,0
180
+ OST_VerticalCirculation,Vertical Circulation,0
181
+ OST_VibrationDampers,Vibration Dampers,0
182
+ OST_VibrationIsolators,Vibration Isolators,0
183
+ OST_VibrationManagement,Vibration Management,0
184
+ OST_WallAnalytical,Analytical Walls,1
185
+ OST_WallFoundationAnalytical,Analytical Wall Foundations,0
186
+ OST_Walls,Walls,0
187
+ OST_Windows,Windows,0
188
+ OST_Wire,Wires,0
189
+ OST_ZoneEquipment,Zone Equipment,1
pyrulefilter/enums.py ADDED
@@ -0,0 +1,58 @@
1
+ from enum import Enum
2
+ import csv
3
+ import pathlib
4
+ import os
5
+
6
+ if "PATH_PYRULEFILTER_CATEGORIES" in os.environ:
7
+ PATH_PYRULEFILTER_CATEGORIES = pathlib.Path(
8
+ os.environ["PATH_PYRULEFILTER_CATEGORIES"]
9
+ )
10
+ else:
11
+ PATH_PYRULEFILTER_CATEGORIES = pathlib.Path(__file__).parent / "categories.csv"
12
+
13
+
14
+ def read_csv(p: pathlib.Path):
15
+ # NOTE: could use pandas for this but it is heavy so could slow imports down.
16
+ li = list(csv.reader(p.read_text().split("\n"), delimiter=","))
17
+ return [dict(zip(li[0], li[n])) for n in range(1, len(li)) if li[n] != []]
18
+
19
+
20
+ def get_categories(filter=True):
21
+ li = read_csv(PATH_PYRULEFILTER_CATEGORIES)
22
+ if filter:
23
+ li = [x for x in li if bool(int(x["Include"]))]
24
+ return {x["Category"]: x["Name"] for x in li}
25
+
26
+
27
+ class OperatorsEnum(str, Enum):
28
+ BeginsWith = "begins with"
29
+ Contains = "contains"
30
+ EndsWith = "ends with"
31
+ Equals = "equals"
32
+ # GreaterOrEqual = "is greater than or equal to"
33
+ # Greater = "is greater than"
34
+ # HasNoValueParameter = "has no value"
35
+ # HasValueParameter = "has value"
36
+ # IsAssociatedWithGlobalParameterRule = "?"
37
+ # IsNotAssociatedWithGlobalParameterRule = "?"
38
+ # LessOrEqual = "is less than or equal to"
39
+ # Less = "is less than"
40
+ NotBeginsWith = "does not begin with"
41
+ NotContains = "does not contain"
42
+ NotEndsWith = "does not end with"
43
+ NotEquals = "does not equal"
44
+ # SharedParameterApplicableRule = "?"
45
+
46
+
47
+ class StrEnum(str, Enum):
48
+ pass
49
+
50
+
51
+ FilterCategoriesEnum = StrEnum("FilterCategoriesEnum", get_categories())
52
+
53
+
54
+ class RuleSetType(str, Enum):
55
+ AND = "AND"
56
+ OR = "OR"
57
+
58
+
@@ -0,0 +1,152 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ import operator
5
+ from pyrulefilter.enums import OperatorsEnum
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+
10
+ def contains(a: str, b: str) -> bool:
11
+ """Check a in b.
12
+
13
+ ```py
14
+ from pyrulefilter.operators import contains
15
+
16
+ print(contains("hello", "hell"))
17
+ #> True
18
+ print(contains("heel", "hello"))
19
+ #> False
20
+ ```
21
+ """
22
+ return b in a
23
+
24
+
25
+ def not_contains(a: str, b: str) -> bool:
26
+ """Check a not in b.
27
+
28
+ ```py
29
+ from pyrulefilter.operators import not_contains
30
+
31
+ print(not_contains("hello", "hell"))
32
+ #> False
33
+ print(not_contains("heel", "hello"))
34
+ #> True
35
+ ```
36
+ """
37
+ return b not in a
38
+
39
+
40
+ def startswith(a: str, b: str) -> bool:
41
+ """Check a startswith b.
42
+
43
+ ```py
44
+ from pyrulefilter.operators import startswith
45
+
46
+ print(startswith("hello", "hell"))
47
+ #> True
48
+ print(startswith("heel", "hello"))
49
+ #> False
50
+ ```
51
+ """
52
+ return bool(a.startswith(b))
53
+
54
+
55
+ def not_startswith(a: str, b: str) -> bool:
56
+ """Check a not startswith b.
57
+
58
+ ```py
59
+ from pyrulefilter.operators import not_startswith
60
+
61
+ print(not_startswith("hello", "hell"))
62
+ #> False
63
+ print(not_startswith("heel", "hello"))
64
+ #> True
65
+ ```
66
+ """
67
+ return bool(not a.startswith(b))
68
+
69
+
70
+ def endswith(a: str, b: str) -> bool:
71
+ """Check a endswith b
72
+
73
+ ```py
74
+ from pyrulefilter.operators import endswith
75
+
76
+ print(endswith("hello", "lo"))
77
+ #> True
78
+ print(endswith("hello", "elo"))
79
+ #> False
80
+ ```
81
+ """
82
+ return bool(a.endswith(b))
83
+
84
+
85
+ def not_endswith(a: str, b: str) -> bool:
86
+ """Check a not_endswith b.
87
+
88
+ ```py
89
+ from pyrulefilter.operators import not_endswith
90
+
91
+ print(not_endswith("hello", "lo"))
92
+ #> False
93
+ print(not_endswith("hello", "elo"))
94
+ #> True
95
+ ```
96
+ """
97
+ return bool(not a.endswith(b))
98
+
99
+
100
+ def isnone(a, b=None) -> bool:
101
+ """Check a isnone.
102
+
103
+ ```py
104
+ from pyrulefilter.operators import isnone
105
+
106
+ print(isnone("hello"))
107
+ #> False
108
+ print(isnone(None))
109
+ #> True
110
+ ```
111
+ """
112
+ return a is None
113
+
114
+
115
+ def not_isnone(a, b=None) -> bool:
116
+ """Check a isnone.
117
+
118
+ ```py
119
+ from pyrulefilter.operators import not_isnone
120
+
121
+ print(not_isnone("hello"))
122
+ #> True
123
+ print(not_isnone(None))
124
+ #> False
125
+ ```
126
+ """
127
+ return a is not None
128
+
129
+
130
+ MAP_OPERATORS = {
131
+ # OperatorsEnum.Less: operator.lt,
132
+ # OperatorsEnum.LessOrEqual: operator.le,
133
+ OperatorsEnum.Equals: operator.eq,
134
+ OperatorsEnum.NotEquals: operator.ne,
135
+ # OperatorsEnum.GreaterOrEqual: operator.ge,
136
+ # OperatorsEnum.Greater: operator.gt,
137
+ OperatorsEnum.Contains: contains,
138
+ OperatorsEnum.NotContains: not_contains,
139
+ OperatorsEnum.BeginsWith: startswith,
140
+ OperatorsEnum.NotBeginsWith: not_startswith,
141
+ OperatorsEnum.EndsWith: endswith,
142
+ OperatorsEnum.NotEndsWith: not_endswith,
143
+ # OperatorsEnum.HasValueParameter: isnone,
144
+ # OperatorsEnum.HasNoValueParameter: not_isnone,
145
+ }
146
+
147
+ # "CreateIsAssociatedWithGlobalParameterRule": "?",
148
+ # "CreateIsNotAssociatedWithGlobalParameterRule": "?",
149
+ # "CreateSharedParameterApplicableRule": "?"
150
+ # ^^^ revit filters not mapped...
151
+
152
+
@@ -0,0 +1,98 @@
1
+ import typing as ty
2
+ from pydantic import ConfigDict, BaseModel, Field, BeforeValidator
3
+ from pyrulefilter.enums import (
4
+ FilterCategoriesEnum,
5
+ OperatorsEnum,
6
+ RuleSetType,
7
+ )
8
+ from typing_extensions import Annotated
9
+
10
+
11
+ class BaseModel(BaseModel): # https://github.com/pydantic/pydantic/issues/1836
12
+ @classmethod
13
+ def schema(cls, **kwargs):
14
+ schema = super().schema(**kwargs)
15
+ for fld_v in cls.__fields__.values():
16
+ if fld_v.default_factory is not None:
17
+ schema["properties"][fld_v.alias]["default"] = fld_v.default_factory()
18
+ return schema
19
+
20
+
21
+ def html_link(url: str, description: str, color: str = "blue"):
22
+ """returns an html link string to open in new tab
23
+
24
+ Args:
25
+ url (url):
26
+ description (str): the text to display for the link
27
+ color (str, optional): color of description text. Defaults to "blue".
28
+
29
+ Returns:
30
+ str: html text
31
+ """
32
+ return (
33
+ f'<font color="{color}"><a href="{url}" target="blank"'
34
+ f" >{description}</a></font>"
35
+ )
36
+
37
+
38
+ URL_REVIT_FILTERS = "https://help.autodesk.com/view/RVT/2023/ENU/?guid=GUID-400FD74B-00E0-4573-B3AC-3965E65CBBDB"
39
+ URL_UNICLASS_SYSTEMS = "https://uniclass.thenbs.com/taxon/ss"
40
+ URL_UNICLASS_PRODUCTS = "https://uniclass.thenbs.com/taxon/pr"
41
+ HTMLLINK_UNICLASS_SYSTEMS = html_link(URL_UNICLASS_SYSTEMS, "Uniclass System codes đź”—")
42
+ HTMLLINK_UNICLASS_PRODUCTS = html_link(
43
+ URL_UNICLASS_PRODUCTS, "Uniclass Product codes đź”—"
44
+ )
45
+
46
+
47
+ FilterCategories = Annotated[
48
+ list[FilterCategoriesEnum], BeforeValidator(lambda v: [] if v is None else v)
49
+ ]
50
+
51
+
52
+ class Rule(BaseModel):
53
+ categories: FilterCategories = Field(
54
+ default=[],
55
+ title="Categories", # TODO: this is pydantic bug (should generate title from field name)
56
+ description="Revit MEP categories to filter by (i.e. revit object must belong to categories defined here). If empty, all categories are included.",
57
+ )
58
+ parameter: str = Field(
59
+ description="name of schedule parameter against which to apply filter rule",
60
+ json_schema_extra=dict(autoui="ipywidgets.Combobox"),
61
+ )
62
+ operator: OperatorsEnum = Field(
63
+ title="Logical Operator",
64
+ description="logical operator used to evaluate parameter value against value below",
65
+ )
66
+ value: str = Field(
67
+ "",
68
+ description="Value to filter by. Evaluates to the appropriate type. Leave empty if none required (e.g. has value operator)",
69
+ json_schema_extra=dict(autoui="ipywidgets.Combobox"),
70
+ )
71
+ model_config = ConfigDict(
72
+ json_schema_extra=dict(autoui="ipyautoui.demo_schemas.ruleset.rule_ui")
73
+ )
74
+
75
+
76
+ RuleSet = ty.ForwardRef("RuleSet")
77
+
78
+
79
+ class RuleSet(BaseModel):
80
+ set_type: RuleSetType = Field(default=RuleSetType.OR)
81
+ rule: ty.List[ty.Union[Rule, RuleSet]] = Field(
82
+ description="""
83
+ rules return a boolean for the logical evaluation defined below for every item within the categories defined
84
+ """
85
+ )
86
+
87
+ model_config = ConfigDict(title="RuleSet")
88
+
89
+
90
+ RuleSet.__doc__ = (
91
+ """A set of rules that defines what equipment specifications will appear in a given schedule.<br>
92
+ Rules must evaluate to True for the item to be included in a schedule.
93
+ This is analogous to how
94
+ """
95
+ + html_link(URL_REVIT_FILTERS, "filter rules work in Revit.")
96
+ + "<br>As such, rules defined are imported into Revit and are used to create Revit"
97
+ " Schedules.<br><hr>"
98
+ )
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyrulefilter
3
+ Version: 0.5.0
4
+ Author-email: jgunstone <j.gunstone@maxfordham.com>
5
+ License-Expression: BSD-3-Clause
6
+ License-File: licenses/BSD-3-Clause.txt
7
+ Keywords: revit,rules
8
+ Requires-Python: >=3.11
9
+ Requires-Dist: pydantic>2
@@ -0,0 +1,10 @@
1
+ pyrulefilter/__init__.py,sha256=ly1KnhOyJbjN4EYzLCWiT1vXHpgiznu4Rv48CYJe5ds,2939
2
+ pyrulefilter/_version.py,sha256=N2U3TRgLfYxjXfoF4Dy9PxAbZq24zjCym3P3cwuxKP8,511
3
+ pyrulefilter/categories.csv,sha256=K09GKql9iuCA5UftR4HMn0VQuB06AoyJnq0H8rKxzdo,6634
4
+ pyrulefilter/enums.py,sha256=z-0AKBGJ0B1ia6Eg4z5fRpds657LvGM9RCaVyv6hleg,1620
5
+ pyrulefilter/operators.py,sha256=xaLE4kuCJv-uhK0YIoyIR3wsIpe0O7QQ3npsPDHbBQY,3142
6
+ pyrulefilter/schemas.py,sha256=xoeZAewtdcsbs9BE9gtWPVcXZxiAR0jNdxvW15Kg3q0,3426
7
+ pyrulefilter-0.5.0.dist-info/METADATA,sha256=00iFbwxZb_BTtr0Y-YMay-FgP0fNXiGmxyIBO7PrtvA,253
8
+ pyrulefilter-0.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ pyrulefilter-0.5.0.dist-info/licenses/licenses/BSD-3-Clause.txt,sha256=-0vkRCqQjzeS_FcMEdseehYhEP9zRnS3-tv9-uAum0k,1644
10
+ pyrulefilter-0.5.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,15 @@
1
+ Note: This license has also been called the “New BSD License” or “Modified BSD License”. See also the 2-clause BSD License.
2
+
3
+ Copyright <YEAR> <COPYRIGHT HOLDER>
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10
+
11
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
+
15
+ // SPDX-License-Identifier: BSD-3-Clause