Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In GPS application we receive data every 10 seconds from each device.we are displaying the device count like OffRoad, Moving, Stopped and Not working

suppose no data from the device in the last 5 minutes we are marking them as Not working,

we are updating device data in concurrent dictionary and database as well.
while counting OffRoad, Moving, Stopped and Not working, we are using a concurrent dictionary but Not working device count is always wrong. but when we count using database data the count is correct. both concurrent dictionary and database data is the same.
Please look into it, any suggestion would be appreciated

What I have tried:

C#
try
           {
               if (latestLocations.ContainsKey(IMEI))
               {
                   CompletePointInfo previousPointData = latestLocations[IMEI];
                   if (completepointinfo.point.DeviceTime >= previousPointData.point.DeviceTime || OffRoadKey == 1)
                   {
                       DateTime curetDateTime = DateTime.Now.AddMinutes(-5);
                       //Pushing the latest data to Memory
                       latestLocations.AddOrUpdate(IMEI, completepointinfo, (key, oldcompletepoint) => completepointinfo);

                       var pointStatus = completepointinfo.pointstatusinfo; string devicemotionstatus = string.Empty;
                       if (OffRoadVehilcesList.ContainsKey(completepointinfo.VehicleNo))
                           devicemotionstatus = "OffRoad";
                       else if (completepointinfo.point.DeviceTime.Value < curetDateTime || completepointinfo.point.DeviceTime.Value == null)
                           devicemotionstatus = "NotWorking";
                       else if (completepointinfo.point.ACC.Value && completepointinfo.point.Speed > 0 && completepointinfo.point.DeviceTime.Value >= curetDateTime)
                           devicemotionstatus = "Moving";
                       else if (completepointinfo.point.DeviceTime.Value >= curetDateTime)
                           devicemotionstatus = "stoppedOrstaying";


                       //Dashboard Counts
                       #region SignalR Responses

                       DashBoardRepsonse deviceStatusCount = new DashBoardRepsonse();
                       //Dashboard Counts

                           foreach (var user in AssamGVKHub.connectedUsersWithSelectedDevice)
                           {
                               var userDeviceList = user.Value; var userConnectionId = user.Key;
                               int movingCount = 0, idleCount = 0, offRoadcount = 0, stoppedcount = 0;

                               if (userDeviceList.Contains(IMEI))
                               {

                                   //Parallel.ForEach(userDeviceList, (e) =>
                                  userDeviceList.ForEach(e =>
                                   {
                                       CompletePointInfo latestPoint = null;
                                       if (latestLocations.ContainsKey(e))
                                       {
                                           //latestPoint = list.Where(a => a.point.IMEI == e).FirstOrDefault();
                                               latestPoint = latestLocations1[e];
                                               if (latestPoint != null && latestPoint.point.ACC != null)
                                               {
                                                   if (GeoFenceController.OffRoadVehilcesList.ContainsKey(latestPoint.VehicleNo))
                                                       offRoadcount++;
                                                   else if (latestPoint.point.DeviceTime.Value < curetDateTime)

                                                       stoppedcount++;
                                                   else if (latestPoint.point.ACC.Value && latestPoint.point.Speed > 0 && latestPoint.point.DeviceTime.Value >= curetDateTime)//&& latestPoint.point.DeviceTime.Value.AddMinutes(5) >= DateTime.Now)
                                                       movingCount++; //If Engine(Acc) is ON, latest speed is > 0 & received the data in the last 5 minutes then device is moving
                                                   else if (latestPoint.point.DeviceTime.Value >= curetDateTime)
                                                       idleCount++; //If Engine(Acc) is ON, latest speed is = 0 then the device is idel
                                               }

                                       }
                                   });
                                   deviceStatusCount.total = userDeviceList.Count;
                                   deviceStatusCount.OffRoad = offRoadcount;
                                   deviceStatusCount.moving = movingCount;
                                   deviceStatusCount.idle = idleCount;
                                   deviceStatusCount.stopped = stoppedcount;


                                   _dashboardHub.Clients.Client(userConnectionId).VehicleStats(deviceStatusCount);
                               }

                           }




                       //Dashboard Markers

                       _dashboardHub.Clients.All.updateMarkerStatus(new
                       {
                           Lat = completepointinfo.point.Latitude,
                           Lng = completepointinfo.point.Longitude,
                           Status = devicemotionstatus,
                           Imei = completepointinfo.point.IMEI,
                           VehicleNo = completepointinfo.VehicleNo,
                           CurrentSpeed = completepointinfo.point.Speed,
                           DeviceDate = completepointinfo.point.DeviceTime,
                           ReceivedDate = completepointinfo.point.Inserted_Date,
                           SegmentName = completepointinfo.vehicleBaseLocation,
                           DistrictName = completepointinfo.DistrictName,
                           vehicleCounts = deviceStatusCount
                       });


                       #endregion SignalR Responses
Posted
Updated 9-Sep-19 7:52am
v2
Comments
Richard MacCutchan 9-Sep-19 8:09am    
You need to provide more details and explain where the error occurs. Where exactly are the counts being collected and how are they different?

What does the debugger tell you ? No one will trawl through all that code for you - make more of an effort to pinpoint the problem
 
Share this answer
 
Comments
chandubbbb 9-Sep-19 6:10am    
without seeing the code how can anybody will help? no exception at all. but count is not
matching with the database one.
Step through your code in the debugger and look at the values as you go - you say the data is identical but it it obviously isn't
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900