2026-10-02 18:06:45 +02:00
|
|
|
use crate::statistics::{GlobalStatistics, Statistics, sum_options};
|
2026-09-24 20:55:30 +02:00
|
|
|
|
2026-10-01 18:42:31 +02:00
|
|
|
#[derive(Debug, Default)]
|
|
|
|
|
pub struct StatisticsBuffer {
|
2026-09-24 20:55:30 +02:00
|
|
|
pub total_distance: Vec<f64>,
|
2026-09-30 19:19:23 +02:00
|
|
|
pub moving_distance: Vec<f64>,
|
2026-10-02 18:06:45 +02:00
|
|
|
pub total_time: Vec<i32>,
|
|
|
|
|
pub moving_time: Vec<i32>,
|
2026-09-24 20:55:30 +02:00
|
|
|
pub speed: Vec<f64>,
|
|
|
|
|
pub elevation_gain: Vec<f64>,
|
|
|
|
|
pub elevation_loss: Vec<f64>,
|
|
|
|
|
pub slope: Vec<f64>,
|
|
|
|
|
pub slope_segment_slope: Vec<f64>,
|
|
|
|
|
pub slope_segment_distance: Vec<f64>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-01 18:42:31 +02:00
|
|
|
impl StatisticsBuffer {
|
2026-10-02 18:06:45 +02:00
|
|
|
pub fn update(&mut self, stats: &[&Statistics]) {
|
2026-09-24 20:55:30 +02:00
|
|
|
self.total_distance.clear();
|
2026-09-30 19:19:23 +02:00
|
|
|
self.moving_distance.clear();
|
2026-09-24 20:55:30 +02:00
|
|
|
self.total_time.clear();
|
|
|
|
|
self.moving_time.clear();
|
|
|
|
|
self.speed.clear();
|
|
|
|
|
self.elevation_gain.clear();
|
|
|
|
|
self.elevation_loss.clear();
|
|
|
|
|
self.slope.clear();
|
|
|
|
|
self.slope_segment_slope.clear();
|
|
|
|
|
self.slope_segment_distance.clear();
|
|
|
|
|
|
|
|
|
|
let mut cumul_stats = GlobalStatistics::default();
|
|
|
|
|
for stats in stats {
|
2026-09-30 19:19:23 +02:00
|
|
|
for trkpt_stats in stats.local.iter() {
|
|
|
|
|
self.total_distance
|
|
|
|
|
.push(cumul_stats.total_distance + trkpt_stats.total_distance);
|
|
|
|
|
self.moving_distance.push(
|
|
|
|
|
sum_options(cumul_stats.moving_distance, trkpt_stats.moving_distance)
|
|
|
|
|
.unwrap_or_default(),
|
|
|
|
|
);
|
|
|
|
|
self.total_time.push(
|
|
|
|
|
sum_options(cumul_stats.total_time(), trkpt_stats.total_time)
|
|
|
|
|
.unwrap_or_default(),
|
|
|
|
|
);
|
|
|
|
|
self.moving_time.push(
|
|
|
|
|
sum_options(cumul_stats.moving_time, trkpt_stats.moving_time)
|
|
|
|
|
.unwrap_or_default(),
|
|
|
|
|
);
|
|
|
|
|
self.speed.push(trkpt_stats.speed.unwrap_or_default());
|
|
|
|
|
self.elevation_gain
|
|
|
|
|
.push(cumul_stats.elevation_gain + trkpt_stats.elevation_gain);
|
|
|
|
|
self.elevation_loss
|
|
|
|
|
.push(cumul_stats.elevation_loss + trkpt_stats.elevation_loss);
|
|
|
|
|
self.slope.push(trkpt_stats.slope);
|
|
|
|
|
self.slope_segment_slope
|
|
|
|
|
.push(trkpt_stats.slope_segment.slope);
|
|
|
|
|
self.slope_segment_distance
|
|
|
|
|
.push(trkpt_stats.slope_segment.distance);
|
|
|
|
|
}
|
2026-09-24 20:55:30 +02:00
|
|
|
cumul_stats.merge(&stats.global);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|