private decimal Validate(WeightVectorLabel label, decimal?value) { var criteria = DecisionCriterias.First(x => x.Position == (int)label); if (!value.HasValue) { return(criteria.ReserveLevel); } if (criteria.IsProfit) { return(GetInRange(value.Value, criteria.ReserveLevel, criteria.AspirationLevel)); } else { return(GetInRange(value.Value, criteria.AspirationLevel, criteria.ReserveLevel)); } }
public decimal GetLabelValue(WeightVectorLabel label) { return(Values[(int)label]); }
public void AddValue(WeightVectorLabel label, decimal value) { Values[(int)label] += GetInRange(value); }
public void SetPriority(WeightVectorLabel label, decimal value) { Values[(int)label] = GetInRange(value); }
public void SetValue(WeightVectorLabel label, decimal value) { DecisionValues[(int)label] = value; }
public async Task <IList <PlanElementCandidate> > GetCandidates(Plan plan, WeightVector weightVector) { var test = true; var candidates = new List <PlanElementCandidate>(); PlanElementType[] planElementTypes = new PlanElementType[] { PlanElementType.Entertainment, PlanElementType.Relax, PlanElementType.Activity, PlanElementType.Culture, PlanElementType.Sightseeing, PlanElementType.Partying, PlanElementType.Shopping, }; foreach (var planElementType in planElementTypes) { var googlePlaceTypes = GooglePlaceTypes.Table.Where(x => x.PlanElementType == planElementType).ToList(); foreach (var type in googlePlaceTypes) { var nearbySearchInput = _googlePlaceNearbySearchInputFactory.Create(plan.StartLocation, (int)MaximumDistanceToAccomodation, type); var nearbyResults = await _googlePlaceNearbySearchApiClient.GetAsync(nearbySearchInput); int counter = 1; foreach (var nr in nearbyResults.results) { var details = await _googlePlaceDetailsApiClient.GetAsync(_googlePlaceDetailsInputFactory.CreateAllUseful(nr.place_id)); if (details.IsOk) { var candidate = new PlanElementCandidate(details.Result.name, details.Result.place_id, details.Result.formatted_address, details.Result.geometry.location, details.Result.opening_hours, details.Result.types, details.Result.rating, details.Result.price_level, details.Result.user_ratings_total); if (!candidates.Any(x => x.PlaceId == candidate.PlaceId)) { candidates.Add(candidate); } } ++counter; } if (test && candidates.Count > 15) { return(candidates); } WeightVectorLabel weightVectorLabel = WeightVector.TranslateLabel(planElementType); if ((plan.PlanForm.IsOverOneWeek || weightVector.GetLabelValue(weightVectorLabel) >= 0.1m) && nearbyResults.IsMoreResults) { var nearbyResults2 = await _googlePlaceNearbySearchApiClient.GetNextPageTokenAsync(nearbyResults.next_page_token); foreach (var nr in nearbyResults2.results) { var details = await _googlePlaceDetailsApiClient.GetAsync(_googlePlaceDetailsInputFactory.CreateAllUseful(nr.place_id)); if (details.IsOk) { var candidate = new PlanElementCandidate(details.Result.name, details.Result.place_id, details.Result.formatted_address, details.Result.geometry.location, details.Result.opening_hours, details.Result.types, details.Result.rating, details.Result.price_level, details.Result.user_ratings_total); if (!candidates.Any(x => x.PlaceId == candidate.PlaceId)) { candidates.Add(candidate); } } ++counter; } } if (test && candidates.Count > 15) { return(candidates); } } if (test && candidates.Count > 15) { break; } } if (candidates.Count == 0) { throw new UserFriendlyException($"Nie znaleziono żadnych potencjalnych kandydatów na elementy planu"); } return(candidates); }