Skip to content

UnchangedGaps

roosit edited this page Nov 15, 2026 · 1 revision

UnchangedGaps

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 UnchangedGaps.java: the production code stays clean and the explanations live in the wiki.

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

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.GapInput;
import com.velitask.sdk.scenario.GapsStep;
import com.velitask.sdk.scenario.IStepControl;

/* Formula "Pauses by frozen value": the device kept recording, but the value stood still. */
public final class UnchangedGaps extends GapsStep<SensorAtom> {

    /* Stable step name; localization keys Plugin.ImportStep.unchangedGaps.* */
    public static final String NAME = "unchangedGaps";
    public static final String HOLD_SEC = "holdSec";

    /* Prefix of the localization keys of the pause formula parameters: Plugin.ImportStep.gaps. */
    private static final String KEY = _KEY + ".gaps";

    /* The only parameter of the formula; created in defineFormulaParameters(). */
    private DoubleSpinnerProperty mHoldSec;

    public UnchangedGaps() {
        super(NAME, 1, SensorAtom.class);
    }

    @Override
    protected IProperty[] defineFormulaParameters() {
        /* Default 0: any repeat of the value in a row becomes a pause. */
        mHoldSec = decimal(HOLD_SEC, localized(KEY + "." + HOLD_SEC + ".title"),
                localizedOrEmpty(KEY + "." + HOLD_SEC + ".description"), 0);
        return new IProperty[]{mHoldSec};
    }

    @Override
    /* We look for series of consecutive atoms with the same value. */
    protected boolean[] detect(GapInput<SensorAtom> input, IStepControl control) {
        SensorAtom[] atoms = input.atoms();
        long[] times = input.times();
        boolean[] pauseAfter = new boolean[atoms.length];
        /* Time without changes in milliseconds. */
        long holdMs = (long) (mHoldSec.get() * 1000);
        /* start - the first atom of the current series of equal values. */
        int start = 0;
        for (int i = 1; i < atoms.length; i++) {
            /* Same value - the series goes on; otherwise the series ended before atom i. */
            if (atoms[i].sameValueAs(atoms[start])) {
                continue;
            }
            mark(pauseAfter, times, start, i - 1, holdMs);
            start = i;
        }
        /* The last series is closed after the loop. */
        if (atoms.length > 0) {
            mark(pauseAfter, times, start, atoms.length - 1, holdMs);
        }
        return pauseAfter;
    }

    /* A series of one atom or not longer than holdMs is not a pause; otherwise a pause after every atom of the series except the last. */
    private void mark(boolean[] pauseAfter, long[] times, int first, int last, long holdMs) {
        if (last <= first || times[last] - times[first] <= holdMs) {
            return;
        }
        for (int i = first; i < last; i++) {
            pauseAfter[i] = true;
        }
    }
}

Purpose

UnchangedGaps is the "Pauses by frozen value" formula (unchangedGaps): it sets a pause where the sensor value did not change for longer than the given time. The device kept recording, but the data stood still, for example the heart rate or speed froze at the last value after the connection with the sensor was lost. The formula is registered in BuiltinScenarios, but no built-in import scenario uses it: it is chosen in custom scenarios.

How it works

Data. The formula compares atom values with the SensorAtom.sameValueAs(...) method: atoms are equal if they have the same class and the same base values. The times are taken from GapInput.times().

Parameters. One formula parameter: "Time without changes, s" (holdSec, default 0), a fractional number of seconds. It is complemented by the common parameter "Stood if moved less than, m" (stoodMeters, default 30): it does not affect the search for pauses and only marks a found pause as a stop.

Algorithm.

  1. The atoms are divided into series of consecutive atoms whose value is equal to the value of the first atom of the series.
  2. A series of a single atom is not a pause.
  3. For the others, the time from the start of the first atom of the series to the start of the last one is measured: if it is strictly greater than holdSec, a pause is set after every atom of the series except the last. So the whole interval from the first to the last repeat becomes a pause.

Features and limitations

  • With the value 0 any repeat in a row becomes a pause: two identical atoms in a row are enough.
  • The duration of the last atom of a series is not included in the "time without changes": the difference of the start times of the first and the last atoms is used.
  • If an atom cannot compare values (by default SensorAtom treats values as unequal), the series consist of one atom and there are no pauses.
  • The formula is applicable to any sensor, but for slowly changing values (temperature, elevation) a small time gives many false pauses: the time must be chosen for the sensor.
  • The end point of the recording also takes part in the comparison as an ordinary atom.

Clone this wiki locally