Geoevent processor "field calculator" rounds up value removing all decimals

408
1
Jump to solution
07-03-2022 06:11 PM
WalterSimonazzi_VicPol
New Contributor III

Hi geoevent team, 

I have a very simple geofencing service that calculates the time police officers spent inside a geofence. The geofence is setup as cumulative. Everything works ok, I'm getting the time they spent inside the geofence in miliseconds. I'm using the default geoevent definition called "incident" and the time spent inside the geofence is recorded in a field called "duration" in milliseconds. 

WalterSimonazzi_VicPol_0-1656896244420.png

Since I need the time in minutes, I added a new step in the process that converts the time recorded in the field "duration" into seconds just by adding a new geoprocessor "field calculator" that converts milliseconds into minutes. 

WalterSimonazzi_VicPol_1-1656896456528.png

I set the new field that will hold the minutes as float but I have tested with double too - and got exact the same result.

The problem is, the process works and the conversion happends however, for some reason the field calculator processor rounds up the results removing all decimals. Anything less than 1 min gets rounded up to 0 minutes which in turn makes us undercalculate the time spent inside the geofences. 

 

WalterSimonazzi_VicPol_2-1656897021435.png

 

Why is this happening? is there any workaround or a different way to perform the conversion? 

 

PS: Tested in 10.8 and 10.8.1 with the exact same results. 

@RJSunderman 

 

 

 

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RJSunderman
Esri Regular Contributor

At the 10.8.1 release I believe you need to use an expression whose constant value is a decimal value (rather than an integer value).  The duration field is a Long. The Field Calculator is therefore evaluating the expression ( duration / 60000 ) as ( LongLong ) and returning a Long.

Try an expression like:   duration / 60000.0

Adding the '.0' to the constant should force the Field Calculator to implicitly cast duration to a Double and evaluate ( Double / Double ) returning a Double, which will then be implicitly cast to a Float since that is the data type of the field into which you are writing the result.

When up upgrade to 10.9.1 you will have additional explicit type/cast functions such as toDouble() and toFloat(). The 10.9.1 type/cast functions could be used to clarify the expression as you would be able to write something like:  toFloat(duration) / 60000.0 and remove some of the implicit type/cast ambiguity.

-- RJ

View solution in original post

1 Reply
RJSunderman
Esri Regular Contributor

At the 10.8.1 release I believe you need to use an expression whose constant value is a decimal value (rather than an integer value).  The duration field is a Long. The Field Calculator is therefore evaluating the expression ( duration / 60000 ) as ( LongLong ) and returning a Long.

Try an expression like:   duration / 60000.0

Adding the '.0' to the constant should force the Field Calculator to implicitly cast duration to a Double and evaluate ( Double / Double ) returning a Double, which will then be implicitly cast to a Float since that is the data type of the field into which you are writing the result.

When up upgrade to 10.9.1 you will have additional explicit type/cast functions such as toDouble() and toFloat(). The 10.9.1 type/cast functions could be used to clarify the expression as you would be able to write something like:  toFloat(duration) / 60000.0 and remove some of the implicit type/cast ambiguity.

-- RJ