@@ -2425,6 +2425,31 @@ private double CalculateBetterLinePercentage(Dictionary<int, int> line1, Diction
2425
2425
}
2426
2426
}
2427
2427
2428
+ private double CalculateBetterLinePercentage ( Dictionary < int , double > line1 , Dictionary < int , double > line2 )
2429
+ {
2430
+ if ( line1 . Count == 0 || line2 . Count == 0 )
2431
+ return 0.0 ;
2432
+ // Find the cutoff time where the first series ends.
2433
+ int cutoffTime = Math . Min ( line1 . Keys . Max ( ) , line2 . Keys . Max ( ) ) ;
2434
+
2435
+ // Calculate the area under each line series up to the cutoff time.
2436
+ double area1 = CalculateAreaUnderLine ( line1 , cutoffTime ) ;
2437
+ double area2 = CalculateAreaUnderLine ( line2 , cutoffTime ) ;
2438
+
2439
+ // Determine which series has the larger area and calculate the percentage difference.
2440
+ if ( area1 == area2 )
2441
+ {
2442
+ return 0 ; // Both series are equal.
2443
+ }
2444
+ else
2445
+ {
2446
+ double largerArea = Math . Max ( area1 , area2 ) ;
2447
+ double smallerArea = Math . Min ( area1 , area2 ) ;
2448
+ double percentageDifference = ( ( largerArea - smallerArea ) / smallerArea ) * 100 ;
2449
+ return area1 > area2 ? percentageDifference : - percentageDifference ;
2450
+ }
2451
+ }
2452
+
2428
2453
private double CalculateAreaUnderLine ( Dictionary < int , int > line , int cutoffTime )
2429
2454
{
2430
2455
// Assuming the line is sorted by time.
@@ -2453,6 +2478,34 @@ private double CalculateAreaUnderLine(Dictionary<int, int> line, int cutoffTime)
2453
2478
return area ;
2454
2479
}
2455
2480
2481
+ private double CalculateAreaUnderLine ( Dictionary < int , double > line , int cutoffTime )
2482
+ {
2483
+ // Assuming the line is sorted by time.
2484
+ double area = 0 ;
2485
+ int previousTime = 0 ;
2486
+ double previousScore = 0.0 ;
2487
+
2488
+ foreach ( var point in line . OrderBy ( p => p . Key ) )
2489
+ {
2490
+ if ( point . Key > cutoffTime )
2491
+ break ;
2492
+
2493
+ if ( previousTime != 0 )
2494
+ {
2495
+ // Calculate the area of the trapezoid.
2496
+ double base1 = point . Value ;
2497
+ double base2 = previousScore ;
2498
+ double height = point . Key - previousTime ;
2499
+ area += ( base1 + base2 ) * height / 2 ;
2500
+ }
2501
+
2502
+ previousTime = point . Key ;
2503
+ previousScore = point . Value ;
2504
+ }
2505
+
2506
+ return area ;
2507
+ }
2508
+
2456
2509
private void SetLineSeriesForDictionaryIntDouble ( Dictionary < int , double > data , Dictionary < int , double > ? extraData )
2457
2510
{
2458
2511
if ( this . graphChart == null )
@@ -2498,6 +2551,13 @@ private void SetLineSeriesForDictionaryIntDouble(Dictionary<int, double> data, D
2498
2551
Stroke = new SolidColorPaint ( new SKColor ( this . MainWindow . DataLoader . Model . HexColorToDecimal ( "#ff89b4fa" ) ) ) { StrokeThickness = 2 } ,
2499
2552
Fill = new LinearGradientPaint ( new SKColor ( this . MainWindow . DataLoader . Model . HexColorToDecimal ( "#ff89b4fa" , "7f" ) ) , new SKColor ( this . MainWindow . DataLoader . Model . HexColorToDecimal ( "#ff89b4fa" , "00" ) ) , new SKPoint ( 0.5f , 0 ) , new SKPoint ( 0.5f , 1 ) ) ,
2500
2553
} ) ;
2554
+
2555
+ if ( this . runIDComparisonTextBlock != null && this . extraRunIDTextBox != null )
2556
+ {
2557
+ var runComparisonPercentage = CalculateBetterLinePercentage ( newData , newData2 ) ;
2558
+ var betterRun = runComparisonPercentage >= 0.0 ? RunIDTextBox . Text : extraRunIDTextBox . Text ;
2559
+ this . runIDComparisonTextBlock . Text = string . Format ( CultureInfo . InvariantCulture , "Run {0} is higher by around {1:0.##}%" , betterRun , Math . Abs ( runComparisonPercentage ) ) ;
2560
+ }
2501
2561
}
2502
2562
2503
2563
this . XAxes = new Axis [ ]
@@ -2717,6 +2777,13 @@ private void SetHitsTakenBlocked(Dictionary<int, Dictionary<int, int>> data, Dic
2717
2777
Stroke = new SolidColorPaint ( new SKColor ( this . MainWindow . DataLoader . Model . HexColorToDecimal ( "#ff89b4fa" ) ) ) { StrokeThickness = 2 } ,
2718
2778
Fill = new LinearGradientPaint ( new SKColor ( this . MainWindow . DataLoader . Model . HexColorToDecimal ( "#ff89b4fa" , "7f" ) ) , new SKColor ( this . MainWindow . DataLoader . Model . HexColorToDecimal ( "#ff89b4fa" , "00" ) ) , new SKPoint ( 0.5f , 0 ) , new SKPoint ( 0.5f , 1 ) ) ,
2719
2779
} ) ;
2780
+
2781
+ if ( this . runIDComparisonTextBlock != null && this . extraRunIDTextBox != null )
2782
+ {
2783
+ var runComparisonPercentage = CalculateBetterLinePercentage ( newData , newData2 ) ;
2784
+ var betterRun = runComparisonPercentage >= 0.0 ? RunIDTextBox . Text : extraRunIDTextBox . Text ;
2785
+ this . runIDComparisonTextBlock . Text = string . Format ( CultureInfo . InvariantCulture , "Run {0} is higher by around {1:0.##}%" , betterRun , Math . Abs ( runComparisonPercentage ) ) ;
2786
+ }
2720
2787
}
2721
2788
2722
2789
this . XAxes = new Axis [ ]
0 commit comments