Select to view content in your preferred language

Calculate Total Time Spent at a Location

2304
6
05-06-2021 04:53 AM

Calculate Total Time Spent at a Location

This document provides steps on how to track how long an event has visited a location (geofence).  In the below example, a GeoTab Connector has been configured to track vehicle locations.  A polygon well pad feature service has been imported as geofences.  We’re interested in tracking how long a vehicle spends at each well pad. 

Configure Data

1. Create a table (i.e. Trip_Info) in a geodatabase with the following fields:

JakeSkinner_0-1620293911893.png

Field Name

Alias

Data Type

Description

OBJECTID

OBJECTID

Object ID

 

vin

VIN

Text

VIN number of the vehicle

wellpad

Well Pad

Text

Name of the well pad

wellpad_starttime

Well Pad Start Time

Date

Start Date/Time vehicle enters well pad

wellpad_endtime

Well Pad End Time

Date

End Date/Time vehicle exits well pad

unique_id

Unique ID

Text

Unique ID calculated by GeoEvent

visited

Visited

Text

Text field that will be updated to Yes when a vehicle enters and exits a geofence

wellpad_totaltime

Well Pad Total Time

Double

Field to calculate total time vehicle spends at well pad

 

This table is published to an editable feature service called Trip_Info

Configure GeoEvent

1. Previously configured for this example, the GeoTab Connector is writing real-time vehicle data to a feature service called Vehicles_Realtime

JakeSkinner_1-1620293911896.png

2.  The Well Pads have also been imported as Geofences.  The Category name is Well Pad for all these geofences:

JakeSkinner_2-1620293911905.png

3.  Create a GeoEvent Definition by importing the schema from the Trip_Info service published previously.

a.  Set the vin field as the TRACK_ID

JakeSkinner_3-1620293911915.png

4.  Create a copy of this GeoEvent Definition with the name Trip_Info_Reduced_Enter and keep only the vin, wellpad, wellpad_starttime, and unique_id fields:

JakeSkinner_4-1620293911923.png

5.  Create another copy of the Trip_Info GeoEvent Definition with the name Trip_Info_Reduced_Exit and keep only the vin, wellpad, wellpad_endtime, and unique_id fields:

JakeSkinner_5-1620293911930.png

The Trip_Info_Reduced_Enter and Trip_Info_Reduced_Exit GeoEvent Definitions are used to update the wellpad_starttime and wellpad_endtime fields.  The other fields are removed so that GeoEvent Services do not populate these fields will NULL/empty values.

6.  Create an Update a Feature output that updates the Trip_Info service using the unique_id field as the Unique Feature Identifier Field:

JakeSkinner_6-1620293911940.png

Start the Trip Info Update Output service.

7.  Create a new GeoEvent Service, i.e. Vehicle Enters Well Pad

a.  Add the geotab-in input

b. Add the GeoTagger processor referencing the Geofences with the Spatial Operator Enter Any.  The target field will be a New Field called GeoTags.  Specify a new name for the GeoEvent Definition, i.e. Enter Well Pad GeoTagger.  Choose No for the option Include Geofence Category in GeoTag

JakeSkinner_7-1620293911948.png

c.  Connect the Input to the GeoTagger Processor

d.  Add the Trip Info Update Output created previously to the GeoEvent Service, but do not connect it to the GeoTagger Processor.  Publish the GeoEvent Service and start it.  Let it run until some events enter a geofence.  This will create the new GeoEvent Definition created in the GeoTagger Processor. 

e.  Add a Filter to remove events that have NULL values for the GeoTags field:

JakeSkinner_8-1620293911951.png

 

f.  Add a Field Mapper Processor.  The Source GeoEvent Definition will be the GeoEvent Definition created from the GeoTagger Processor.  The Target GeoEvent Definition will be Trip_Info_Reduced_Enter.  The GeoTags field created by the GeoTagger Processor contains the name of the well pad.  This will be mapped to the wellpad field.  The $RECEIVED_TIME will be mapped to the wellpad_starttime, and nothing will be mapped to unique_id.  This will be calculated next:

JakeSkinner_9-1620293911958.png

g.  Add a Field Calculator Processor.  Calculate the unique_id by concatenating the vin and wellpad fields:

JakeSkinner_10-1620293911963.png

The unique_id is used in the case the vehicle visits multiple geofences.  This field will allow all these visits to be recorded.

The GeoEvent Service should appear as the following:

JakeSkinner_11-1620293911966.png

8.  Make a copy of the Vehicle Enters Well Pad GeoEvent Service

a.  Rename the GeoEvent Service to Vehicle Exits Well Pad

b.  Update the GeoTagger Process and change the Spatial Operator to Exit Any.  Also, change the New GeoEvent Definition Name to Exit Well Pad GeoTagger

JakeSkinner_12-1620293911974.png

c.  Disconnect the GeoTagger from the Filter, Publish, and start the GeoEvent Service so it creates the new GeoEvent Definition:

JakeSkinner_13-1620293911977.png

d.  After the Exit Well Pad GeoTagger geoevent definition has been created, open the Field Mapper Processor.  Change the Source GeoEvent Definition to Exit Well Pad GeoTagger and the Target GeoEvent Definition to Trip_Info_Reduced_ExitGeoTags will be mapped to wellpad, $RECEIVED_TIME will be mapped to wellpad_endtime, and unique_id will be left blank:

