v1.19: fix empty usage-history chart (always fetch utilization)
Build APK / build (push) Successful in 1m52s
Build APK / build (push) Successful in 1m52s
recordHistory() only ever stored fiveHourUtilization/weeklyUtilization, but fetchUsage() returned early with message-count data — before calling the /usage utilization endpoint — whenever the org JSON carried a message limit. So utilization was never populated and the history chart stayed stuck on 'Collecting history…'. The prior chart fix only corrected the throttle. - UsageRepository: always attempt /usage (preferred signal that drives the weekly bar + history); fall back to org message-count data only when utilization is unavailable. - UsageData.sessionReadingPct: utilization preferred, message-count % fallback, -1f when no reading — so message-only accounts also build history. - PreferencesManager.recordHistory: record the session line from sessionReadingPct instead of utilization-only. - UsageDataTest: cover sessionReadingPct.
This commit is contained in:
@@ -95,6 +95,32 @@ class UsageDataTest {
|
||||
assertFalse(UsageData().hasAnyReading)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun sessionReadingPctPrefersUtilization() {
|
||||
// Utilization present → used verbatim (kept as Float, not truncated), even alongside messages.
|
||||
val d = UsageData(fiveHourUtilization = 42.5f, messagesUsed = 10, messagesLimit = 100)
|
||||
assertEquals(42.5f, d.sessionReadingPct, 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun sessionReadingPctFallsBackToMessages() {
|
||||
// No utilization → derive from message counts so message-only accounts still get history.
|
||||
val d = UsageData(messagesUsed = 30, messagesLimit = 120)
|
||||
assertEquals(25f, d.sessionReadingPct, 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun sessionReadingPctMessagesCoercedTo100() {
|
||||
val d = UsageData(messagesUsed = 150, messagesLimit = 100)
|
||||
assertEquals(100f, d.sessionReadingPct, 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun sessionReadingPctNegativeWhenNoReading() {
|
||||
// No utilization and no message data → -1f, so recordHistory skips the point.
|
||||
assertEquals(-1f, UsageData().sessionReadingPct, 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mergedWithEmptyFetchKeepsPreviousMetrics() {
|
||||
// (a) previous has a reading; this fetch is empty (all defaults) → previous metrics kept.
|
||||
|
||||
Reference in New Issue
Block a user