Skip to content

FitImportPlan

roosit edited this page Nov 15, 2026 · 1 revision

FitImportPlan

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

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

import com.velitask.plugin.official.processing.compress.SameValueCompress;
import com.velitask.plugin.official.processing.filters.BadPointFilter;
import com.velitask.plugin.official.processing.filters.CyclingPowerBadPointFilter;
import com.velitask.plugin.official.processing.filters.GeoBadPointFilter;
import com.velitask.plugin.official.processing.filters.HeartBadPointFilter;
import com.velitask.plugin.official.processing.filters.PowerBalanceBadPointFilter;
import com.velitask.plugin.official.processing.filters.SlopeBadPointFilter;
import com.velitask.plugin.official.processing.filters.SpeedBadPointFilter;
import com.velitask.plugin.official.processing.gaps.ExplicitGaps;
import com.velitask.plugin.official.processing.gaps.StepGaps;
import com.velitask.sdk.SensorType;
import com.velitask.sdk.scenario.ImportPlan;
import java.util.Map;

/* Import plan for FIT files. */
public final class FitImportPlan extends ImportPlan {

    /* Import format identifier. */
    public static final String FORMAT_ID = "fit";

    public FitImportPlan() {
        super(FORMAT_ID);
    }

    @Override
    protected void define() {
        /* Coordinates: jump rejection (not faster than 120 km/h, reset after a 30 s break), pauses from the file. */
        sensor(SensorType.GEO)
                .step(GeoBadPointFilter.NAME, Map.of(BadPointFilter.MAX_RATE, 120, BadPointFilter.RATE_RESET_SEC, 30))
                .step(ExplicitGaps.NAME)
                .step(SameValueCompress.NAME);
        /* Distance from the file: pauses from the file by the geo track. */
        sensor(SensorType.DISTANCE)
                .step(ExplicitGaps.NAME, track(SensorType.GEO))
                .step(SameValueCompress.NAME);
        sensor(SensorType.ELEVATION)
                .step(ExplicitGaps.NAME, track(SensorType.GEO))
                .step(SameValueCompress.NAME);
        /* Speed: rejection outside 0..120 km/h. */
        sensor(SensorType.SPEED)
                .step(SpeedBadPointFilter.NAME,
                        Map.of(BadPointFilter.USE_RANGE, true, BadPointFilter.MIN, 0, BadPointFilter.MAX, 120))
                .step(ExplicitGaps.NAME, track(SensorType.GEO))
                .step(SameValueCompress.NAME);
        /* Temperature is recorded less often: a pause is a gap of 60 s or more. */
        sensor(SensorType.TEMPERATURE)
                .step(StepGaps.NAME, Map.of(StepGaps.MIN_STEP_SEC, 60, StepGaps.STEP_FACTOR, 5), track(SensorType.GEO))
                .step(SameValueCompress.NAME);
        /* Heart rate: rejection outside 1..220 bpm. */
        sensor(SensorType.HEART)
                .step(HeartBadPointFilter.NAME,
                        Map.of(BadPointFilter.USE_RANGE, true, BadPointFilter.MIN, 1, BadPointFilter.MAX, 220))
                .step(ExplicitGaps.NAME, track(SensorType.GEO))
                .step(SameValueCompress.NAME);
        sensor(SensorType.CADENC)
                .step(ExplicitGaps.NAME, track(SensorType.GEO))
                .step(SameValueCompress.NAME);
        /* Power: spike rejection. */
        sensor(SensorType.CYCLING_POWER)
                .step(CyclingPowerBadPointFilter.NAME,
                        Map.of(BadPointFilter.WINDOW_SEC, 5, BadPointFilter.DEVIATION, 1000, BadPointFilter.FLOOR, 1500))
                .step(ExplicitGaps.NAME, track(SensorType.GEO))
                .step(SameValueCompress.NAME);
        /* Power balance: rejection outside 0..100 %. */
        sensor(SensorType.POWER_BALANCE)
                .step(PowerBalanceBadPointFilter.NAME,
                        Map.of(BadPointFilter.USE_RANGE, true, BadPointFilter.MIN, 0, BadPointFilter.MAX, 100))
                .step(ExplicitGaps.NAME, track(SensorType.GEO))
                .step(SameValueCompress.NAME);
        /* Pedalling metrics: only pauses from the file and compression. */
        sensor(SensorType.PEDAL_EFFICIENCY)
                .step(ExplicitGaps.NAME, track(SensorType.GEO))
                .step(SameValueCompress.NAME);
        sensor(SensorType.PEDAL_SMOOTHNESS)
                .step(ExplicitGaps.NAME, track(SensorType.GEO))
                .step(SameValueCompress.NAME);
        sensor(SensorType.PEDAL_DYNAMICS)
                .step(ExplicitGaps.NAME, track(SensorType.GEO))
                .step(SameValueCompress.NAME);
        /* The device grade is off by default: the user turns it on. */
        sensor(SensorType.GRADE).disabled()
                .step(ExplicitGaps.NAME, track(SensorType.GEO))
                .step(SameValueCompress.NAME);
        /* Computed distance and G-force: compression only. */
        computed(SensorType.DISTANCE)
                .step(SameValueCompress.NAME);
        computed(SensorType.GFORCE)
                .step(SameValueCompress.NAME);
        /* Computed slope is off by default; when turned on, rejection outside -45..45 %. */
        computed(SensorType.SLOPE).disabled()
                .step(SlopeBadPointFilter.NAME,
                        Map.of(BadPointFilter.USE_RANGE, true, BadPointFilter.MIN, -45, BadPointFilter.MAX, 45))
                .step(SameValueCompress.NAME);
    }
}

