Filter walkers by distance and average rating, ensuring a minimum of 10 walkers displayed
This commit is contained in:
parent
9ee1164161
commit
69c293b7a7
@ -549,15 +549,33 @@ namespace gehGassiApp.ViewModels
|
|||||||
request.Distance = Location.CalculateDistance(CurrentLocation.Lat.Value, CurrentLocation.Lng.Value, request.Lat, request.Lng, DistanceUnits.Kilometers);
|
request.Distance = Location.CalculateDistance(CurrentLocation.Lat.Value, CurrentLocation.Lng.Value, request.Lat, request.Lng, DistanceUnits.Kilometers);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sortierung: Entfernung, dann mit Foto, dann mit Rating
|
// Maximale Entfernung in Kilometern
|
||||||
Walkers = requests.Value
|
const double maxDistanceKm = 2.0;
|
||||||
.OrderBy(x => x.Distance)
|
const int minWalkersCount = 10;
|
||||||
|
|
||||||
|
// Filtern nach Entfernung (max 2km), dann Sortierung: Bewertung, dann mit Foto, dann Entfernung
|
||||||
|
var filteredWalkers = requests.Value
|
||||||
|
.Where(x => x.Distance <= maxDistanceKm)
|
||||||
|
.OrderByDescending(x => x.AverageRating)
|
||||||
.ThenByDescending(x => !string.IsNullOrWhiteSpace(x.Photo))
|
.ThenByDescending(x => !string.IsNullOrWhiteSpace(x.Photo))
|
||||||
.ThenByDescending(x => x.AverageRating > 0)
|
.ThenBy(x => x.Distance)
|
||||||
.ToObservableCollection();
|
.ToList();
|
||||||
|
|
||||||
|
// Falls weniger als 10 Walker in der 1km-Zone, weitere nach Entfernung hinzufügen
|
||||||
|
if (filteredWalkers.Count < minWalkersCount)
|
||||||
|
{
|
||||||
|
var additionalWalkers = requests.Value
|
||||||
|
.Where(x => x.Distance > maxDistanceKm)
|
||||||
|
.OrderBy(x => x.Distance)
|
||||||
|
.Take(minWalkersCount - filteredWalkers.Count);
|
||||||
|
|
||||||
|
filteredWalkers.AddRange(additionalWalkers);
|
||||||
|
}
|
||||||
|
|
||||||
|
Walkers = filteredWalkers.ToObservableCollection();
|
||||||
|
|
||||||
// Set First10Walkers for the home screen display
|
// Set First10Walkers for the home screen display
|
||||||
First10Walkers = requests.Value.Take(10).ToObservableCollection();
|
First10Walkers = filteredWalkers.Take(10).ToObservableCollection();
|
||||||
|
|
||||||
_total = requests.Total;
|
_total = requests.Total;
|
||||||
_skip = requests.Skip + requests.Take;
|
_skip = requests.Skip + requests.Take;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user