Make station price age informational only
The relay's price_updated is the maximum price_last_updated across the grades it maps, so it cannot vouch for the selected grade: stop using it to score, gate or warn about Best Value. - FuelPriceFreshness is now station-level and display-only: one age per station, fresh/outdated/unknown/invalid, "May be outdated" past 30 days, with future-tolerance and non-finite guards. - Best Value restores the closest-station-selling-the-selected-fuel baseline and its savings ranking; eligibility gating, eligible-first sorting and the unavailable banner are gone. - Price age appears in the More info sheet only - no listing-row warnings, no extra banners. - Copy reverted from "closest eligible station" to "closest station"; stale price-confidence strings removed, "May be outdated" added. - Dormant per-grade timestamp plumbing removed, and regression tests added for every fuel type, missing/invalid/future stamps and the bundled offline dump.
This commit is contained in:
@@ -38,9 +38,7 @@ enum FuelPriceProvider {
|
||||
lat: relay.lat ?? 0,
|
||||
lng: relay.lng ?? 0,
|
||||
prices: relay.allPrices,
|
||||
priceUpdated: relay.priceUpdatedDate?.timeIntervalSince1970,
|
||||
priceUpdatedByFuel: relay.priceUpdatedByFuel,
|
||||
priceUpdatedByFuelRaw: relay.priceUpdatedByFuelRaw
|
||||
priceUpdated: relay.priceUpdatedDate?.timeIntervalSince1970
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -118,41 +116,16 @@ private struct MirrorResponse: Codable {
|
||||
let price: Double?
|
||||
let prices: [String: Double]?
|
||||
let priceUpdated: String?
|
||||
let priceUpdatedByGrade: [String: String]?
|
||||
let priceUpdatedByFuelRawValues: [String: String]?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id, name, brand, address, postcode, lat, lng, price, prices
|
||||
case priceUpdated = "price_updated"
|
||||
case priceUpdatedByGrade = "price_updated_by_grade"
|
||||
case priceUpdatedByFuelRawValues = "price_updated_by_fuel"
|
||||
}
|
||||
|
||||
var priceUpdatedDate: Date? {
|
||||
FuelPriceTimestamp.parse(priceUpdated)
|
||||
}
|
||||
|
||||
var priceUpdatedByFuelRaw: [FuelType: String]? {
|
||||
let raw = priceUpdatedByGrade ?? priceUpdatedByFuelRawValues
|
||||
guard let raw else { return nil }
|
||||
let parsed = raw.reduce(into: [FuelType: String]()) { result, item in
|
||||
guard let fuel = FuelPriceProvider.fuelType(for: item.key) else { return }
|
||||
result[fuel] = item.value
|
||||
}
|
||||
return parsed.isEmpty ? nil : parsed
|
||||
}
|
||||
|
||||
var priceUpdatedByFuel: [FuelType: TimeInterval]? {
|
||||
let raw = priceUpdatedByGrade ?? priceUpdatedByFuelRawValues
|
||||
guard let raw else { return nil }
|
||||
let parsed = raw.reduce(into: [FuelType: TimeInterval]()) { result, item in
|
||||
guard let fuel = FuelPriceProvider.fuelType(for: item.key),
|
||||
let date = FuelPriceTimestamp.parse(item.value) else { return }
|
||||
result[fuel] = date.timeIntervalSince1970
|
||||
}
|
||||
return parsed.isEmpty ? nil : parsed
|
||||
}
|
||||
|
||||
/// Map mirror grade keys (E5/E10/DIESEL) to FuelType for ALL fuels the
|
||||
/// station sells — one fetch populates every fuel tab. Defensive guard:
|
||||
/// any grade outside the 50–500 pence/litre band is dropped, so a mirror
|
||||
|
||||
Reference in New Issue
Block a user