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:
try
{
if (latestLocations.ContainsKey(IMEI))
{
CompletePointInfo previousPointData = latestLocations[IMEI];
if (completepointinfo.point.DeviceTime >= previousPointData.point.DeviceTime || OffRoadKey == 1)
{
DateTime curetDateTime = DateTime.Now.AddMinutes(-5);
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";
#region SignalR Responses
DashBoardRepsonse deviceStatusCount = new DashBoardRepsonse();
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))
{
userDeviceList.ForEach(e =>
{
CompletePointInfo latestPoint = null;
if (latestLocations.ContainsKey(e))
{
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)
movingCount++;
else if (latestPoint.point.DeviceTime.Value >= curetDateTime)
idleCount++;
}
}
});
deviceStatusCount.total = userDeviceList.Count;
deviceStatusCount.OffRoad = offRoadcount;
deviceStatusCount.moving = movingCount;
deviceStatusCount.idle = idleCount;
deviceStatusCount.stopped = stoppedcount;
_dashboardHub.Clients.Client(userConnectionId).VehicleStats(deviceStatusCount);
}
}
_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