mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-19 09:22:12 +00:00
sparser data transfers
This commit is contained in:
1 parent
4583874e7e
commit
a07da16163
15 files changed
+22
-24
No files matched your search
@@ -527,6 +527,9 @@ impl TrackpointDetails {
|
|||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct SelectionPoint {
|
pub struct SelectionPoint {
|
||||||
|
/// Slope (%) at the trackpoint.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub slope: Option<f64>,
|
||||||
/// ms since the epoch.
|
/// ms since the epoch.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub time: Option<f64>,
|
pub time: Option<f64>,
|
||||||
|
|||||||
@@ -153,7 +153,6 @@ buffers!(
|
|||||||
total_distance,
|
total_distance,
|
||||||
elevation_gain,
|
elevation_gain,
|
||||||
elevation_loss,
|
elevation_loss,
|
||||||
slope,
|
|
||||||
lng,
|
lng,
|
||||||
lat,
|
lat,
|
||||||
ele
|
ele
|
||||||
@@ -202,6 +201,7 @@ pub fn selection_point<H: History>(engine: &Engine<H>, index: usize) -> Option<S
|
|||||||
let segment = stats.slope_segments.at(index);
|
let segment = stats.slope_segments.at(index);
|
||||||
let finite = |value: f64| value.is_finite().then_some(value);
|
let finite = |value: f64| value.is_finite().then_some(value);
|
||||||
Some(SelectionPoint {
|
Some(SelectionPoint {
|
||||||
|
slope: finite(stats.slope[index]),
|
||||||
time: stats
|
time: stats
|
||||||
.time
|
.time
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ macro_rules! f64_getters {
|
|||||||
)*};
|
)*};
|
||||||
}
|
}
|
||||||
|
|
||||||
f64_getters!(total_distance, slope, slope_segment_slopes, lng, lat, ele);
|
f64_getters!(total_distance, slope_segment_slopes, lng, lat, ele);
|
||||||
|
|
||||||
macro_rules! optional_f64_getters {
|
macro_rules! optional_f64_getters {
|
||||||
($($name:ident),*) => {$(
|
($($name:ident),*) => {$(
|
||||||
|
|||||||
@@ -145,7 +145,6 @@ fn register_commands<R: tauri::Runtime>(builder: tauri::Builder<R>) -> tauri::Bu
|
|||||||
queries::waypoint_coordinates,
|
queries::waypoint_coordinates,
|
||||||
// statistics
|
// statistics
|
||||||
statistics::total_distance,
|
statistics::total_distance,
|
||||||
statistics::slope,
|
|
||||||
statistics::slope_segment_starts,
|
statistics::slope_segment_starts,
|
||||||
statistics::slope_segment_slopes,
|
statistics::slope_segment_slopes,
|
||||||
statistics::lng,
|
statistics::lng,
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ macro_rules! stats_getter {
|
|||||||
stats_getter!(total_distance, Float64Array);
|
stats_getter!(total_distance, Float64Array);
|
||||||
stats_getter!(elevation_gain, Float64Array);
|
stats_getter!(elevation_gain, Float64Array);
|
||||||
stats_getter!(elevation_loss, Float64Array);
|
stats_getter!(elevation_loss, Float64Array);
|
||||||
stats_getter!(slope, Float64Array);
|
|
||||||
stats_getter!(lng, Float64Array);
|
stats_getter!(lng, Float64Array);
|
||||||
stats_getter!(lat, Float64Array);
|
stats_getter!(lat, Float64Array);
|
||||||
stats_getter!(ele, Float64Array);
|
stats_getter!(ele, Float64Array);
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ export interface TrackpointDetails {
|
|||||||
* Absent fields are unknown.
|
* Absent fields are unknown.
|
||||||
*/
|
*/
|
||||||
export interface SelectionPoint {
|
export interface SelectionPoint {
|
||||||
|
/** Slope (%) at the trackpoint. */
|
||||||
|
slope?: number;
|
||||||
/** ms since epoch */
|
/** ms since epoch */
|
||||||
time?: number;
|
time?: number;
|
||||||
/** Slope (%) and length (km) of the smoothed elevation segment of the trackpoint. */
|
/** Slope (%) and length (km) of the smoothed elevation segment of the trackpoint. */
|
||||||
|
|||||||
@@ -226,23 +226,25 @@ export class ElevationProfile {
|
|||||||
const details =
|
const details =
|
||||||
hovered?.index === point.index ? hovered.point : undefined;
|
hovered?.index === point.index ? hovered.point : undefined;
|
||||||
const elevationFill = get(this._elevationFill);
|
const elevationFill = get(this._elevationFill);
|
||||||
let slope = `${this._data.slope[point.index]?.toFixed(1)} %`;
|
|
||||||
if (
|
|
||||||
elevationFill === 'slope' &&
|
|
||||||
details?.slopeSegmentSlope !== undefined &&
|
|
||||||
details.slopeSegmentDistance !== undefined
|
|
||||||
) {
|
|
||||||
slope += ` (${getDistanceWithUnits(details.slopeSegmentDistance)} @${details.slopeSegmentSlope.toFixed(1)} %)`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let labels = [
|
let labels = [
|
||||||
` ${i18n._('quantities.distance')}: ${getDistanceWithUnits(point.x, false)}`,
|
` ${i18n._('quantities.distance')}: ${getDistanceWithUnits(point.x, false)}`,
|
||||||
` ${i18n._('quantities.slope')}: ${slope}`,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!details) {
|
if (!details) {
|
||||||
return labels;
|
return labels;
|
||||||
}
|
}
|
||||||
|
if (details.slope !== undefined) {
|
||||||
|
let slope = `${details.slope.toFixed(1)} %`;
|
||||||
|
if (
|
||||||
|
elevationFill === 'slope' &&
|
||||||
|
details.slopeSegmentSlope !== undefined &&
|
||||||
|
details.slopeSegmentDistance !== undefined
|
||||||
|
) {
|
||||||
|
slope += ` (${getDistanceWithUnits(details.slopeSegmentDistance)} @${details.slopeSegmentSlope.toFixed(1)} %)`;
|
||||||
|
}
|
||||||
|
labels.push(` ${i18n._('quantities.slope')}: ${slope}`);
|
||||||
|
}
|
||||||
let surface = details.surface ?? 'unknown';
|
let surface = details.surface ?? 'unknown';
|
||||||
let highway = details.highway ?? 'unknown';
|
let highway = details.highway ?? 'unknown';
|
||||||
let sacScale = details.sacScale;
|
let sacScale = details.sacScale;
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ async function point(index: number): Promise<SelectionPoint | undefined> {
|
|||||||
}
|
}
|
||||||
const segment = intervalAt(slopeSegmentStarts, index);
|
const segment = intervalAt(slopeSegmentStarts, index);
|
||||||
return {
|
return {
|
||||||
|
slope: data.slope[index],
|
||||||
time: data.timestamps[index],
|
time: data.timestamps[index],
|
||||||
slopeSegmentSlope: data.slopeSegmentSlopes[segment],
|
slopeSegmentSlope: data.slopeSegmentSlopes[segment],
|
||||||
slopeSegmentDistance: data.slopeSegmentDistances[segment],
|
slopeSegmentDistance: data.slopeSegmentDistances[segment],
|
||||||
@@ -66,7 +67,6 @@ export const exampleStatistics: SelectionStatistics = {
|
|||||||
global: data.global,
|
global: data.global,
|
||||||
length,
|
length,
|
||||||
totalDistance: Float64Array.from(data.totalDistance),
|
totalDistance: Float64Array.from(data.totalDistance),
|
||||||
slope: Float64Array.from(data.slope),
|
|
||||||
lng: Float64Array.from(data.lng),
|
lng: Float64Array.from(data.lng),
|
||||||
lat: Float64Array.from(data.lat),
|
lat: Float64Array.from(data.lat),
|
||||||
ele: Float64Array.from(data.ele),
|
ele: Float64Array.from(data.ele),
|
||||||
|
|||||||
@@ -178,7 +178,6 @@ export async function createTauriBackend(): Promise<Backend> {
|
|||||||
slice_statistics: async (start, end) =>
|
slice_statistics: async (start, end) =>
|
||||||
(await invoke('slice_statistics', { start, end })) ?? undefined,
|
(await invoke('slice_statistics', { start, end })) ?? undefined,
|
||||||
total_distance: () => f64('total_distance'),
|
total_distance: () => f64('total_distance'),
|
||||||
slope: () => f64('slope'),
|
|
||||||
lng: () => f64('lng'),
|
lng: () => f64('lng'),
|
||||||
lat: () => f64('lat'),
|
lat: () => f64('lat'),
|
||||||
ele: () => f64('ele'),
|
ele: () => f64('ele'),
|
||||||
|
|||||||
@@ -274,7 +274,6 @@ export interface Backend {
|
|||||||
selection_statistics(): Promise<GlobalStatistics | undefined>;
|
selection_statistics(): Promise<GlobalStatistics | undefined>;
|
||||||
slice_statistics(start: number, end: number): Promise<GlobalStatistics | undefined>;
|
slice_statistics(start: number, end: number): Promise<GlobalStatistics | undefined>;
|
||||||
total_distance(): Promise<Float64Array>;
|
total_distance(): Promise<Float64Array>;
|
||||||
slope(): Promise<Float64Array>;
|
|
||||||
lng(): Promise<Float64Array>;
|
lng(): Promise<Float64Array>;
|
||||||
lat(): Promise<Float64Array>;
|
lat(): Promise<Float64Array>;
|
||||||
ele(): Promise<Float64Array>;
|
ele(): Promise<Float64Array>;
|
||||||
|
|||||||
@@ -131,7 +131,6 @@ export async function createWasmBackend(): Promise<Backend> {
|
|||||||
selection_statistics: lift(w.selection_statistics),
|
selection_statistics: lift(w.selection_statistics),
|
||||||
slice_statistics: lift(w.slice_statistics),
|
slice_statistics: lift(w.slice_statistics),
|
||||||
total_distance: lift(w.total_distance),
|
total_distance: lift(w.total_distance),
|
||||||
slope: lift(w.slope),
|
|
||||||
lng: lift(w.lng),
|
lng: lift(w.lng),
|
||||||
lat: lift(w.lat),
|
lat: lift(w.lat),
|
||||||
ele: lift(w.ele),
|
ele: lift(w.ele),
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ describe('statistics', () => {
|
|||||||
const statistics = get(engine.statistics);
|
const statistics = get(engine.statistics);
|
||||||
const point = (await statistics.point(3))!;
|
const point = (await statistics.point(3))!;
|
||||||
assert.ok(point.slopeSegmentDistance! > 0);
|
assert.ok(point.slopeSegmentDistance! > 0);
|
||||||
|
assert.equal(typeof point.slope, 'number');
|
||||||
assert.equal(await statistics.point(statistics.length), undefined);
|
assert.equal(await statistics.point(statistics.length), undefined);
|
||||||
|
|
||||||
// only for the selection it was read for
|
// only for the selection it was read for
|
||||||
|
|||||||
@@ -46,10 +46,9 @@ export class StatisticsReader {
|
|||||||
private async read(backend: Backend): Promise<SelectionStatistics> {
|
private async read(backend: Backend): Promise<SelectionStatistics> {
|
||||||
const version = ++this._version;
|
const version = ++this._version;
|
||||||
this._loaded.clear();
|
this._loaded.clear();
|
||||||
const [global, totalDistance, slope, lng, lat, ele] = await Promise.all([
|
const [global, totalDistance, lng, lat, ele] = await Promise.all([
|
||||||
backend.selection_statistics(),
|
backend.selection_statistics(),
|
||||||
backend.total_distance(),
|
backend.total_distance(),
|
||||||
backend.slope(),
|
|
||||||
backend.lng(),
|
backend.lng(),
|
||||||
backend.lat(),
|
backend.lat(),
|
||||||
backend.ele(),
|
backend.ele(),
|
||||||
@@ -60,7 +59,6 @@ export class StatisticsReader {
|
|||||||
global: global ?? EMPTY_STATISTICS,
|
global: global ?? EMPTY_STATISTICS,
|
||||||
length: totalDistance.length,
|
length: totalDistance.length,
|
||||||
totalDistance,
|
totalDistance,
|
||||||
slope,
|
|
||||||
lng,
|
lng,
|
||||||
lat,
|
lat,
|
||||||
ele,
|
ele,
|
||||||
|
|||||||
@@ -209,8 +209,6 @@ export type SelectionStatistics = {
|
|||||||
/** Number of trackpoints. */
|
/** Number of trackpoints. */
|
||||||
length: number;
|
length: number;
|
||||||
totalDistance: Float64Array;
|
totalDistance: Float64Array;
|
||||||
/** Slope at the trackpoint. */
|
|
||||||
slope: Float64Array;
|
|
||||||
lng: Float64Array;
|
lng: Float64Array;
|
||||||
lat: Float64Array;
|
lat: Float64Array;
|
||||||
ele: Float64Array;
|
ele: Float64Array;
|
||||||
@@ -248,7 +246,6 @@ export const EMPTY_SELECTION_STATISTICS: SelectionStatistics = {
|
|||||||
global: EMPTY_STATISTICS,
|
global: EMPTY_STATISTICS,
|
||||||
length: 0,
|
length: 0,
|
||||||
totalDistance: new Float64Array(),
|
totalDistance: new Float64Array(),
|
||||||
slope: new Float64Array(),
|
|
||||||
lng: new Float64Array(),
|
lng: new Float64Array(),
|
||||||
lat: new Float64Array(),
|
lat: new Float64Array(),
|
||||||
ele: new Float64Array(),
|
ele: new Float64Array(),
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export async function computeExampleData() {
|
|||||||
movingTime: numbers(engine.moving_time()),
|
movingTime: numbers(engine.moving_time()),
|
||||||
elevationGain: numbers(engine.elevation_gain()),
|
elevationGain: numbers(engine.elevation_gain()),
|
||||||
elevationLoss: numbers(engine.elevation_loss()),
|
elevationLoss: numbers(engine.elevation_loss()),
|
||||||
slope: numbers(engine.slope()),
|
slope: points.map((point) => point.slope!),
|
||||||
slopeSegmentStarts,
|
slopeSegmentStarts,
|
||||||
slopeSegmentSlopes: numbers(engine.slope_segment_slopes()),
|
slopeSegmentSlopes: numbers(engine.slope_segment_slopes()),
|
||||||
// the length of each segment, which is the one of its trackpoints
|
// the length of each segment, which is the one of its trackpoints
|
||||||
|
|||||||
Reference in new issue
Block a user