JakeSkinner_14-1620293911985.png

e.  Connect the GeoTagger Processor back to the Filter, Publish, and start the GeoEvent Service

JakeSkinner_15-1620293911987.png

9.  Make a copy of the Trip_Info GeoEvent Definition

  1. Specify the name as Trip_Info_OBJECTID
  2. Set the objectid field as the TRACK_IDJakeSkinner_16-1620293911994.png

10.  Make a copy of the Trip_Info_OBJECTID GeoEvent Definition

  1. Specify the name as Trip_Info_OBJECTID_Reduced
  2. Delete all fields except objected, vin, unique_id, and visited

JakeSkinner_17-1620293912001.png

11.  Create a Poll an ArcGIS Server for Features input

  1.  Name:             Trip Info Input
  2.  Check No for Create GeoEvent Definition
  3.  Set the GeoEvent Definition Name (Existing) to Trip_Info_OBJECTID

JakeSkinner_18-1620293912010.png

This input will be used to see when a location has a start time and end time recorded

12.  Create a copy of the Trip Info Update Output and rename it to Trip Info Update Visited Output.  Set the Unique Feature Identifier Field to objectid:

JakeSkinner_19-1620293912015.png

Start the Trip Info Update Visited Output service.

13.  Create a new GeoEvent Service called Trip Info Visited

  1. Add the Trip Info Input
  2. Add a Filter and set this to when the wellpad_endtime is not NULL

JakeSkinner_20-1620293912017.png

c.  Add another Filter and set this to when the visited field is NULL

JakeSkinner_21-1620293912019.png

d.  Add a Field Mapper Processor:

Source GeoEvent Definition:                       Trip_Info_OBJECTID

Target GeoEvent Definition:                        Trip_Info_OBJECTID_Reduced

Map objected, vin, and unique_id fields

JakeSkinner_22-1620293912024.png

e.  Add a Field Calculator Processor

Expression:                       unique_id + ‘ - Visited’

Target Field:                     Existing Field

Existing Field Name:       unique_id

JakeSkinner_23-1620293912029.png

This Field Calculator will update the unique_id field so GeoEvent can accurately record if the same vehicle visits the same well pad multiple times.

f.  Add another Field Calculator Processor

Expression:                       ‘Yes’

Target Field:                     Existing Field

Existing Field Name:       visited

JakeSkinner_24-1620293912034.png

This field will allow the GeoEvent Service to only update rows that have not been visited, instead of updating any row that has a wellpad_endtime.  If you recall, we created a filter early to only process events that have a NULL value for the visited field.

g.  Add the Trip Info Updated Visited Output

JakeSkinner_25-1620293912038.png

Calculate Date Difference

Here is an example of how the data will appear in the Trip Info feature service:

JakeSkinner_26-1620293912050.png

The wellpad_totaltime field can now be calculated to show the total time a vehicle has spent at a well pad.  You can easily perform the calculation using ArcGIS Pro’s Field Calculator. 

1.  Select all records that contain Yes for the visited field

JakeSkinner_27-1620293912054.png

2.  Execute the Field Calculator on the wellpad_totaltime field:

Expression Type:                              Arcade

Expression:                                        

 

 

var startDate = Date($feature.wellpad_starttime);
var endDate = Date($feature.wellpad_endtime);
var totalTime = DateDiff(endDate, startDate, 'minutes');
return totalTime;

 

 

JakeSkinner_28-1620293912062.png

Result:

pict.png

Comments
CatherineKoerber
Emerging Contributor

@JakeSkinner 

Jake, thank you for showing this geoevent configuration. I've been trying to figure out a way to show this using Tracker Tracks within a geofence but to add to this would be sending 1 email if a field worker using Tracker stays within the geofence for 30 minutes (which in my case would be a danger zone) and then send only 1 email after the 30 minute time limit? I've tried several incident detectors and filter scenarios (which didn't work) and what I currently have configured is using the event controller (with the trip info input from this blog) but I don't know if that's exactly what I need. Any ideas?

JakeSkinner
Esri Esteemed Contributor

@CatherineKoerber  This is what I think would work:

  • As a GeoEvent Input, poll the Trip Info table which contains the total time at a location
  • Create a GeoEvent Service
  • Add the GeoEvent Input in bullet one
  • Add a Filter for when the total time is greater than 30 minutes
  • Add the Event  Controller to send only one e-mail at a given time interval
  • Add the E-mail Output
CatherineKoerber
Emerging Contributor

@JakeSkinner

Thank you!

Moi_Nccncc
Regular Contributor

I have question, 

  If the car entered the geofence area at 1:00PM and I want to fire an event (email,sms,etc) if it will stay more than 10m. The Car stopped there are no more event are coming to check the status of the car. However I want fire an event after 10 minute not per receiving a location from the car.  And I also don't want to save the car location any where, the location will be save in cache when car enter the geofence and every thing will be deleted after hi exit the geofence. 
Any help how to do so

JakeSkinner
Esri Esteemed Contributor

@Moi_Nccncc take a look at the Track Idle Detector.  This may provide a solution for you.

JeffSilberberg
Frequent Contributor

@JakeSkinner 

  I am working on a similar need only in Velocity and I just wanted to say thank you for that Link.  That's a great very detailed posting. 

Version history
Last update:
‎05-06-2021 07:04 AM
Updated by:
Contributors