Sort every fuel tab cheapest-first (distance only as tiebreaker) in app + widget
This commit is contained in:
@@ -91,9 +91,12 @@ struct FuelPriceTimelineProvider: TimelineProvider {
|
||||
let sorted: [FuelStation]
|
||||
if let location {
|
||||
sorted = filtered.sorted { lhs, rhs in
|
||||
let lScore = lhs.distanceKM(to: location.lat, lng2: location.lng) * 0.4 + lhs.prices[fuel]! * 0.001
|
||||
let rScore = rhs.distanceKM(to: location.lat, lng2: location.lng) * 0.4 + rhs.prices[fuel]! * 0.001
|
||||
return lScore < rScore
|
||||
// Cheapest first; distance only breaks ties.
|
||||
let lPrice = lhs.prices[fuel]!
|
||||
let rPrice = rhs.prices[fuel]!
|
||||
if lPrice != rPrice { return lPrice < rPrice }
|
||||
return lhs.distanceKM(to: location.lat, lng2: location.lng) <
|
||||
rhs.distanceKM(to: location.lat, lng2: location.lng)
|
||||
}
|
||||
} else {
|
||||
sorted = filtered.sorted { $0.prices[fuel]! < $1.prices[fuel]! }
|
||||
|
||||
Reference in New Issue
Block a user