aggregate method

Combines this record with another visit of the same screen.

Implementation

ScreenPerformanceData aggregate(ScreenPerformanceData other) {
  final aggregated = ScreenPerformanceData(screenName);
  aggregated.totalFrames = totalFrames + other.totalFrames;
  aggregated.droppedFrames = droppedFrames + other.droppedFrames;
  aggregated.peakMemoryMb = max(peakMemoryMb, other.peakMemoryMb);
  aggregated.visitCount = visitCount + other.visitCount;
  aggregated._accumulatedDuration = duration + other.duration;

  // For sorting/display, use the latest end time
  aggregated.endTime = (endTime != null && other.endTime != null)
      ? (endTime!.isAfter(other.endTime!) ? endTime : other.endTime)
      : (endTime ?? other.endTime);
  return aggregated;
}