Skip to content

DriftFilter

roosit edited this page Nov 15, 2026 · 1 revision

DriftFilter

Up | Previous | Next | Русский

Full source with short explanations

Below is the full source of the class in documentation form. The comments inside the block explain the purpose of the parts of the class, but they are not stored in the working file DriftFilter.java: the production code stays clean and the explanations live in the wiki.

package com.velitask.plugin.official.processing.filters;

import static com.velitask.plugin.official.processing.FormulaParameters.decimal;

import com.velitask.sdk.data.SensorAtom;
import com.velitask.sdk.properties.DoubleSpinnerProperty;
import com.velitask.sdk.properties.IProperty;
import com.velitask.sdk.scenario.IStepControl;

/* Zeroes the "drift" - a small non-zero value that the device shows while standing still. */
public abstract class DriftFilter<A extends SensorAtom> extends ValueFilter<A> {

    /* Parameter names: keys in the import plans and in the step settings. */
    public static final String SPEED_BELOW = "speedBelow";
    public static final String SHIFT_BELOW = "shiftBelow";

    /* Localization key prefix: Plugin.ImportStep.drift. */
    private static final String KEY = _KEY + ".drift";

    private DoubleSpinnerProperty mSpeedBelow;
    private DoubleSpinnerProperty mShiftBelow;

    protected DriftFilter(String name, int version, Class<A> atomClass) {
        super(name, version, atomClass);
    }

    /* Shift of the point over the recording step in metres; computed by the subclass. */
    protected abstract double shiftMeters(A atom);

    @Override
    /* Two parameters; both default to 0 - the filter changes nothing. */
    public IProperty[] defineParameters() {
        mSpeedBelow = decimal(SPEED_BELOW, localized(KEY + "." + SPEED_BELOW + ".title"),
                localizedOrEmpty(KEY + "." + SPEED_BELOW + ".description"), 0);
        mShiftBelow = decimal(SHIFT_BELOW, localized(KEY + "." + SHIFT_BELOW + ".title"),
                localizedOrEmpty(KEY + "." + SHIFT_BELOW + ".description"), 0);
        return new IProperty[]{mSpeedBelow, mShiftBelow};
    }

    @Override
    /* A copy of the values in which the "drifting" values are replaced with zero. */
    protected double[] smooth(A[] atoms, double[] values, IStepControl control) {
        double speedBelow = mSpeedBelow.get();
        double shiftBelow = mShiftBelow.get();
        double[] result = values.clone();
        for (int i = 0; i < atoms.length; i++) {
            /* Condition: the value is below the threshold and (the shift is not checked or it is small). */
            if (values[i] < speedBelow && (shiftBelow <= 0 || shiftMeters(atoms[i]) < shiftBelow)) {
                result[i] = 0;
            }
        }
        return result;
    }
}

Purpose

DriftFilter<A> is the base of the "Drift … at a stop" filters. A GPS receiver standing still shows a small speed: the coordinates "wander" and draw movement that did not happen. The filter replaces such a value with zero. The subclass SpeedDriftFilter defines the speed and the shift calculation. The base is ValueFilter.

How it works

Parameters. Both are created as decimal(...) (a number not less than zero), default 0:

Parameter (key) UI name Meaning
speedBelow Zero below A value below the threshold is replaced with zero (km/h for speed). 0 — do not zero
shiftBelow Shift over the step less than, m Zero only if the point moved less than this distance over the recording step, in metres. 0 — do not check the shift

Algorithm. smooth copies the values (values.clone()) and for each atom i writes 0 if the following holds:

values[i] < speedBelow and (shiftBelow <= 0 or shiftMeters(atoms[i]) < shiftBelow).

The shift over the step is the abstract shiftMeters(atom); the subclass computes it. The values are not shifted and not smoothed: they either stay as they are or become zero. Writing to the atoms and recalculating the increments are in ValueFilter.

Where it is used. speedDrift is registered in BuiltinScenarios. In GoproImportPlan it is in the speed scenario: speedBelow = 4 (a speed below 4 km/h is zeroed); shiftBelow is not set.

Features and limitations

  • With the default values (speedBelow = 0) the condition values[i] < 0 does not hold for non-negative values: the filter changes nothing.
  • The shift condition is added to the threshold with "and", it does not replace it: both must hold.
  • The step requires a pauses step before it (the default for FilterStep).

Clone this wiki locally