@@ -248,12 +248,6 @@ def valid_ink_trajectory(
248248 ):
249249 ink_end_idx = idx
250250 break
251- if (
252- ink_start_idx is not None
253- and ink_end_idx is not None
254- and ink_end_idx > ink_start_idx
255- ):
256- self .ink_points = self .points .iloc [ink_start_idx : ink_end_idx + 1 ].copy ()
257251
258252 return ink_start_idx , ink_end_idx
259253
@@ -358,8 +352,9 @@ def calculate_smoothness(self) -> None:
358352 """Calculate path smoothness based on Root Mean Square (RMS) curvature.
359353
360354 Represents the curvature per unit arc length.
361- Lower values indicate smoother drawings. Penalizes sharp corners (e.g., 90° turns)
362- and noisy corrections. Normalized by arc length to reduce sampling-rate dependence.
355+ Lower values indicate smoother drawings. Penalizes sharp corners (e.g.,
356+ 90° turns) and noisy corrections. Normalized by arc length to reduce
357+ sampling-rate dependence.
363358 """
364359 if len (self .ink_points ) < 3 :
365360 return 0.0
@@ -398,71 +393,58 @@ def calculate_smoothness(self) -> None:
398393 def compute_segment_metrics (
399394 self , circles : dict [str , dict [str , CircleTarget ]], trail_id : str
400395 ) -> None :
401- """Compute metrics for a line segment (excluding think time which is calculated separately) .
396+ """Compute all metrics for a line segment.
402397
403- Args:
404- circles: Dictionary of circle targets keyed by trail ID
405- trail_id: Trail identifier for circle lookup
398+ This function computes various metrics for the line segment, including ink time,
399+ velocity metrics, path optimality, smoothness, and hesitation detection. It
400+ first determines the valid ink trajectory between the start and end circles. If
401+ a valid trajectory is found, it updates the ink_points attribute and calculates
402+ the metrics.
406403
407- Returns:
408- LineSegment with computed metrics
404+ Args:
405+ circles: A dictionary mapping each trail type to dictionaries of
406+ CircleTarget instances (output of load_scaled_circles in config).
407+ trail_id: Trail identifier for circle lookup.
409408 """
410409 circles = circles [trail_id ]
411410 points = self .points .copy ()
412411
413412 if len (points ) < 2 :
414- return self
413+ return
415414
416415 if self .start_label not in circles or self .end_label not in circles :
417- return self
416+ return
418417
419418 start_circle = circles [self .start_label ]
420419 end_circle = circles [self .end_label ]
421420
422- points = points .reset_index (drop = True )
423-
424- # NOTE: Think time is now calculated separately using consecutive segments
425- # This method only handles ink time and movement metrics
426-
427- ink_start_idx , ink_end_idx = self .valid_ink_trajectory (
428- points , start_circle , end_circle
429- )
421+ ink_start_idx , ink_end_idx = self .valid_ink_trajectory (start_circle , end_circle )
430422
431423 if (
432424 ink_start_idx is not None
433425 and ink_end_idx is not None
434426 and ink_end_idx > ink_start_idx
435427 ):
436- ink_points = points .iloc [ink_start_idx : ink_end_idx + 1 ].copy ()
428+ self . ink_points = self . points .iloc [ink_start_idx : ink_end_idx + 1 ].copy ()
437429
438- if len (ink_points ) >= 2 :
439- ink_start = ink_points .iloc [0 ]["seconds" ]
440- ink_end = ink_points .iloc [- 1 ]["seconds" ]
430+ if len (self . ink_points ) >= 2 :
431+ ink_start = self . ink_points .iloc [0 ]["seconds" ]
432+ ink_end = self . ink_points .iloc [- 1 ]["seconds" ]
441433 self .ink_time = ink_end - ink_start
442434
443- # NOTE: Unsure if we are going to resample or not
444- # # Resample to 60Hz if duration is sufficient
445- # if self.ink_time > 0.05: # Only resample if duration > 50ms
446- # ink_points = resample_to_60hz(ink_points, ink_start, ink_end)
447-
448- # Calculate velocities and speeds
449435 self .calculate_velocity_metrics ()
450436
451- # Calculate path optimality
452437 self .calculate_path_optimality (start_circle , end_circle )
453- # Smoothness (based on curvature changes)
454- if len (ink_points ) >= 3 :
455- self .calculate_smoothness ()
456438
457- # Hesitation detection
439+ self .calculate_smoothness ()
440+
458441 self .detect_hesitations ()
459442
460443 elif ink_start_idx is not None :
461- # Line started but never reached destination - use all remaining points
462- ink_points = points .iloc [ink_start_idx :].copy ()
463- if len (ink_points ) >= 2 :
444+ self .ink_points = points .iloc [ink_start_idx :].copy ()
445+ if len (self .ink_points ) >= 2 :
464446 self .ink_time = (
465- ink_points .iloc [- 1 ]["seconds" ] - ink_points .iloc [0 ]["seconds" ]
447+ self .ink_points .iloc [- 1 ]["seconds" ]
448+ - self .ink_points .iloc [0 ]["seconds" ]
466449 )
467-
468450 return
0 commit comments