@@ -94,147 +94,114 @@ def evaluate_rule(iteration_rule: IterationRule, attribute_value: Any) -> bool:
9494 return int (attribute_value or 0 ) >= int (iteration_rule .comparator )
9595 case RuleOperator .lte :
9696 return int (attribute_value or 0 ) <= int (iteration_rule .comparator )
97-
9897 case RuleOperator .contains :
9998 return attribute_value and iteration_rule .comparator in str (attribute_value )
10099 case RuleOperator .not_contains :
101100 return iteration_rule .comparator not in str (attribute_value )
102-
103101 case RuleOperator .starts_with :
104102 return str (attribute_value ).startswith (iteration_rule .comparator )
105103 case RuleOperator .not_starts_with :
106104 return not str (attribute_value ).startswith (iteration_rule .comparator )
107-
108105 case RuleOperator .ends_with :
109106 return str (attribute_value ).endswith (iteration_rule .comparator )
110-
111107 case RuleOperator .is_in :
112108 comparators = str (iteration_rule .comparator ).split ("," )
113109 return str (attribute_value ) in comparators
114110 case RuleOperator .not_in :
115111 comparators = str (iteration_rule .comparator ).split ("," )
116112 return str (attribute_value ) not in comparators
117-
118113 case RuleOperator .member_of :
119114 attribute_values = str (attribute_value ).split ("," )
120115 return iteration_rule .comparator in attribute_values
121116 case RuleOperator .not_member_of :
122117 attribute_values = str (attribute_value ).split ("," )
123118 return iteration_rule .comparator not in attribute_values
124-
125119 case RuleOperator .is_null :
126120 return attribute_value in (None , "" )
127121 case RuleOperator .is_not_null :
128122 return attribute_value not in (None , "" )
129-
130123 case RuleOperator .between :
131- if attribute_value in (None , "" ): return False
124+ if attribute_value in (None , "" ):
125+ return False
132126 low_comparator_str , high_comparator_str = str (iteration_rule .comparator ).split ("," )
133127 low_comparator = min (int (low_comparator_str ), int (high_comparator_str ))
134128 high_comparator = max (int (low_comparator_str ), int (high_comparator_str ))
135129 return low_comparator <= int (attribute_value ) <= high_comparator
136-
137130 case RuleOperator .not_between :
138- if attribute_value in (None , "" ): return False
131+ if attribute_value in (None , "" ):
132+ return False
139133 low_comparator_str , high_comparator_str = str (iteration_rule .comparator ).split ("," )
140134 low_comparator = min (int (low_comparator_str ), int (high_comparator_str ))
141135 high_comparator = max (int (low_comparator_str ), int (high_comparator_str ))
142136 return int (attribute_value ) < low_comparator or int (attribute_value ) > high_comparator
143-
144137 case RuleOperator .is_empty :
145- return (
146- attribute_value is None or
147- all (item .strip () == '' for item in attribute_value .split (',' ))
148- )
149-
138+ return attribute_value is None or all (item .strip () == "" for item in attribute_value .split ("," ))
150139 case RuleOperator .is_not_empty :
151- return (
152- attribute_value is not None and
153- any (item .strip () != '' for item in attribute_value .split (',' ))
154- )
155-
140+ return attribute_value is not None and any (item .strip () != "" for item in attribute_value .split ("," ))
156141 case RuleOperator .is_true :
157142 return attribute_value is True
158143 case RuleOperator .is_false :
159144 return attribute_value is False
160-
161-
162145 case RuleOperator .day_lte :
163- attribute_date = datetime .strptime (str (attribute_value ), ' %Y%m%d' ) if attribute_value else None # noqa: DTZ007
146+ attribute_date = datetime .strptime (str (attribute_value ), " %Y%m%d" ) if attribute_value else None # noqa: DTZ007
164147 today_date = datetime .today ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
165148 cutoff = today_date + relativedelta (days = int (iteration_rule .comparator ))
166149 return (attribute_date <= cutoff ) if attribute_date else False
167-
168150 case RuleOperator .day_lt :
169- attribute_date = datetime .strptime (str (attribute_value ), ' %Y%m%d' ) if attribute_value else None # noqa: DTZ007
151+ attribute_date = datetime .strptime (str (attribute_value ), " %Y%m%d" ) if attribute_value else None # noqa: DTZ007
170152 today_date = datetime .today ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
171153 cutoff = today_date + relativedelta (days = int (iteration_rule .comparator ))
172154 return (attribute_date < cutoff ) if attribute_date else False
173-
174155 case RuleOperator .day_gte :
175- attribute_date = datetime .strptime (str (attribute_value ),' %Y%m%d' ) if attribute_value else None # noqa: DTZ007
156+ attribute_date = datetime .strptime (str (attribute_value ), " %Y%m%d" ) if attribute_value else None # noqa: DTZ007
176157 today_date = datetime .today ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
177158 cutoff = today_date + relativedelta (days = int (iteration_rule .comparator ))
178159 return (attribute_date >= cutoff ) if attribute_date else False
179-
180160 case RuleOperator .day_gt :
181- attribute_date = datetime .strptime (str (attribute_value ),' %Y%m%d' ) if attribute_value else None # noqa: DTZ007
161+ attribute_date = datetime .strptime (str (attribute_value ), " %Y%m%d" ) if attribute_value else None # noqa: DTZ007
182162 today_date = datetime .today ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
183163 cutoff = today_date + relativedelta (days = int (iteration_rule .comparator ))
184164 return (attribute_date > cutoff ) if attribute_date else False
185-
186-
187165 case RuleOperator .week_lte :
188- attribute_date = datetime .strptime (str (attribute_value ), ' %Y%m%d' ) if attribute_value else None # noqa: DTZ007
166+ attribute_date = datetime .strptime (str (attribute_value ), " %Y%m%d" ) if attribute_value else None # noqa: DTZ007
189167 today_date = datetime .today ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
190168 cutoff = today_date + relativedelta (weeks = int (iteration_rule .comparator ))
191169 return (attribute_date <= cutoff ) if attribute_date else False
192-
193170 case RuleOperator .week_lt :
194- attribute_date = datetime .strptime (str (attribute_value ), ' %Y%m%d' ) if attribute_value else None # noqa: DTZ007
171+ attribute_date = datetime .strptime (str (attribute_value ), " %Y%m%d" ) if attribute_value else None # noqa: DTZ007
195172 today_date = datetime .today ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
196173 cutoff = today_date + relativedelta (weeks = int (iteration_rule .comparator ))
197174 return (attribute_date < cutoff ) if attribute_date else False
198-
199175 case RuleOperator .week_gte :
200- attribute_date = datetime .strptime (str (attribute_value ),' %Y%m%d' ) if attribute_value else None # noqa: DTZ007
176+ attribute_date = datetime .strptime (str (attribute_value ), " %Y%m%d" ) if attribute_value else None # noqa: DTZ007
201177 today_date = datetime .today ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
202178 cutoff = today_date + relativedelta (weeks = int (iteration_rule .comparator ))
203179 return (attribute_date >= cutoff ) if attribute_date else False
204-
205180 case RuleOperator .week_gt :
206- attribute_date = datetime .strptime (str (attribute_value ),' %Y%m%d' ) if attribute_value else None # noqa: DTZ007
181+ attribute_date = datetime .strptime (str (attribute_value ), " %Y%m%d" ) if attribute_value else None # noqa: DTZ007
207182 today_date = datetime .today ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
208183 cutoff = today_date + relativedelta (weeks = int (iteration_rule .comparator ))
209184 return (attribute_date > cutoff ) if attribute_date else False
210-
211-
212185 case RuleOperator .year_lte :
213- attribute_date = datetime .strptime (str (attribute_value ), ' %Y%m%d' ) if attribute_value else None # noqa: DTZ007
186+ attribute_date = datetime .strptime (str (attribute_value ), " %Y%m%d" ) if attribute_value else None # noqa: DTZ007
214187 today_date = datetime .today ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
215188 cutoff = today_date + relativedelta (years = int (iteration_rule .comparator ))
216189 return (attribute_date <= cutoff ) if attribute_date else False
217-
218190 case RuleOperator .year_lt :
219- attribute_date = datetime .strptime (str (attribute_value ), ' %Y%m%d' ) if attribute_value else None # noqa: DTZ007
191+ attribute_date = datetime .strptime (str (attribute_value ), " %Y%m%d" ) if attribute_value else None # noqa: DTZ007
220192 today_date = datetime .today ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
221193 cutoff = today_date + relativedelta (years = int (iteration_rule .comparator ))
222194 return (attribute_date < cutoff ) if attribute_date else False
223-
224195 case RuleOperator .year_gte :
225- attribute_date = datetime .strptime (str (attribute_value ),' %Y%m%d' ) if attribute_value else None # noqa: DTZ007
196+ attribute_date = datetime .strptime (str (attribute_value ), " %Y%m%d" ) if attribute_value else None # noqa: DTZ007
226197 today_date = datetime .today ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
227198 cutoff = today_date + relativedelta (years = int (iteration_rule .comparator ))
228199 return (attribute_date >= cutoff ) if attribute_date else False
229-
230200 case RuleOperator .year_gt :
231- attribute_date = datetime .strptime (str (attribute_value ),
232- "%Y%m%d" ) if attribute_value else None # noqa: DTZ007
201+ attribute_date = datetime .strptime (str (attribute_value ), "%Y%m%d" ) if attribute_value else None # noqa: DTZ007
233202 today = datetime .today ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
234203 cutoff = today + relativedelta (years = int (iteration_rule .comparator ))
235204 return (attribute_date > cutoff ) if attribute_date else False
236-
237-
238205 case _:
239206 msg = f"{ iteration_rule .operator } not implemented"
240207 raise NotImplementedError (msg )
0 commit comments