Skip to content

SlopeGroupAtom

roosit edited this page Oct 16, 2026 · 2 revisions

SlopeGroupAtom

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

package com.velitask.plugin.official.slope;

/*
 * A row of the slope_groups table. The fields are public: the plugin reads them from the DB
 * by column name (SELECT *).
 */
public class SlopeGroupAtom {

    /* Primary key of the row. */
    public long id;
    /* The slope sensor the group belongs to. */
    public long sensor_id;

    /* Sequence number of the group within the sensor. */
    public int measureIndex;
    public long timeRaw;
    public long duration;

    /* Distance at the start of the group and its length (mm). */
    public long distance;
    public long distanceDelta;

    /* Elevation at the start of the group and its change over the group (mm). */
    public int elevation;
    public int elevationDelta;

    /* Elevation gain and elevation loss (negative) inside the group. */
    public int eleUp;
    public int eleDown;

    /* Slope type (-1 downhill, 0 flat, 1 uphill) and the percent multiplied by 100. */
    public int slopeType;
    public int slopePercent;
}

Purpose

SlopeGroupAtom is the row object of the slope_groups table in the plugin database. The result of SlopeGroup.buildAtom is written to the table, and the indicators read the rows back with a SELECT * query, mapping column names to public fields.

How it works

The table schema from src/main/resources/sql/setup/create.sql:

CREATE TABLE IF NOT EXISTS ${table:slope_groups} (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    sensor_id INTEGER NOT NULL,

    measureIndex INTEGER NOT NULL,
    timeRaw INTEGER NOT NULL,
    duration INTEGER NOT NULL,

    distance INTEGER NOT NULL,
    distanceDelta INTEGER NOT NULL,

    elevation INTEGER NOT NULL,
    elevationDelta INTEGER NOT NULL,

    eleUp INTEGER NOT NULL,
    eleDown INTEGER NOT NULL,

    slopeType INTEGER NOT NULL,
    slopePercent INTEGER NOT NULL
);

CREATE INDEX idx_slope_groups_sensor ON ${table:slope_groups} (sensor_id);
CREATE INDEX idx_slope_groups_distance ON ${table:slope_groups} (distance);
Field Column Meaning
id id Primary key, auto-increment.
sensor_id sensor_id The slope sensor the group belongs to.
measureIndex measureIndex Sequence number of the group within the sensor (from zero).
timeRaw, duration same Start of the group in source time and its duration.
distance, distanceDelta same Distance at the start of the group and its length, mm.
elevation, elevationDelta same Elevation at the start of the group and its change over the group, mm.
eleUp, eleDown same Sums of positive and negative elevation changes; eleDown is negative.
slopeType slopeType -1 downhill, 0 flat, 1 uphill.
slopePercent slopePercent Slope percent multiplied by 100.

Next to it, the same schema has a link table slope_atom_groups (atom_id PRIMARY KEY, group_id NOT NULL) with the index idx_slope_atom_groups_group: it links the rows of sensors_slope_data.data_id to a group, but it is not reflected in this class.

The tables are filled in VelitaskPlagin.onSourceImported: first the old groups of the sensor are deleted, then the new ones are inserted. The table is read by SlopeTextIndicator and SlopeChartIndicator.

Features and limitations

  • The class is a plain container without logic; the fields must stay public and match the column names, otherwise the mapping during SELECT * will not fill them.
  • The field name sensor_id deliberately has an underscore, as in the column.
  • The Java types (long, int) are narrower than the 64-bit SQLite INTEGER: elevations and percents must fit into int.
  • The indexes on sensor_id and distance are needed by the indicator queries (lookup by sensor and distance range).

Clone this wiki locally