use std::collections::BTreeMap;
use std::ops::RangeInclusive;
use chrono::{DateTime, FixedOffset};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TopologicalLocation {
pub netelement_id: String,
pub intrinsic: f64,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GeographicLocation {
pub latitude: f64,
pub longitude: f64,
pub crs: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PunctualDetection {
pub timestamp: DateTime<FixedOffset>,
pub location: Option<TopologicalLocation>,
pub coordinates: Option<GeographicLocation>,
pub intrinsic: Option<f64>,
pub id: Option<String>,
pub source: Option<String>,
pub source_file: String,
pub source_row: usize,
pub metadata: BTreeMap<String, String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct LinearDetection {
pub t_from: DateTime<FixedOffset>,
pub t_to: DateTime<FixedOffset>,
pub netelement_id: String,
pub start_intrinsic: f64,
pub end_intrinsic: f64,
pub id: Option<String>,
pub source: Option<String>,
pub source_file: String,
pub source_row: usize,
pub metadata: BTreeMap<String, String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum Detection {
Punctual(PunctualDetection),
Linear(LinearDetection),
}
impl Detection {
pub fn source_file(&self) -> &str {
match self {
Detection::Punctual(p) => &p.source_file,
Detection::Linear(l) => &l.source_file,
}
}
pub fn source_row(&self) -> usize {
match self {
Detection::Punctual(p) => p.source_row,
Detection::Linear(l) => l.source_row,
}
}
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum ResolvedAnchor {
Punctual {
netelement_id: String,
intrinsic: f64,
gnss_index: usize,
},
Linear {
netelement_id: String,
start_intrinsic: f64,
end_intrinsic: f64,
gnss_range: RangeInclusive<usize>,
},
}
impl ResolvedAnchor {
pub fn first_index(&self) -> usize {
match self {
ResolvedAnchor::Punctual { gnss_index, .. } => *gnss_index,
ResolvedAnchor::Linear { gnss_range, .. } => *gnss_range.start(),
}
}
pub fn netelement_id(&self) -> &str {
match self {
ResolvedAnchor::Punctual { netelement_id, .. }
| ResolvedAnchor::Linear { netelement_id, .. } => netelement_id,
}
}
}