Filter Duplicate

tambiu3 months ago

Hi, I was trying to compile traccar with some modification the filterhandler about filter duplicate, because most the device that we have do not filter duplicate because they have ignition attribute, so I have made this code modification (to filter duplicate only the device does not have changes on ignition and charge)

private boolean filterDuplicate(Position position, Position last) {
        if (filterDuplicate && last != null && position.getFixTime().equals(last.getFixTime())) {
            if (position.getAttributes().containsKey(position.KEY_IGNITION)) {
                if (position.getAttributes().get(position.KEY_IGNITION) != last.getAttributes().get(last.KEY_IGNITION)) {
                    return false;
                }
            } else if (position.getAttributes().containsKey(position.KEY_CHARGE)) {
                if (position.getAttributes().get(position.KEY_CHARGE) != last.getAttributes().get(last.KEY_CHARGE)) {
                    return false;
                }
            } for (String key : position.getAttributes().keySet()) {
                    if (!last.hasAttribute(key)) {
                        return false;
                    }
                }
                return true;
        }
        return false;
    }

for now is working, but maybe anyone have better way to do it tell me please.