mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-10-25 23:57:05 +01:00
fix: sort the AP column numerically instead of by its text (#87)
The "AP [minutes / pot%]" column of the station list and of the directed
messages had no comparator, so DataTableState fell back to the rendered
text and "13 (75%)" sorted above "3 (50%)".
AirplaneCell now owns a shared comparator, AirplaneCell.order, that both
column definitions use. The sort key is the first aeroplane of the cell,
which is the one the operator reads and the one the colour marks:
ascending by its arriving minutes, then by the better potential first for
equal minutes. A null info (nothing computed) and an empty list ("nil")
carry Int.MAX_VALUE, so they sort after every real aeroplane in ascending
order, consistent with the qrb and qtf sentinels. The second aeroplane of
a cell does not influence the order. Cell text, colours, column ids,
titles and weights are unchanged, as are DataTableState and the sort
cycle.
Fixes #87
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
456957808d
commit
ab28216280
8 files changed
+150
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package kst4contest.view.compose
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import kst4contest.model.AirPlane
|
||||
import kst4contest.model.AirPlaneReflectionInfo
|
||||
|
||||
/**
|
||||
@@ -34,6 +35,27 @@ object AirplaneCell {
|
||||
*/
|
||||
private const val NOTHING_COMING = "nil"
|
||||
|
||||
// ---- the order ----------------------------------------------------------
|
||||
|
||||
/** Unknown or no aeroplane sorts after every real one. */
|
||||
private const val NO_PLANE = Int.MAX_VALUE
|
||||
|
||||
/** The aeroplane the cell shows first; the parser already put the best one there. */
|
||||
private fun first(info: AirPlaneReflectionInfo?): AirPlane? = info?.risingAirplanes?.firstOrNull()
|
||||
|
||||
/**
|
||||
* Ascending: the minutes the operator reads first, then the better potential first.
|
||||
*
|
||||
* Issue #87: without a comparator the table fell back to the rendered text, which put
|
||||
* "13 (75%)" above "3 (50%)". Only the first aeroplane counts, as it is the one the
|
||||
* operator reads and the one the colour marks; the second is in the cell for context.
|
||||
* Empty and "nil" cells carry [NO_PLANE]: like qrb and qtf, an absent value gets a
|
||||
* sentinel instead of a null check, here the maximum so the cell sorts last ascending.
|
||||
*/
|
||||
val order: Comparator<AirPlaneReflectionInfo?> =
|
||||
compareBy<AirPlaneReflectionInfo?> { first(it)?.arrivingDurationMinutes ?: NO_PLANE }
|
||||
.thenByDescending { first(it)?.potential ?: 0 }
|
||||
|
||||
/** `.table-cell-100PercentAP`, identical in both stylesheets: a certain path. */
|
||||
val PURPLE_100 = Color(0xFFF98AFF)
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ object DirectedMessageColumns {
|
||||
title = "AP [minutes / pot%]",
|
||||
value = { AirplaneCell.format(it.sender?.airPlaneReflectInfo) },
|
||||
accent = { _, rendered -> AirplaneCell.accentFor(rendered) },
|
||||
comparator = compareBy(AirplaneCell.order) { it.sender?.airPlaneReflectInfo },
|
||||
weight = 1.4f,
|
||||
),
|
||||
DataColumn(
|
||||
|
||||
@@ -55,6 +55,7 @@ object StationColumns {
|
||||
title = "AP [minutes / pot%]",
|
||||
value = { AirplaneCell.format(it.airPlaneReflectInfo) },
|
||||
accent = { _, rendered -> AirplaneCell.accentFor(rendered) },
|
||||
comparator = compareBy(AirplaneCell.order) { it.airPlaneReflectInfo },
|
||||
weight = 1.4f,
|
||||
))
|
||||
add(DataColumn(id = "tropo", title = "Tropo", value = tropoOf, weight = 0.7f))
|
||||
|
||||
Reference in new issue
Block a user