Purpose

Import plan for FIT activity files from watches and bike computers: the track and sensor readings (speed, heart rate, cadence, power, balance and pedalling dynamics, temperature, device grade), plus computed distance, G-force and slope.

The plan processes no data itself. It tells the application which steps (formulas) to apply to each sensor of the source, in what order and with which parameter values. The steps themselves are in the packages processing/gaps, processing/filters and processing/compress, and the list of plans is collected by BuiltinScenarios. The title and description of the format in the import settings are the strings Plugin.ImportPlan.fit.title ("FIT") and Plugin.ImportPlan.fit.description.

How it works

Data. The format identifier is "fit" (the FORMAT_ID constant), it is passed to the constructor of the base ImportPlan. The define() method declares the sensor scenarios in two ways: sensor(type) is a sensor that the source reads from the file, and computed(type) is a sensor that the application computes from others (the SensorType.GEO channel). .disabled() means the scenario is off by default, and the user can turn it on in the import settings. .step(name, values, bindings) adds a step: the name is the NAME of the step, Map.of(...) holds the parameter values, track(...) is the sensor that provides the geo track to a pause step, reference(...) is the reference sensor. A step without a Map takes the default values.

Almost everywhere ExplicitGaps ("Pauses from the file") is used; it does not look for new pauses and keeps the pauses of the format; the sensors other than the coordinates themselves take the geo track from track(SensorType.GEO). The exception is temperature: it uses StepGaps ("Pauses by recording gap").

Settings. The step values below are taken from the plan code; the units are as in the step parameter description (speed in km/h, distances in metres, time in seconds, balance and slope in percent, acceleration in mm/s², rotation in °/s).

Sensor Steps and values
Coordinates (GEO) "Bad GPS points": rate of change limit 120 km/h, reset after a break 30 s; "Pauses from the file"; "Data compression"
Distance from the file (DISTANCE) "Pauses from the file" (track is GEO); "Data compression"
Elevation (ELEVATION) "Pauses from the file" (track is GEO); "Data compression"
Speed (SPEED) "Bad speed points": limit check on, 0..120 km/h; "Pauses from the file"; "Data compression"
Temperature (TEMPERATURE) "Pauses by recording gap": minimal gap 60 s, factor 5, track is GEO; "Data compression"
Heart rate (HEART) "Bad heart rate points": limit check on, 1..220; "Pauses from the file"; "Data compression"
Cadence (CADENC) "Pauses from the file"; "Data compression"
Power (CYCLING_POWER) "Bad power points": window 5 s, deviation 1000, lower threshold 1500; "Pauses from the file"; "Data compression"
Power balance (POWER_BALANCE) "Bad power balance points": limit check on, 0..100; "Pauses from the file"; "Data compression"
Pedal efficiency, smoothness and dynamics (PEDAL_EFFICIENCY, PEDAL_SMOOTHNESS, PEDAL_DYNAMICS) for each: "Pauses from the file" (track is GEO); "Data compression"
Device grade (GRADE), off "Pauses from the file"; "Data compression"
Distance, computed (computed DISTANCE) "Data compression"
G-force, computed (computed GFORCE) "Data compression"
Slope, computed (computed SLOPE), off "Bad slope points": limit check on, -45..45; "Data compression"

The FIT plan has no smoothing and no drift zeroing.

Drawing. Not applicable: the plan only sets the order and the values of the processing.

Features and limitations

  • Distance is declared twice: sensor(DISTANCE) (the value from the file) and computed(DISTANCE) (computed by the application); the scenarios are independent.
  • Only the device grade (GRADE) and the computed slope are off by default; the other scenarios are on.
  • The two values of 120 are different parameters of different steps: the rate of change limit of the coordinates and the upper limit of the speed.
  • The user can change the values and turn scenarios on or off; the plan sets only the default values.
  • A public no-argument constructor is required: without it the user could not change the plan values in the settings. The class is final.

Clone this wiki locally