Select to view content in your preferred language

Arcade function TrackFieldWindow() question --

240
2
03-03-2026 10:42 AM
JeffSilberberg
Frequent Contributor

I am struggling with what I thought would be an easy task..  

Specifically,  I have a Velocity RTA that needs to determine if a vehicle is speeding by looking at three successive reports and if they are all over the limit, flag a speeding violation -- 

So the Feed uses the UnitId as the Track_id and the Event_time as the Start_time. 

In the Calculate Field I have the following Arcade -- 

// Get last 3 speed observations
var speeds = TrackFieldWindow("speedInMph", -2, 0);

// Check that all 3 speeds are > 25 MPH
return
    Count(speeds) >= 3 &&
    speeds[0] > 25 &&
    speeds[1] > 25 &&
    speeds[2] > 25;
 
But when I add some additional logic and acpture the values of count(speeds)
it's always two which is the Index not the Count. And the if I read the
Documentation properly speeds[0] is Current, Speeds[1] is previous report and
speeds[2] is two previosu of the current report.
 
Anway, my question is my trackFieldWindow() not correct or is something else going
on here ??
 
 
 
0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

From the way I read it, your code would only return two items. Take a look at the second example in the documentation:

Your track has a field named Speed with sequentially ordered values of [10, 20, 30, 40, 50]. The geometries of the features are [{x: 1, y: 1},{x: 2, y: 2} ,{x: null, y: null},{x: 4, y: 4}, {x: 5, y: 5}]. The expression is evaluated at each feature in the track. For this example, we examine results when evaluated at the third feature (30). Results are returned inclusive of the start feature, and exclusive of the end feature.

var window = TrackFieldWindow('Speed', -2,2)window;// returns [10,20,30,40]

What happens when you use this syntax?

// Get last 3 speed observations
var speeds = TrackFieldWindow("speedInMph", -2, 1);

// Check that all 3 speeds are > 25 MPH
return
    Count(speeds) >= 3 &&
    speeds[0] > 25 &&
    speeds[1] > 25 &&
    speeds[2] > 25;

 

0 Kudos
JeffSilberberg
Frequent Contributor

Well, it's much better, although I honestly do not understand the results I see -- 

 

The function trackFieldWindow() takes the Field Name, the Start Index and the End Index.  So I had that I wanted, -2, -1, and 0 index positions,  With your change of setting the End Index to 1 I am seeing a count() of three in some cases, although I see multiple counts of 1 and 2 before I see it get up to three sometimes. 

 

Also, trackFieldWindow(speedInMPH, -1, 1)Window;  gives me an error .  

Test execution error: Unexpected identifier.. Verify test data.

 

 

0 Kudos