Pass delta; fix coeffs calculation (#716)

This commit is contained in:
KirillPamPam
2025-08-28 18:02:58 +04:00
committed by GitHub
parent b3d8d39552
commit 0ec7e4fd70
4 changed files with 53 additions and 5 deletions

View File

@@ -109,6 +109,7 @@ class Selector {
it.lowerHeightSelector.height,
it.lowerHeightSelector.lowerBoundType.fromProtoType(),
it.lowerHeightSelector.timeOffset,
it.lowerHeightSelector.heightDelta,
)
} else {
empty
@@ -571,10 +572,11 @@ class Selector {
private val lowerHeight: Long,
private val boundType: LowerBoundType,
private val timeOffsetSeconds: Long = 0,
private val delta: Long = 0,
) : Matcher() {
override fun matchesWithCause(up: Upstream): MatchesResponse {
val predictedLowerBound = up.predictLowerBound(boundType, timeOffsetSeconds)
return if (lowerHeight >= predictedLowerBound && predictedLowerBound != 0L) {
return if (lowerHeight >= (predictedLowerBound - delta) && predictedLowerBound != 0L) {
Success
} else {
LowerHeightResponse(lowerHeight, predictedLowerBound, boundType)

View File

@@ -75,6 +75,12 @@ class LowerBounds(
return (lowerBoundCoeffs.k.get() * xTime + lowerBoundCoeffs.b.get()).roundToLong()
}
fun predictNextBoundAtSpecificTime(type: LowerBoundType, timestamp: Long): Long {
val lowerBoundCoeffs = lowerBounds[type] ?: return 0
return (lowerBoundCoeffs.k.get() * timestamp + lowerBoundCoeffs.b.get()).roundToLong()
}
fun getLastBound(type: LowerBoundType): LowerBoundData? {
return lowerBounds[type]?.getLastBound()
}
@@ -124,7 +130,8 @@ class LowerBounds(
regression.addObservation(doubleArrayOf(it.timestamp.toDouble()), it.lowerBound.toDouble())
}
updateCoeffs(regression.slope, regression.intercept)
// we want our line to go through the last point in terms of the function k(y-y(t))+b
updateCoeffs(regression.slope, lowerBounds.last.lowerBound.toDouble() - regression.slope * lowerBounds.last.timestamp)
}
}
}