Repository navigation
FollowGaps
Up | Previous | Next | Русский
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 FollowGaps.java: the production code stays clean and the explanations live in the wiki.
package com.velitask.plugin.official.processing.gaps;
import com.velitask.sdk.data.SensorAtom;
import com.velitask.sdk.scenario.GapInput;
import com.velitask.sdk.scenario.GapsStep;
import com.velitask.sdk.scenario.IStepControl;
import com.velitask.sdk.scenario.NeighborInput;
import java.util.Arrays;
import java.util.List;
/* Formula "Pauses as in the reference sensor": repeats the pauses of another sensor of the same source. */
public final class FollowGaps extends GapsStep<SensorAtom> {
/* Stable step name; localization keys Plugin.ImportStep.followGaps.* */
public static final String NAME = "followGaps";
public FollowGaps() {
super(NAME, 1, SensorAtom.class);
}
@Override
/* Input roles: the geotrack for describing a pause and the reference sensor whose pauses are repeated. */
public String[] inputRoles() {
return new String[]{TRACK, REFERENCE};
}
@Override
/* Without a reference sensor there are no pauses. */
protected boolean[] detect(GapInput<SensorAtom> input, IStepControl control) {
long[] times = input.times();
boolean[] pauseAfter = new boolean[times.length];
/* The result of the sensor that the scenario attached to the reference role. */
NeighborInput reference = input.neighbor(REFERENCE);
if (reference == null) {
return pauseAfter;
}
/* Recording segments of the reference sensor: there is a pause between neighbouring segments. */
List<List<SensorAtom>> segments = SensorAtom.splitSegments(Arrays.asList(reference.atoms()));
int next = 0;
for (int s = 0; s + 1 < segments.size(); s++) {
List<SensorAtom> segment = segments.get(s);
/* A pause of the reference: from the end of its last atom to the start of the first atom of the next segment. */
long pauseFrom = segment.get(segment.size() - 1).getNextTimeRaw();
long pauseTo = segments.get(s + 1).get(0).timeRaw;
/* We stand on the last own atom that started not later than the start of the pause. */
while (next < times.length - 1 && times[next + 1] <= pauseFrom) {
next++;
}
/* A pause after every atom that started before the end of the reference pause. */
for (int i = next; i < times.length - 1 && times[i] < pauseTo; i++) {
pauseAfter[i] = true;
}
}
return pauseAfter;
}
}FollowGaps is the "Pauses as in the reference sensor" formula (followGaps): it repeats the pauses of another sensor of the same source, so that the recordings break off at the same time. A typical case is a sensor that does not mark pauses itself, while the reference is a sensor with known stops. The formula is registered in BuiltinScenarios, but no built-in scenario uses it: it is chosen in custom scenarios, with the reference role attached.
Data. The formula takes the result of the reference sensor, input.neighbor(REFERENCE), and divides its atoms into recording segments with the SensorAtom.splitSegments(...) method: a new segment starts where an atom does not continue the previous one (it starts no later than it or has a different segmentStart). A pause of the reference sensor is the interval between neighbouring segments: from the end of the last atom of the first segment (getNextTimeRaw()) to the timeRaw of the first atom of the next one.
Parameters. The formula has no parameters of its own; the common parameter "Stood if moved less than, m" (stoodMeters, default 30) remains. The input roles are track (inherited from GapsStep) and reference; inputRoles() returns both.
Algorithm. For every pause of the reference sensor the pointer over the own atoms stands on the last atom that started no later than the start of the pause. Then a pause is set after every own atom, starting from it and onwards, as long as the atom started before the end of the reference pause (the last atom of the array is skipped). The own atoms inside the reference pause are thus separated from each other, and the atom that was running at the moment it started is completed.
- If the reference sensor is not attached or the source has none,
neighbor(REFERENCE)returnsnulland the formula adds no pauses. - If the atoms of the reference sensor form one continuous segment, there are no pauses either.
- The time is matched by the raw time of the atoms (
timeRaw) without interpolation: the pause boundary is bound to the boundaries of the own atoms. - The base class keeps the pauses from the file and the manual ones separately, as for the other formulas.