tp_lib_core/models/
detection.rs1use std::collections::BTreeMap;
9use std::ops::RangeInclusive;
10
11use chrono::{DateTime, FixedOffset};
12use serde::{Deserialize, Serialize};
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
16pub struct TopologicalLocation {
17 pub netelement_id: String,
19 pub intrinsic: f64,
21}
22
23#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
25pub struct GeographicLocation {
26 pub latitude: f64,
27 pub longitude: f64,
28 pub crs: String,
30}
31
32#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
37pub struct PunctualDetection {
38 pub timestamp: DateTime<FixedOffset>,
39 pub location: Option<TopologicalLocation>,
41 pub coordinates: Option<GeographicLocation>,
43 pub intrinsic: Option<f64>,
46 pub id: Option<String>,
48 pub source: Option<String>,
50 pub source_file: String,
52 pub source_row: usize,
54 pub metadata: BTreeMap<String, String>,
56}
57
58#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
60pub struct LinearDetection {
61 pub t_from: DateTime<FixedOffset>,
62 pub t_to: DateTime<FixedOffset>,
63 pub netelement_id: String,
64 pub start_intrinsic: f64,
65 pub end_intrinsic: f64,
66 pub id: Option<String>,
67 pub source: Option<String>,
68 pub source_file: String,
69 pub source_row: usize,
70 pub metadata: BTreeMap<String, String>,
71}
72
73#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
75#[serde(tag = "kind", rename_all = "lowercase")]
76pub enum Detection {
77 Punctual(PunctualDetection),
78 Linear(LinearDetection),
79}
80
81impl Detection {
82 pub fn source_file(&self) -> &str {
83 match self {
84 Detection::Punctual(p) => &p.source_file,
85 Detection::Linear(l) => &l.source_file,
86 }
87 }
88
89 pub fn source_row(&self) -> usize {
90 match self {
91 Detection::Punctual(p) => p.source_row,
92 Detection::Linear(l) => l.source_row,
93 }
94 }
95}
96
97#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
102pub enum ResolvedAnchor {
103 Punctual {
104 netelement_id: String,
105 intrinsic: f64,
106 gnss_index: usize,
107 },
108 Linear {
109 netelement_id: String,
110 start_intrinsic: f64,
111 end_intrinsic: f64,
112 gnss_range: RangeInclusive<usize>,
113 },
114}
115
116impl ResolvedAnchor {
117 pub fn first_index(&self) -> usize {
119 match self {
120 ResolvedAnchor::Punctual { gnss_index, .. } => *gnss_index,
121 ResolvedAnchor::Linear { gnss_range, .. } => *gnss_range.start(),
122 }
123 }
124
125 pub fn netelement_id(&self) -> &str {
127 match self {
128 ResolvedAnchor::Punctual { netelement_id, .. }
129 | ResolvedAnchor::Linear { netelement_id, .. } => netelement_id,
130 }
131 }
132}