Skip to content

Commit

Permalink
fine tuning of color markings #28
Browse files Browse the repository at this point in the history
  • Loading branch information
Marrrrtthias committed Sep 13, 2022
1 parent e0369ef commit d3096f1
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions station/lib/usecase/get_stations_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class GetStationsUseCaseImpl extends GetStationsUseCase {
@override
Future<List<StationModel>> invoke(
String type, CoordinateModel position) async {
StationPricesModel minPrices = await _fetchMinPrices(type, position);
List<StationPricesModel> minMaxPrices = await _fetchMinMaxPrices(type, position);
StationPricesModel minPrices = minMaxPrices[0];
StationPricesModel maxPrices = minMaxPrices[1];

return _stationRepository.list(type, position, 15).then((stations) {
return stations
Expand All @@ -27,11 +29,13 @@ class GetStationsUseCaseImpl extends GetStationsUseCase {
station.address,
StationPricesModel(
station.prices.e5,
_getPriceRange(minPrices.e5, station.prices.e5),
_getPriceRange(minPrices.e5, maxPrices.e5, station.prices.e5),
station.prices.e10,
_getPriceRange(minPrices.e10, station.prices.e10),
_getPriceRange(
minPrices.e10, maxPrices.e10, station.prices.e10),
station.prices.diesel,
_getPriceRange(minPrices.diesel, station.prices.diesel),
_getPriceRange(
minPrices.diesel, maxPrices.diesel, station.prices.diesel),
),
station.coordinate,
station.openTimes,
Expand All @@ -40,7 +44,7 @@ class GetStationsUseCaseImpl extends GetStationsUseCase {
});
}

Future<StationPricesModel> _fetchMinPrices(
Future<List<StationPricesModel>> _fetchMinMaxPrices(
String type, CoordinateModel position) {
return _stationRepository.list(type, position, 25).then((stations) {
Iterable<double> e5Prices =
Expand All @@ -52,24 +56,34 @@ class GetStationsUseCaseImpl extends GetStationsUseCase {
Iterable<double> dieselPrices =
stations.map((s) => s.prices.diesel).where((p) => p != 0.0);

return StationPricesModel(
e5Prices.isNotEmpty ? e5Prices.reduce(min) : 0,
StationPriceRange.unknown,
e10Prices.isNotEmpty ? e10Prices.reduce(min) : 0,
StationPriceRange.unknown,
dieselPrices.isNotEmpty ? dieselPrices.reduce(min) : 0,
StationPriceRange.unknown);
return [
StationPricesModel(
e5Prices.isNotEmpty ? e5Prices.reduce(min) : 0,
StationPriceRange.unknown,
e10Prices.isNotEmpty ? e10Prices.reduce(min) : 0,
StationPriceRange.unknown,
dieselPrices.isNotEmpty ? dieselPrices.reduce(min) : 0,
StationPriceRange.unknown),
StationPricesModel(
e5Prices.isNotEmpty ? e5Prices.reduce(max) : 0,
StationPriceRange.unknown,
e10Prices.isNotEmpty ? e10Prices.reduce(max) : 0,
StationPriceRange.unknown,
dieselPrices.isNotEmpty ? dieselPrices.reduce(max) : 0,
StationPriceRange.unknown),
];
});
}

StationPriceRange _getPriceRange(double minPrice, double price) {
StationPriceRange _getPriceRange(
double minPrice, double maxPrice, double price) {
if (price == 0.0) {
return StationPriceRange.unknown;
}

if (minPrice + 0.04 >= price) {
if (minPrice + ((maxPrice - minPrice) * .1) >= price) {
return StationPriceRange.cheap;
} else if (minPrice + 0.10 >= price) {
} else if (minPrice + ((maxPrice - minPrice) * .5) >= price) {
return StationPriceRange.normal;
} else {
return StationPriceRange.expensive;
Expand Down

0 comments on commit d3096f1

Please sign in to comment.