Exemplo n.º 1
0
        /* await using (ServiceBusClient client = new ServiceBusClient(_configuration["Settings:AzureServiceBusConnectionString"]))
         * {
         *   // create a processor that we can use to process the messages
         *   ServiceBusProcessor processor = client.CreateProcessor("messagetest1", new ServiceBusProcessorOptions());
         */

        public async Task <object> setSuggestion()
        {
            PeopleCountModel _peopleCount = GetPeopleCountFromDB();

            DocumentSnapshot snapshot = await fireStoreDb.Collection("SuggestionHistory").Document("productdataset").GetSnapshotAsync();

            if (snapshot.Exists && _peopleCount != null)
            {
                Dictionary <string, List <ProductModel> > _objects = snapshot.ConvertTo <Dictionary <string, List <ProductModel> > >();
                ProductModel _product = _objects["products"].Where(x => x.ProductName == _peopleCount.ProductName).FirstOrDefault();
                if (_product != null)
                {
                    Int64 nonBuyingPeople = _peopleCount.PeopleCount - _product.SalesCount;

                    decimal notBuyingPercentage = (nonBuyingPeople / _product.TotalCount) * 100;
                    if (notBuyingPercentage < 50)
                    {
                        decimal maxCashbackPrice  = _product.Price - _product.OriginalPrice;
                        decimal suggestedCashback = maxCashbackPrice - 100;
                        string  suggestion        = $"{_peopleCount.ProductName} was watched by total of {_peopleCount.PeopleCount} people. But total sale for this product was {100 - notBuyingPercentage}% . If we provide CASHBACK of ${suggestedCashback} for this product then sales can improve";

                        AddToAzureMessageQueue(suggestion);
                    }
                }
            }
            return(string.Empty);
        }
Exemplo n.º 2
0
        public ActionResult PeopleCount(int?SearchType, DateTime?ReportForTime)
        {
            var model = new PeopleCountModel();

            if (SearchType == null)
            {
                return(View(model));
            }
            model.SearchType  = (PeopleCountSearchType)SearchType.Value;
            model.ReportItems = _dao.GetPeopleCountReport((PeopleCountSearchType)SearchType.Value, ReportForTime);
            if (Request.IsAjaxRequest())
            {
                return(PartialView("PeopleCountList", model));
            }
            return(View(model));
        }
Exemplo n.º 3
0
        private PeopleCountModel GetPeopleCountFromDB()
        {
            string filepath = @"inputfiles\iretaildb-4bac09deb4f6.json";

            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", filepath);
            string projectId   = "iretaildb";
            var    fireStoreDb = FirestoreDb.Create(projectId);

            DocumentSnapshot snapshot = fireStoreDb.Collection("SuggestionHistory").Document("peoplewatchcount").GetSnapshotAsync().Result;

            if (snapshot.Exists)
            {
                PeopleCountModel _objects = snapshot.ConvertTo <PeopleCountModel>();
                return(_objects);
            }


            return(null);
        }
Exemplo n.º 4
0
        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;
            }
        }