Pass delta; fix coeffs calculation (#716)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user