88
99from sgf_parser .datetime_parser import convert_str_to_datetime , convert_str_to_time
1010from sgf_parser .models import MethodType
11- from sgf_parser .models .types import FlushingVariant , HammeringVariant , RotationVariant
1211
1312
1413class MethodData (BaseModel , abc .ABC ):
@@ -135,11 +134,8 @@ def __repr__(self):
135134
136135# class Method(BaseModel, abc.ABC):
137136class Method (BaseModel ):
138- _flushing_variant : FlushingVariant | None = None
139137 _current_flushing_active_state : bool = False
140- _hammering_variant : HammeringVariant | None = None
141138 _current_hammer_active_state : bool = False
142- _rotation_variant : RotationVariant | None = None
143139 _current_increased_rotation_state : bool = False
144140
145141 def __init__ (self , ** kwargs ):
@@ -148,31 +144,6 @@ def __init__(self, **kwargs):
148144 def post_processing (self ):
149145 pass
150146
151- def detect_flushing_rule (self ) -> FlushingVariant :
152- """
153- Call this with the method data before parsing the method data.
154-
155- The result of calling this method will set the self.detected_flushing_variant to either use the "K" code if any
156- regulating the flushing are present, the "AR" (flushing on/off) code or the "I" (flushing pressure) code.
157- """
158- if self ._flushing_variant :
159- return self ._flushing_variant
160-
161- if any (
162- [
163- row .comment_code in (72 , 73 , 76 , 77 )
164- or any (x in (72 , 73 , 76 , 77 ) for x in self .extract_codes (row .remarks ))
165- for row in self .method_data
166- ]
167- ):
168- self ._flushing_variant = FlushingVariant .CODE_K
169- elif any ([getattr (row , "flushing" ) is not None for row in self .method_data ]):
170- self ._flushing_variant = FlushingVariant .CODE_AR
171- else :
172- self ._flushing_variant = FlushingVariant .CODE_I
173-
174- return self ._flushing_variant
175-
176147 @classmethod
177148 def extract_codes (cls , remarks : str | None ) -> tuple [int , ...]:
178149 """
@@ -195,10 +166,10 @@ def is_flushing_active(
195166
196167 The following priority should be used to figure out if flushing is active:
197168
198- 1. Check K (kode) regulating flushing in file, use only K codes
199- 2. If no K codes present in file , then check if "AR" code is present and has
169+ 1. Check K (kode) regulating flushing in file
170+ 2. If no K code present, then check if "AR" code is present and has
200171 a value (0 or 0.0 = off, 1 or 1.0 = on)
201- 3. If no "AR" code is present in the file , then check if "I" (flushing pressure) > 0.1
172+ 3. If no "AR" code is present, then check if "I" (flushing pressure) > 0.1
202173 4. Otherwise, return False
203174
204175 Codes used:
@@ -207,49 +178,28 @@ def is_flushing_active(
207178 Kode 76 (hammer and flushing on)
208179 Kode 77 (hammer and flushing off)
209180 """
210- if self ._flushing_variant == FlushingVariant .CODE_K :
211- if data_row .comment_code in (72 , 76 ) or any (x in (72 , 76 ) for x in self .extract_codes (data_row .remarks )):
181+ if data_row .comment_code in (72 , 76 ) or any (x in (72 , 76 ) for x in self .extract_codes (data_row .remarks )):
182+ self ._current_flushing_active_state = True
183+ return self ._current_flushing_active_state
184+ # TODO: check remark for extra codes
185+ elif data_row .comment_code in (73 , 77 ) or any (x in (73 , 77 ) for x in self .extract_codes (data_row .remarks )):
186+ self ._current_flushing_active_state = False
187+ return self ._current_flushing_active_state
188+
189+ if data_row .flushing is not None :
190+ self ._current_flushing_active_state = data_row .flushing
191+ return self ._current_flushing_active_state
192+
193+ if data_row .flushing_pressure is not None :
194+ if data_row .flushing_pressure > Decimal ("0.1" ):
212195 self ._current_flushing_active_state = True
213- # TODO: check remark for extra codes
214- elif data_row .comment_code in (73 , 77 ) or any (x in (73 , 77 ) for x in self .extract_codes (data_row .remarks )):
196+ else :
215197 self ._current_flushing_active_state = False
216198
217- elif self ._flushing_variant == FlushingVariant .CODE_AR :
218- if data_row .flushing is not None :
219- self ._current_flushing_active_state = data_row .flushing
220-
221- elif self ._flushing_variant == FlushingVariant .CODE_I :
222- if data_row .flushing_pressure is not None :
223- if data_row .flushing_pressure > Decimal ("0.1" ):
224- self ._current_flushing_active_state = True
225- else :
226- self ._current_flushing_active_state = False
199+ return self ._current_flushing_active_state
227200
228201 return self ._current_flushing_active_state
229202
230- def detect_hammering_rule (self ) -> HammeringVariant | None :
231- """
232- Call this with the method data loaded before parsing the hammering in the method data.
233-
234- The result of calling this method will set the self._hammering_variant to either use the "K" code if
235- any regulating the hammering are present, the "AP" (hammering on/off) code.
236- """
237- if self ._hammering_variant :
238- return self ._hammering_variant
239-
240- if any (
241- [
242- row .comment_code in (74 , 75 , 76 , 77 )
243- or any (x in (74 , 75 , 76 , 77 ) for x in self .extract_codes (row .remarks ))
244- for row in self .method_data
245- ]
246- ):
247- self ._hammering_variant = HammeringVariant .K
248- else :
249- self ._hammering_variant = HammeringVariant .AP
250-
251- return self ._hammering_variant
252-
253203 def is_hammer_active (
254204 self ,
255205 data_row , #: models.MethodCPTData| models.MethodTOTData| models.MethodRPData| models.MethodSRSData,
@@ -269,46 +219,18 @@ def is_hammer_active(
269219 Kode 76 (hammer and flushing on)
270220 Kode 77 (hammer and flushing off)
271221 """
272- if self ._hammering_variant == HammeringVariant .K :
273- if data_row .comment_code in (74 , 76 ) or any (x in (74 , 76 ) for x in self .extract_codes (data_row .remarks )):
274- self ._current_hammer_active_state = True
275- return self ._current_hammer_active_state
276- elif data_row .comment_code in (75 , 77 ) or any (x in (75 , 77 ) for x in self .extract_codes (data_row .remarks )):
277- self ._current_hammer_active_state = False
278- return self ._current_hammer_active_state
279-
280- elif self ._hammering_variant == HammeringVariant .AP :
281- if data_row .hammering is not None :
282- self ._current_hammer_active_state = data_row .hammering
283- return self ._current_hammer_active_state
284-
285- return self ._current_hammer_active_state
286-
287- def detect_increased_rotation_rule (self ) -> RotationVariant | None :
288- """
289- Call this with the method data before updating the increased rotation in the method data.
222+ if data_row .comment_code in (74 , 76 ) or any (x in (74 , 76 ) for x in self .extract_codes (data_row .remarks )):
223+ self ._current_hammer_active_state = True
224+ return self ._current_hammer_active_state
225+ elif data_row .comment_code in (75 , 77 ) or any (x in (75 , 77 ) for x in self .extract_codes (data_row .remarks )):
226+ self ._current_hammer_active_state = False
227+ return self ._current_hammer_active_state
290228
291- The result of calling this method will set the self._increased_rotation_variant to either use the
292- "K" code if any regulating the increased rotation are present, the "AQ" (increased rotation on/off) code
293- or the "R" (rotation rate) code.
294- """
229+ if data_row .hammering is not None :
230+ self ._current_hammer_active_state = data_row .hammering
231+ return self ._current_hammer_active_state
295232
296- if self ._rotation_variant :
297- return self ._rotation_variant
298-
299- if any (
300- [
301- row .comment_code in (70 , 71 ) or any (x in (70 , 71 ) for x in self .extract_codes (row .remarks ))
302- for row in self .method_data
303- ]
304- ):
305- self ._rotation_variant = RotationVariant .K
306- elif any ([row .increased_rotation_rate is not None for row in self .method_data ]):
307- self ._rotation_variant = RotationVariant .AQ
308- else :
309- self ._rotation_variant = RotationVariant .R
310-
311- return self ._rotation_variant
233+ return self ._current_hammer_active_state
312234
313235 def is_increased_rotation_active (
314236 self ,
@@ -328,53 +250,24 @@ def is_increased_rotation_active(
328250 Kode 70 (increased rotation speed on)
329251 Kode 71 (increased rotation speed off)
330252 """
331- if self ._rotation_variant == RotationVariant .K :
332- if data_row .comment_code == 70 :
253+ if data_row .comment_code == 70 :
254+ self ._current_increased_rotation_state = True
255+ return self ._current_increased_rotation_state
256+ elif data_row .comment_code == 71 :
257+ self ._current_increased_rotation_state = False
258+ return self ._current_increased_rotation_state
259+ if data_row .increased_rotation_rate is not None :
260+ self ._current_increased_rotation_state = data_row .increased_rotation_rate
261+ return self ._current_increased_rotation_state
262+ if data_row .rotation_rate is not None :
263+ if data_row .rotation_rate > 35 :
333264 self ._current_increased_rotation_state = True
334- elif data_row . comment_code == 71 :
265+ else :
335266 self ._current_increased_rotation_state = False
336- elif self ._rotation_variant == RotationVariant .AQ :
337- if data_row .increased_rotation_rate is not None :
338- self ._current_increased_rotation_state = data_row .increased_rotation_rate
339- else :
340- if data_row .rotation_rate is not None :
341- if data_row .rotation_rate > 35 :
342- self ._current_increased_rotation_state = True
343- else :
344- self ._current_increased_rotation_state = False
267+ return self ._current_increased_rotation_state
345268
346269 return self ._current_increased_rotation_state
347270
348- def flushing_update (self ):
349- """
350- Update flushing
351-
352- """
353- self ._flushing_variant = self .detect_flushing_rule ()
354-
355- for data in self .method_data :
356- data .flushing = self .is_flushing_active (data )
357-
358- def hammering_update (self ):
359- """
360- Update hammering
361-
362- """
363- self ._hammering_variant = self .detect_hammering_rule ()
364-
365- for data in self .method_data :
366- data .hammering = self .is_hammer_active (data )
367-
368- def rotation_update (self ):
369- """
370- Update rotation
371-
372- """
373- self ._rotation_variant = self .detect_increased_rotation_rule ()
374-
375- for data in self .method_data :
376- data .increased_rotation_rate = self .is_increased_rotation_active (data )
377-
378271 @model_validator (mode = "before" )
379272 @classmethod
380273 def guess_date_format (cls , data : Any ) -> Any :
0 commit comments