Example #1
0
        public static void GroupFootFallFun()
        {
            var newData = new RetailGffData
            {
                Type        = "Customer",
                Escorted    = true,
                GroupId     = "GroupId-01",
                Membercount = 2,
                Direction   = "In",
            };

            RetailGroupFoolFallElk data = new RetailGroupFoolFallElk
            {
                timestamp = DateTime.Now,
                CustId    = "Tes111",
                CreatedAt = DateTimeOffset.Now.ToUnixTimeSeconds(),
                Table     = "GroupFootFall",
                AssetId   = "NanoId-02",
                CameraId  = "Cam-01",
                SiteId    = "Store-01",
                //data = JsonConvert.SerializeObject(newData)
            };

            var ElkObject = new ELKHelper();

            ElkObject.UpdateDataToElk(data);
        }
Example #2
0
        /// <summary>
        /// Data is Getting Inserted Properly, it is working as expected
        /// </summary>
        /// <param name="groupfootfall"></param>
        public void InsertRetailDataToElk(RetailGroupFoolFallElk groupfootfall)
        {
            try
            {
                var uri      = new Uri("http://127.0.0.1:9200/");
                var settings = new ConnectionSettings(uri);
                var client   = new ElasticClient(settings);
                var day      = DateTimeOffset.Now.Day;
                var month    = DateTimeOffset.Now.Month;
                var year     = DateTimeOffset.Now.Year;

                string indexType    = "elktest1";
                var    DateInString = String.Concat(year, month, day);
                var    indexName    = String.Concat(indexType, "_", DateInString);

                settings.DefaultIndex(indexName);
                var clientResponse = client.IndexDocument(groupfootfall);

                if (clientResponse.IsValid)
                {
                    System.Threading.Thread.Sleep(500);
                    Console.WriteLine("Done");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #3
0
        public void InsertRetailDataToElkDateWise(RetailGroupFoolFallElk groupfootfall)
        {
            try
            {
                var uri      = new Uri("https://localhost:7200/");
                var settings = new ConnectionSettings(uri);
                var client   = new ElasticClient(settings);
                var day      = groupfootfall.timestamp.Date.ToString("dd");
                var month    = groupfootfall.timestamp.Date.ToString("MM");
                var year     = groupfootfall.timestamp.Year;

                string indexType    = "_prod";
                var    DateInString = String.Concat(year, month, day);
                var    indexName    = String.Concat(indexType, "_", DateInString);

                settings.DefaultIndex(indexName);
                var clientResponse = client.IndexDocument(groupfootfall);

                //string GroupFootFallData = "{\"Membercount\":\"4\",  \"Direction\":\"entry\", \"Type\":\"Customer\"}";
                ////var clientResponse = client.Index(GroupFootFallData, i => i.Index(indexName));
                //var clientResponse = client.IndexDocument(GroupFootFallData);


                if (clientResponse.IsValid)
                {
                    System.Threading.Thread.Sleep(500);
                    Console.WriteLine("Done");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #4
0
        /// <summary>
        /// Update a Document Using id For An Index.
        /// </summary>
        /// <param name="gff"></param>
        public void UpdateDataToElk(RetailGroupFoolFallElk gff)
        {
            try
            {
                var uri      = new Uri("http://127.0.0.1:9200/");
                var settings = new ConnectionSettings(uri);
                var client   = new ElasticClient(settings);
                var day      = DateTimeOffset.Now.Day;
                var month    = DateTimeOffset.Now.Month;
                var year     = DateTimeOffset.Now.Year;

                string indexType    = "elktest1_20201216";
                var    DateInString = String.Concat(year, month, day);
                var    indexName    = String.Concat(indexType, "_", DateInString);

                //dynamic updateDoc = new System.Dynamic.ExpandoObject();
                //updateDoc.Title = "My new title";

                var response = client.Update(DocumentPath <RetailGroupFoolFallElk>
                                             .Id("nKt5anYBivAaQj_VvueF"),
                                             u => u
                                             .Index(indexType)
                                             .DocAsUpsert(true)
                                             .Doc(gff)

                                             );
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #5
0
        public async Task <FunctionResponseModel> GetHeatmapSendToELK(string CustId)
        {
            FunctionResponseModel _response = new FunctionResponseModel();
            var influxDbClient = new InfluxDbClient("http://influxurl:8086/", "username", "password", InfluxDbVersion.v_1_3);
            var ping           = await influxDbClient.Diagnostics.PingAsync();

            try
            {
                if (ping.Success)
                {
                    List <GetHeatmapResponseModel> HeatMapList = new List <GetHeatmapResponseModel>();

                    var query1 = "SELECT time,CameraId,MemberCount,XCord,YCord,StoreId FROM \"MeasurementName\"  WHERE \"CustId\"='" + CustId + "'";

                    var response = await influxDbClient.Client.QueryAsync(query1, "DatabaseName");

                    IEnumerable <Serie> series = response;

                    foreach (Serie serie in series)
                    {
                        foreach (dynamic val in serie.Values)
                        {
                            var temp = val[0];
                            var time = DateTime.ParseExact(val[0].ToString("yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss", null);

                            GetHeatmapResponseModel HeatMap = new GetHeatmapResponseModel
                            {
                                //Time = DateTime.ParseExact(val[0].ToString("yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss", null),
                                Time        = time,
                                CameraId    = Convert.ToString(val[1]),
                                TotalNumber = Convert.ToInt32(val[2]),
                                XCord       = Convert.ToString(val[3]),
                                YCord       = Convert.ToString(val[4]),
                                StoreId     = Convert.ToString(val[5]),
                            };
                            HeatMapList.Add(HeatMap);
                        }
                    }

                    foreach (var HMData in HeatMapList)
                    {
                        RetailHMData newData = new RetailHMData
                        {
                            XCord = Convert.ToDouble(HMData.XCord),
                            YCord = Convert.ToDouble(HMData.YCord),
                        };


                        var testData = JsonConvert.SerializeObject(newData);

                        RetailGroupFoolFallElk DataDetails = new RetailGroupFoolFallElk
                        {
                            AssetId   = "Nano-01",
                            CameraId  = HMData.CameraId,
                            CreatedAt = ((DateTimeOffset)HMData.Time).ToUnixTimeSeconds(),
                            CustId    = CustId,
                            SiteId    = HMData.StoreId,
                            Table     = "Heatmap",
                            timestamp = HMData.Time,
                            data      = newData
                        };

                        var ElkObject = new ELKHelper();
                        ElkObject.InsertRetailDataToElkDateWise(DataDetails);
                    }

                    _response.Message    = JsonConvert.SerializeObject(HeatMapList);
                    _response.Statuscode = "OK";
                    return(_response);
                }
                else
                {
                    _response.Message = "InfluxDB NOT RUNNING";

                    _response.Statuscode = "EXCEPTION";
                    return(_response);
                }
            }
            catch (Exception ex)
            {
                _response.Message    = ex.Message;
                _response.Statuscode = "EXCEPTION";
                return(_response);
            }
        }