Clarify Best Value route confidence

This commit is contained in:
FuelBoard Contributor
2026-10-13 10:30:41 +01:00
parent d8a85b7aa0
commit 9aa8a2ede1
10 changed files with 338 additions and 46 deletions
+35
View File
@@ -1343,6 +1343,29 @@ struct FuelStore {
roadDistanceEntry(for: station, userLat: userLat, userLng: userLng) != nil
}
/// True only for current-format route cache entries with a separately
/// measured return route. Legacy one-way entries are still usable for journey
/// arithmetic (`outward × 2`) but Best Value must describe them as estimated.
static func hasMeasuredReturnRoadDistance(for station: FuelStation, userLat: Double, userLng: Double) -> Bool {
roadDistanceEntry(for: station, userLat: userLat, userLng: userLng)?.returnMeters != nil
}
static func roadDistanceDiagnostics(for station: FuelStation, userLat: Double, userLng: Double) -> RoadDistanceDiagnostics {
let displayKM = displayDistanceKM(station: station, userLat: userLat, userLng: userLng)
let entry = roadDistanceEntry(for: station, userLat: userLat, userLng: userLng)
let outward = entry?.meters
let returnMeters = entry?.returnMeters
return RoadDistanceDiagnostics(
displayDistanceKM: displayKM,
displaySource: outward == nil ? .straightLine : .roadRoute,
outwardMeters: outward,
returnMeters: returnMeters,
totalJourneyMeters: outward.map { $0 + (returnMeters ?? $0) },
hasMeasuredReturn: returnMeters != nil,
hasValidCacheEntry: entry != nil
)
}
private static func roadDistanceEntry(for station: FuelStation, userLat: Double, userLng: Double) -> CachedRoadDistance? {
guard let cache = loadRoadDistances(),
let entry = cache.entries[station.id] else { return nil }
@@ -1432,6 +1455,18 @@ struct FuelStore {
}
}
/// Lightweight description of the distance value shown for a station and any
/// usable road-route cache behind it. No user coordinates are included.
struct RoadDistanceDiagnostics: Equatable {
let displayDistanceKM: Double
let displaySource: FuelSavingsDistanceBasis
let outwardMeters: Double?
let returnMeters: Double?
let totalJourneyMeters: Double?
let hasMeasuredReturn: Bool
let hasValidCacheEntry: Bool
}
/// Cached Apple-Maps road distances for nearby stations (see
/// A single cached road distance plus the station pin it was routed to. Keeping
/// the pin lets `roadDistanceMeters` refuse to serve a route computed for a