fix(amsat): render only the days the API actually returned
The status grid always drew six day columns, but the AMSAT reports endpoint cannot supply six days for the full catalogue. Measured against the live API: limit=500 -> meta.count=500, covers 4 days (Aug 11..Aug 14) limit=1000 -> meta.count=500, same 4 days (server clamps the limit) hours=336 -> meta.count=500, same 4 days (window size does not help) before/offset/page -> ignored, same 500 newest rows With ~90 catalogued satellites the 500 newest rows only reach about four days back, so the two oldest columns were guaranteed to be uniformly gray. Gray means "no report" in this UI, so the screen asserted nobody reported those days when the truth was that the data was never fetched. Derive the column count from the oldest report actually received, capped at six. On live data that yields four columns labelled Aug 14..Aug 11 instead of six with Aug 10 and Aug 9 blank. The UI already renders whatever days it is given, so no UI change is needed. Also name the request constants and record what was measured about the endpoint, so the 500 is not mistaken for an arbitrary choice that can simply be raised. Note for a future change: the per-satellite form of the endpoint (reports.php?name=...) is not affected by the cap - sampling eight satellites returned 926 rows spanning eight days, i.e. full six-day coverage - but it needs one request per satellite (~0.8 s each, ~68 s for the whole catalogue), so switching to it is a deliberate trade-off rather than a bug fix. :core:data:compileReleaseKotlin, :core:data:testDebugUnitTest and :core:domain:test all BUILD SUCCESSFUL.
This commit is contained in:
1 parent
2bac6655f3
commit
27d41eb2ee
1 file changed
+30
-3
+30
-3
@@ -35,7 +35,8 @@ class AmSatRepository(private val remoteSource: IRemoteSource) : IAmSatRepositor
|
||||
override suspend fun fetchStatus(): SatStatusPage? = withContext(Dispatchers.IO) {
|
||||
val nowSec = System.currentTimeMillis() / 1000
|
||||
val catalogJson = remoteSource.getAmSatCatalog() ?: return@withContext null
|
||||
val reportsJson = remoteSource.getAmSatReports(hours = 168, limit = 500) ?: return@withContext null
|
||||
val reportsJson = remoteSource.getAmSatReports(hours = REPORTS_HOURS, limit = REPORTS_LIMIT)
|
||||
?: return@withContext null
|
||||
|
||||
val names = parseCatalog(catalogJson)
|
||||
val reports = parseReports(reportsJson)
|
||||
@@ -98,13 +99,25 @@ class AmSatRepository(private val remoteSource: IRemoteSource) : IAmSatRepositor
|
||||
// of the 72 slots sat under the wrong date label, and at 12:00 UTC half of
|
||||
// them did, so the column headed "today" showed yesterday's reports.
|
||||
val todayStartSec = (nowSec / 86400L) * 86400L
|
||||
val labels = (0 until 6).map { d ->
|
||||
// Only show days the API actually covered. Its reports endpoint caps the
|
||||
// response at 500 rows regardless of the requested limit and fills them
|
||||
// newest-first, so with ~90 catalogued satellites the oldest days come
|
||||
// back empty. Rendering a fixed six columns turned "not fetched" into an
|
||||
// all-gray "nobody reported" column, which is a different claim.
|
||||
val oldestReportSec = reports.minOfOrNull { it.reportedTimeUtcSec }
|
||||
val coveredDays = if (oldestReportSec == null) {
|
||||
1
|
||||
} else {
|
||||
val oldestDayStart = (oldestReportSec / 86400L) * 86400L
|
||||
(((todayStartSec - oldestDayStart) / 86400L) + 1).toInt().coerceIn(1, MAX_DAYS)
|
||||
}
|
||||
val labels = (0 until coveredDays).map { d ->
|
||||
utc.timeInMillis = (todayStartSec - d * 86400L) * 1000
|
||||
"${monthAbbr[utc.get(Calendar.MONTH)]} ${utc.get(Calendar.DAY_OF_MONTH)}"
|
||||
}
|
||||
return names.map { name ->
|
||||
val reportsForSat = byName[name].orEmpty()
|
||||
val days = (0 until 6).map { d ->
|
||||
val days = (0 until coveredDays).map { d ->
|
||||
val dayStart = todayStartSec - d * 86400L
|
||||
// Newest slot first: the UI picks the first non-gray slot of a day
|
||||
// as that day's status.
|
||||
@@ -156,6 +169,20 @@ class AmSatRepository(private val remoteSource: IRemoteSource) : IAmSatRepositor
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** Longest history the status grid will render. */
|
||||
private const val MAX_DAYS = 6
|
||||
|
||||
/**
|
||||
* The reports endpoint clamps its response to 500 rows and ignores a
|
||||
* larger limit (measured: limit=1000 still answers with
|
||||
* `meta.count = 500`), so asking for more is pointless. Rows arrive
|
||||
* newest-first, which is why the oldest days can be missing entirely.
|
||||
*/
|
||||
private const val REPORTS_LIMIT = 500
|
||||
|
||||
/** Request a full week so the six rendered days have data when available. */
|
||||
private const val REPORTS_HOURS = 168
|
||||
|
||||
// AMSAT official status colors (from amsat.org/status)
|
||||
private const val ACTIVE_BLUE = 0xFF648FFF
|
||||
private const val TLM_ORANGE = 0xFFFFB000
|
||||
|
||||
Reference in new issue
Block a user