Clarification Regarding How the Behaviour Event is Generated.

Hello, I was reviewing the onPosition logic for Behavior Event logic and noticed an interesting behavior. Currently, there's a check that compares the new position’s fix time to the cached fix time using an equality check:

    @Override
    public void onPosition(Position position, Callback callback) {

        Position lastPosition = cacheManager.getPosition(position.getDeviceId());
        if (lastPosition != null && position.getFixTime().equals(lastPosition.getFixTime())) {
            double acceleration = UnitsConverter.mpsFromKnots(position.getSpeed() - lastPosition.getSpeed()) * 1000
                    / (position.getFixTime().getTime() - lastPosition.getFixTime().getTime());
            if (accelerationThreshold != 0 && acceleration >= accelerationThreshold) {
                Event event = new Event(Event.TYPE_ALARM, position);
                event.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
                callback.eventDetected(event);
            } else if (brakingThreshold != 0 && acceleration <= -brakingThreshold) {
                Event event = new Event(Event.TYPE_ALARM, position);
                event.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
                callback.eventDetected(event);
            }
        }
    }

I’m curious if this is the intended design. Since this condition only allows processing when the fix times are exactly the same, it means that in cases of different timestamps (i.e., when there's an actual time interval), the acceleration calculation and behavior events like harsh break and harsh acceleration events might be skipped. Also, when the times are equal, this could potentially lead to a zero in the denominator for the acceleration calculation.

Could you please clarify the expected behavior here? Is the goal to process only when both timestamps match, or should we be processing when there's a valid time difference? Should there not be a difference between current and previous position fixtime to calculate the acceleration. Should we perhaps be processing only when there's a valid (non-zero) time difference?

Please forgive if I misunderstood the logic—any clarification on this approach would be greatly appreciated.

Anton Tananaev16 days ago

Got it. Thank you.