/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetPredictionResponse response = new GetPredictionResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("modelScores", targetDepth)) { var unmarshaller = new ListUnmarshaller <ModelScores, ModelScoresUnmarshaller>(ModelScoresUnmarshaller.Instance); response.ModelScores = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("outcomes", targetDepth)) { var unmarshaller = new ListUnmarshaller <string, StringUnmarshaller>(StringUnmarshaller.Instance); response.Outcomes = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("ruleResults", targetDepth)) { var unmarshaller = new ListUnmarshaller <RuleResult, RuleResultUnmarshaller>(RuleResultUnmarshaller.Instance); response.RuleResults = unmarshaller.Unmarshall(context); continue; } } return(response); }
public async Task <PeopleCountModel> GetPeopleCount(string videoPath) { try { List <string> _products = new List <string>() { "Apple", "Samsung", "Nokia", "Redmi" }; byte[] video = File.ReadAllBytes(Path.GetFullPath(_configuration["Settings:VideoRepoPath"])); string inputVideo = Convert.ToBase64String(video, 0, video.Length); var reqInput = new InputRequest() { video_base64 = inputVideo }; var httpClient = _clientFactory.CreateClient(); httpClient.BaseAddress = new Uri(_configuration["Settings:SentientMicroserviceBaseAddress"]); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Add("x-api-key", _configuration["Settings:SentientAPIKey"]); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, _configuration["Settings:SentientPeopleCountAPIEndPoint"]); request.Content = new ObjectContent(typeof(InputRequest), reqInput, new JsonMediaTypeFormatter()); var response = await httpClient.SendAsync(request).ConfigureAwait(false); if (response.IsSuccessStatusCode) { var result = await response.Content.ReadAsStringAsync(); GetPredictionResponse _res = JsonConvert.DeserializeObject <GetPredictionResponse>(result); PeopleCountModel _result = new PeopleCountModel() { PeopleCount = _res.Peoples.Count, ProductName = _products[new Random().Next(3)] }; await fireStoreDb.Collection("SuggestionHistory").Document("peoplewatchcount").SetAsync(_result, SetOptions.Overwrite); //for (int i = 1; i <= _result.NoOfPeople; i++) //{ // string peopleID = i.ToString("D3"); // List<string> peopleObject = _res.Peoples[i - 1][$"person id: {peopleID}"].ToObject<List<string>>(); // string duration = peopleObject.Where(x => x.StartsWith("duration appeared")).FirstOrDefault(); // if (!string.IsNullOrEmpty(duration)) // { // string seconds = duration.Split(':')[1]; // _result.Appearing.Add(new PeopleModel() { PeopleID = peopleID, DurationAppeared = seconds }); // } //} return(_result); } return(null); } catch (Exception ex) { throw ex; } }