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
48325e6016
commit
4583874e7e
23 files changed
+509
-229
No files matched your search
@@ -34,7 +34,3 @@ pub fn optional(array: Option<Vec<u8>>) -> Bytes {
|
||||
pub fn f64_bytes(values: &[f64]) -> Vec<u8> {
|
||||
values.iter().flat_map(|v| v.to_le_bytes()).collect()
|
||||
}
|
||||
|
||||
pub fn i64_bytes(values: &[i64]) -> Vec<u8> {
|
||||
values.iter().flat_map(|v| v.to_le_bytes()).collect()
|
||||
}
|
||||
@@ -17,15 +17,7 @@ macro_rules! f64_getters {
|
||||
)*};
|
||||
}
|
||||
|
||||
f64_getters!(
|
||||
total_distance,
|
||||
slope,
|
||||
slope_segment_slope,
|
||||
slope_segment_distance,
|
||||
lng,
|
||||
lat,
|
||||
ele
|
||||
);
|
||||
f64_getters!(total_distance, slope, slope_segment_slopes, lng, lat, ele);
|
||||
|
||||
macro_rules! optional_f64_getters {
|
||||
($($name:ident),*) => {$(
|
||||
@@ -38,10 +30,16 @@ macro_rules! optional_f64_getters {
|
||||
|
||||
optional_f64_getters!(speed, hr, cad, atemp, power);
|
||||
|
||||
/// Timestamps in milliseconds since the epoch (`NO_TIME` when missing), as `i64`.
|
||||
/// The index of the first trackpoint of each smoothed elevation segment of the selection.
|
||||
#[tauri::command(async)]
|
||||
pub fn timestamps(state: State<AppState>) -> Bytes {
|
||||
optional(state.read(|e| api::timestamps(e).map(i64_bytes)))
|
||||
pub fn slope_segment_starts(state: State<AppState>) -> Bytes {
|
||||
u32s(&state.read(|e| api::slope_segment_starts(e).to_vec()))
|
||||
}
|
||||
|
||||
/// What the buffers do not hold for each trackpoint of the selection, for the one at `index`.
|
||||
#[tauri::command(async)]
|
||||
pub fn selection_point(state: State<AppState>, index: usize) -> Option<api::SelectionPoint> {
|
||||
state.read(move |e| api::selection_point(e, index))
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
|
||||
+3
-3
@@ -146,8 +146,8 @@ fn register_commands<R: tauri::Runtime>(builder: tauri::Builder<R>) -> tauri::Bu
|
||||
// statistics
|
||||
statistics::total_distance,
|
||||
statistics::slope,
|
||||
statistics::slope_segment_slope,
|
||||
statistics::slope_segment_distance,
|
||||
statistics::slope_segment_starts,
|
||||
statistics::slope_segment_slopes,
|
||||
statistics::lng,
|
||||
statistics::lat,
|
||||
statistics::ele,
|
||||
@@ -156,7 +156,7 @@ fn register_commands<R: tauri::Runtime>(builder: tauri::Builder<R>) -> tauri::Bu
|
||||
statistics::cad,
|
||||
statistics::atemp,
|
||||
statistics::power,
|
||||
statistics::timestamps,
|
||||
statistics::selection_point,
|
||||
statistics::selection_statistics,
|
||||
statistics::slice_statistics,
|
||||
statistics::surface_starts,
|
||||
|
||||
@@ -142,6 +142,18 @@ fn reads_the_statistics_of_the_selection() {
|
||||
// optional arrays start with a byte telling whether they are there
|
||||
let hr = app.bytes("hr", json!({}));
|
||||
assert_eq!(hr[0], 0);
|
||||
// the slope segments are intervals of trackpoints
|
||||
let starts = app.bytes("slope_segment_starts", json!({}));
|
||||
let slopes = f64s(&app.bytes("slope_segment_slopes", json!({})));
|
||||
assert_eq!(starts.len() / 4, slopes.len());
|
||||
assert!(!slopes.is_empty() && slopes.len() < distance.len());
|
||||
let point = app.call("selection_point", json!({ "index": 1 }));
|
||||
assert!(point["slopeSegmentDistance"].is_number());
|
||||
assert!(point.get("time").is_none());
|
||||
assert_eq!(
|
||||
app.call("selection_point", json!({ "index": distance.len() })),
|
||||
Value::Null
|
||||
);
|
||||
assert!(
|
||||
app.call("slice_statistics", json!({ "start": 1, "end": 3 }))["totalDistance"].is_number()
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user