public async Task <ResturantsResponse> PostPhoto() { var data = await this.Request.Content.ReadAsByteArrayAsync(); var faces = GetFaces(data); var emotions = GetEmotions(data); //string lat; //Request.Headers.TryGetValues("Lat") //var geoLoc = new GeoLocationParameters() {Lat =[@"Lat"], Lon = Request.Headers["Lon"]}; var searchRequests = SearchRequestEvaluator.Evaluate(faces, emotions); var dataProvider = new DoubleGisDataProvider(); var firms = searchRequests.Select(x => dataProvider.GetResturants(x.SearchQuery, x.Criteria)); var defaultFirms = dataProvider.GetResturants("", Enumerable.Empty <string>()); var random = new Random(); var pickedResults = Pick(firms.SelectMany(x => x.Variants), random.Next(4, 8)).ToArray().OrderByDescending(x => x.FlampOverallRating); var pickedResultNames = pickedResults.Select(x => x.Name); var defaultItems = Pick(defaultFirms.Variants.Where(x => !pickedResultNames.Contains(x.Name)), random.Next(2, 4)).OrderByDescending(x => x.FlampOverallRating); var result = new ResturantsResponse { Variants = pickedResults.Concat(defaultItems) .DistinctBy(x => x.Name) .ToArray(), People = faces.Select(f => f.FaceAttributes).ToArray() }; return(result); }
private void LoadData() { ResturantsResponse resp = null; string parameter; if (NavigationContext.QueryString.TryGetValue("d", out parameter)) { resp = JsonConvert.DeserializeObject <ResturantsResponse>(parameter); } if (resp == null) { return; } if (resp.People == null || resp.People.Length == 0) { MessageBoxResult result = MessageBox.Show("На фото люди не обнаружены. Пожалуйста, попробуйте еще раз.", "Не удалось", MessageBoxButton.OK); if (result == MessageBoxResult.OK) { NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); } return; } var index = 1; foreach (var item in resp.Variants.Where(x => !string.IsNullOrWhiteSpace(x.ImageUrl))) { var model = new ViewModel { Image = new Uri(item.ImageUrl, UriKind.Absolute), Title = item.Name, Index = index, Likes = item.FlampOverallRating.ToString("F2"), Url = item.DoubleGisCardUrl, FlampUrl = item.CardFlampUrl, Total = resp.Variants.Length }; _itemsSource.Add(model); index++; } _peopleViewModel.PeopleViewModels = resp.People.Select(p => new PersonViewModel(GetStyle(p), Convert.ToInt32(p.Age))).ToList(); AgeDiapasonText.Text = _peopleViewModel.AgeDiapason; }
public ResturantsResponse GetResturants(string searchString, IEnumerable <string> criteries, GeoLocationParameters geoLocationParameters = null) { var uri = CreateUri(searchString, criteries, geoLocationParameters); var resturants = MakeRequest(uri); var resturantsResponse = new ResturantsResponse() { Variants = resturants.ToArray() }; return(resturantsResponse); }