Skip to content

Commit 8711436

Browse files
Use better variable names
1 parent f283b73 commit 8711436

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/ServiceControl.Audit.Persistence.RavenDB/CustomChecks/CheckDirtyMemory.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,31 @@ static TrendDirection AnalyzeTrendUsingRegression(List<int> values)
6464
}
6565

6666
// Calculate slope using linear regression
67-
double n = values.Count;
68-
double sumX = 0;
69-
double sumY = 0;
70-
double sumXY = 0;
71-
double sumXX = 0;
67+
double numberOfPoints = values.Count;
68+
double sumOfIndices = 0;
69+
double sumOfValues = 0;
70+
double sumOfIndicesMultipliedByValues = 0;
71+
double sumOfIndicesSquared = 0;
7272

7373
for (int i = 0; i < values.Count; i++)
7474
{
75-
double x = i;
76-
double y = values[i];
75+
double index = i;
76+
double value = values[i];
7777

78-
sumX += x;
79-
sumY += y;
80-
sumXY += x * y;
81-
sumXX += x * x;
78+
sumOfIndices += index;
79+
sumOfValues += value;
80+
sumOfIndicesMultipliedByValues += index * value;
81+
sumOfIndicesSquared += index * index;
8282
}
8383

84-
double slope = ((n * sumXY) - (sumX * sumY)) / ((n * sumXX) - (sumX * sumX));
84+
// Slope formula: (n*Σxy - Σx*Σy) / (n*Σx² - (Σx)²)
85+
double slopeNumerator = (numberOfPoints * sumOfIndicesMultipliedByValues) - (sumOfIndices * sumOfValues);
86+
double slopeDenominator = (numberOfPoints * sumOfIndicesSquared) - (sumOfIndices * sumOfIndices);
87+
double slope = slopeNumerator / slopeDenominator;
8588

8689
// Determine trend based on slope
87-
if (Math.Abs(slope) < 0.001) // Small threshold to handle floating-point precision
90+
const double slopeThreshold = 0.001; // Small threshold to handle floating-point precision
91+
if (Math.Abs(slope) < slopeThreshold)
8892
{
8993
return TrendDirection.Flat;
9094
}

0 commit comments

Comments
 (0)