use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TemporalEdge {
pub id: Uuid,
pub src: Uuid,
pub dst: Uuid,
pub relation: String,
pub valid_from: DateTime<Utc>,
pub valid_to: Option<DateTime<Utc>>,
pub confidence: f32,
pub recorded_at: DateTime<Utc>,
}
impl TemporalEdge {
pub fn new(
src: Uuid,
dst: Uuid,
relation: impl Into<String>,
valid_from: DateTime<Utc>,
valid_to: Option<DateTime<Utc>>,
confidence: f32,
) -> Self {
Self {
id: Uuid::now_v7(),
src,
dst,
relation: relation.into(),
valid_from,
valid_to,
confidence: confidence.clamp(0.0, 1.0),
recorded_at: Utc::now(),
}
}
pub fn valid_at(&self, as_of: DateTime<Utc>) -> bool {
if as_of < self.valid_from {
return false;
}
match self.valid_to {
None => true,
Some(end) => as_of < end,
}
}
}