Calculate stoppage time for a vehicle

We are using ElasticSearch to store GPS data. And we are storing documents in following format : -
{
imei : 12345678,
date : "2017-04-24",
Docs : [
{
latitude : 1.4567,
longitude : 2.8765,
speed : 67,
created_at : "2017-04-24 10:59:34"
},
{
latitude : 1.4567,
longitude : 2.8765,
speed : 67,
created_at : "2017-04-24 10:59:34"
},
{
and so on
}

 ]

}

Now we have to calculate stoppage time of a vehicle, means for how much time a vehicle was stopped at a particular location.
So for this we can do group by lat, long and where speed =0 and imei = xyz and to apply a range of timestamp we can apply a filter of created_at to get stoppages within given time range.And after applying these filter we will calculate min and max value of timestamp field and the difference between these two values will be the stoppage time.

But what if , vehicle's starting and ending locations are same So in this case the lat long of starting and ending point will be same. So in min max it will include starting and ending point's timestamp and we have to consider separate stoppage for starting and ending position.
So anyone can please suggest me any method/approach to solve this.

Thanks In Advance

I think you can have to approaches :

First one : getting the enter / exit of the location with a second query :

You need to know when the vehicle left the location and reenter during the given time lapse .
I did it before using two query :

  • 1st query is the one you have : filter on speed = 0 + geodistancequery around this point , with a radius corresponding to what you want (let's say 100 meters).
  • 2nd query is the same but without speed = 0, and with a radius bigger than the first one (let's say 300 meters, or a radius big enough so that your vehicle has sent at least one message in this zone).

You then have two sets of results : one for the vehicle inside the region you want, and another one with the message the vehicle has sent "just outside" this circle (remove from the result the one inside the smaller region), which are basically all the "enter" or "exit" of this circle. I'm not sure elasticsearch provide a "ring" geoshape yet (instead of a bigger circle), which would be better because it would allow you to directly get the data in a ring outside the smaller region.

Then you can play with the timestamp and reorder your data in the set of results to get when he entered or exited, (if there is no enter/exit, it means that the vehicle stayed in the circle, or that you missed a message in the "outer ring". In this case you have to make it bigger, but then you can have many message inside the outer ring and need to clean up this data you get before calculate the enter / exit).
This solution will also work if you want to know the vehicle inside the region even if speed is != 0.

Second one : getting the message with speed > 0 in the region

If you only need when the vehicle is stopped in the region, you could also get the messages with speed > 0, then split your data from this result. Ordering by timestamp, you could maybe work with the data and say "if speed > 0, than means he wasn't stopped in this place anymore, so I split the data here". I'm not sure if this will be better in your case.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.