1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Path calculation metadata
use serde::{Deserialize, Serialize};
use crate::models::AssociatedNetElement;
/// Algorithm configuration and diagnostic metadata
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PathMetadata {
/// Distance scale parameter used for probability calculation
pub distance_scale: f64,
/// Heading scale parameter used for probability calculation
pub heading_scale: f64,
/// Cutoff distance for candidate selection (meters)
pub cutoff_distance: f64,
/// Heading difference cutoff (degrees)
pub heading_cutoff: f64,
/// Probability threshold for path segment inclusion
pub probability_threshold: f64,
/// Resampling distance applied (meters), None if disabled
pub resampling_distance: Option<f64>,
/// Whether fallback mode was used
pub fallback_mode: bool,
/// Number of candidate paths evaluated
pub candidate_paths_evaluated: usize,
/// Whether path existed in both directions (bidirectional validation)
pub bidirectional_path: bool,
/// Snapshot of segment-level diagnostics (order, intrinsics, probabilities)
#[serde(skip_serializing_if = "Option::is_none")]
pub diagnostic_info: Option<PathDiagnosticInfo>,
}
/// Collection of segment-level diagnostics for a calculated path
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PathDiagnosticInfo {
/// Ordered diagnostics per segment in the path
pub segments: Vec<SegmentDiagnostic>,
}
impl PathDiagnosticInfo {
/// Build diagnostics from associated netelements, preserving traversal order
pub fn from_segments(segments: &[AssociatedNetElement]) -> Self {
let segments = segments
.iter()
.map(|segment| SegmentDiagnostic {
netelement_id: segment.netelement_id.clone(),
probability: segment.probability,
start_intrinsic: segment.start_intrinsic,
end_intrinsic: segment.end_intrinsic,
gnss_start_index: segment.gnss_start_index,
gnss_end_index: segment.gnss_end_index,
})
.collect();
Self { segments }
}
}
/// Diagnostic details for a single segment in a train path
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SegmentDiagnostic {
/// ID of the netelement
pub netelement_id: String,
/// Probability assigned to this segment
pub probability: f64,
/// Intrinsic coordinate where the path enters this segment
pub start_intrinsic: f64,
/// Intrinsic coordinate where the path exits this segment
pub end_intrinsic: f64,
/// Index of the first GNSS position associated with this segment
pub gnss_start_index: usize,
/// Index of the last GNSS position associated with this segment
pub gnss_end_index: usize,
}
#[cfg(test)]
mod tests;