Skip to content

Commit 9648b08

Browse files
committed
feat: add missing run comparison percentage
1 parent e329d60 commit 9648b08

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

MHFZ_Overlay/Views/Windows/ConfigWindow.xaml.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,31 @@ private double CalculateBetterLinePercentage(Dictionary<int, int> line1, Diction
24252425
}
24262426
}
24272427

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+
24282453
private double CalculateAreaUnderLine(Dictionary<int, int> line, int cutoffTime)
24292454
{
24302455
// Assuming the line is sorted by time.
@@ -2453,6 +2478,34 @@ private double CalculateAreaUnderLine(Dictionary<int, int> line, int cutoffTime)
24532478
return area;
24542479
}
24552480

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+
24562509
private void SetLineSeriesForDictionaryIntDouble(Dictionary<int, double> data, Dictionary<int, double>? extraData)
24572510
{
24582511
if (this.graphChart == null)
@@ -2498,6 +2551,13 @@ private void SetLineSeriesForDictionaryIntDouble(Dictionary<int, double> data, D
24982551
Stroke = new SolidColorPaint(new SKColor(this.MainWindow.DataLoader.Model.HexColorToDecimal("#ff89b4fa"))) { StrokeThickness = 2 },
24992552
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)),
25002553
});
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+
}
25012561
}
25022562

25032563
this.XAxes = new Axis[]
@@ -2717,6 +2777,13 @@ private void SetHitsTakenBlocked(Dictionary<int, Dictionary<int, int>> data, Dic
27172777
Stroke = new SolidColorPaint(new SKColor(this.MainWindow.DataLoader.Model.HexColorToDecimal("#ff89b4fa"))) { StrokeThickness = 2 },
27182778
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)),
27192779
});
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+
}
27202787
}
27212788

27222789
this.XAxes = new Axis[]

0 commit comments

Comments
 (0)