Skip to content

Commit b0f8480

Browse files
committed
fix(tokens): update LTTP downsampling to handle smaller gaps/periods
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent b444fbd commit b0f8480

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

apps/flipcash/shared/tokens/src/main/kotlin/data/AggregationType.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,16 @@ sealed interface AggregationType {
6060

6161
// Find the first real data point (non-zero timestamp)
6262
// Instead of checking for x == 0, check if there's a gap at the start
63-
val firstRealPoint = sorted.firstOrNull { it.x >= startTime && it.y > 0.0 }
64-
?: sorted.firstOrNull { it.x > 0 }
63+
val firstRealPoint = sorted.firstOrNull { it.x > 0 }
6564

66-
// Build the effective point list: if data starts after startTime,
67-
// anchor zeros from startTime up to the first real point
68-
val effective = if (firstRealPoint != null && firstRealPoint.x > startTime) {
65+
val duration = now - startTime
66+
val gapThreshold = duration * 0.05 // 5% of the period
67+
68+
val effective = if (
69+
firstRealPoint != null &&
70+
firstRealPoint.x > startTime &&
71+
(firstRealPoint.x - startTime) > gapThreshold
72+
) {
6973
val zeroAnchors = listOf(
7074
MarketCapPoint(x = startTime, y = 0.0),
7175
MarketCapPoint(x = firstRealPoint.x - 1, y = 0.0),
@@ -87,7 +91,6 @@ sealed interface AggregationType {
8791
}
8892

8993
// Interpolate to evenly-spaced timestamps
90-
val duration = now - startTime
9194
val intervalMs = (duration / targetPoints).coerceAtLeast(1)
9295

9396
return (0 until targetPoints).map { bucket ->

0 commit comments

Comments
 (0)