Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions raphtory/src/db/api/properties/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
core::{ArcStr, Prop},
db::api::view::internal::Base,
};
use chrono::NaiveDateTime;
use enum_dispatch::enum_dispatch;

#[enum_dispatch]
Expand All @@ -10,6 +11,12 @@ pub trait TemporalPropertyViewOps {
self.temporal_values(id).last().cloned()
}
fn temporal_history(&self, id: usize) -> Vec<i64>;
fn temporal_history_date_time(&self, id: usize) -> Option<Vec<NaiveDateTime>> {
self.temporal_history(id)
.iter()
.map(|t| NaiveDateTime::from_timestamp_millis(*t))
.collect::<Option<Vec<NaiveDateTime>>>()
}
fn temporal_values(&self, id: usize) -> Vec<Prop>;
fn temporal_value_at(&self, id: usize, t: i64) -> Option<Prop> {
let history = self.temporal_history(id);
Expand Down Expand Up @@ -82,6 +89,10 @@ where
fn temporal_history(&self, id: usize) -> Vec<i64> {
self.base().temporal_history(id)
}
#[inline]
fn temporal_history_date_time(&self, id: usize) -> Option<Vec<NaiveDateTime>> {
self.base().temporal_history_date_time(id)
}

#[inline]
fn temporal_values(&self, id: usize) -> Vec<Prop> {
Expand Down
14 changes: 14 additions & 0 deletions raphtory/src/db/api/properties/temporal_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,26 @@ impl<P: PropertiesOps> TemporalPropertyView<P> {
pub fn history(&self) -> Vec<i64> {
self.props.temporal_history(self.id)
}
pub fn history_date_time(&self) -> Option<Vec<NaiveDateTime>> {
self.props.temporal_history_date_time(self.id)
}
pub fn values(&self) -> Vec<Prop> {
self.props.temporal_values(self.id)
}
pub fn iter(&self) -> impl Iterator<Item = (i64, Prop)> {
self.into_iter()
}

pub fn histories(&self) -> impl Iterator<Item = (i64, Prop)> {
self.iter()
}

pub fn histories_date_time(&self) -> Option<impl Iterator<Item = (NaiveDateTime, Prop)>> {
let hist = self.history_date_time()?;
let vals = self.values();
Some(hist.into_iter().zip(vals))
}

pub fn at(&self, t: i64) -> Option<Prop> {
self.props.temporal_value_at(self.id, t)
}
Expand Down
1 change: 1 addition & 0 deletions raphtory/src/db/api/view/internal/materialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::{
},
prelude::{Layer, Prop},
};
use chrono::NaiveDateTime;
use enum_dispatch::enum_dispatch;
use serde::{Deserialize, Serialize};
use std::path::Path;
Expand Down
7 changes: 7 additions & 0 deletions raphtory/src/db/graph/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ impl<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>> TemporalProperty
.map(|(t, _)| t)
.collect()
}
fn temporal_history_date_time(&self, id: usize) -> Option<Vec<NaiveDateTime>> {
self.graph
.temporal_edge_prop_vec(self.edge, id, self.graph.layer_ids())
.into_iter()
.map(|(t, _)| NaiveDateTime::from_timestamp_millis(t))
.collect::<Option<Vec<NaiveDateTime>>>()
}

fn temporal_values(&self, id: usize) -> Vec<Prop> {
let layer_ids = self.graph.layer_ids().constrain_from_edge(self.edge);
Expand Down
9 changes: 9 additions & 0 deletions raphtory/src/db/graph/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::{
prelude::*,
};

use chrono::NaiveDateTime;
use std::{
fmt,
hash::{Hash, Hasher},
Expand Down Expand Up @@ -210,6 +211,14 @@ impl<G, GH: TimeSemantics> TemporalPropertyViewOps for NodeView<G, GH> {
.collect()
}

fn temporal_history_date_time(&self, id: usize) -> Option<Vec<NaiveDateTime>> {
self.graph
.temporal_node_prop_vec(self.node, id)
.into_iter()
.map(|(t, _)| NaiveDateTime::from_timestamp_millis(t))
.collect::<Option<Vec<NaiveDateTime>>>()
}

fn temporal_values(&self, id: usize) -> Vec<Prop> {
self.graph
.temporal_node_prop_vec(self.node, id)
Expand Down
8 changes: 8 additions & 0 deletions raphtory/src/db/graph/views/window_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ use crate::{
},
prelude::GraphViewOps,
};
use chrono::NaiveDateTime;
use std::{
cmp::{max, min},
fmt::{Debug, Formatter},
Expand Down Expand Up @@ -125,6 +126,13 @@ impl<'graph, G: GraphViewOps<'graph>> TemporalPropertyViewOps for WindowedGraph<
.collect()
}

fn temporal_history_date_time(&self, id: usize) -> Option<Vec<NaiveDateTime>> {
self.temporal_prop_vec(id)
.into_iter()
.map(|(t, _)| NaiveDateTime::from_timestamp_millis(t))
.collect::<Option<Vec<NaiveDateTime>>>()
}

fn temporal_values(&self, id: usize) -> Vec<Prop> {
self.temporal_prop_vec(id)
.into_iter()
Expand Down
12 changes: 12 additions & 0 deletions raphtory/src/db/internal/temporal_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
core::{entities::graph::tgraph::InnerTemporalGraph, ArcStr, Prop},
db::api::properties::internal::{TemporalPropertiesOps, TemporalPropertyViewOps},
};
use chrono::NaiveDateTime;

impl<const N: usize> TemporalPropertyViewOps for InnerTemporalGraph<N> {
fn temporal_value(&self, id: usize) -> Option<Prop> {
Expand All @@ -17,6 +18,17 @@ impl<const N: usize> TemporalPropertyViewOps for InnerTemporalGraph<N> {
.unwrap_or_default()
}

fn temporal_history_date_time(&self, id: usize) -> Option<Vec<NaiveDateTime>> {
self.inner()
.get_temporal_prop(id)
.map(|prop| {
prop.iter()
.map(|(t, _)| NaiveDateTime::from_timestamp_millis(t))
.collect::<Option<Vec<NaiveDateTime>>>()
})
.unwrap_or_default()
}

fn temporal_values(&self, id: usize) -> Vec<Prop> {
self.inner()
.get_temporal_prop(id)
Expand Down
4 changes: 4 additions & 0 deletions raphtory/src/db/task/edge/eval_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ impl<
self.edge.temporal_history(id)
}

fn temporal_history_date_time(&self, id: usize) -> Option<Vec<NaiveDateTime>> {
self.edge.temporal_history_date_time(id)
}

fn temporal_values(&self, id: usize) -> Vec<Prop> {
self.edge.temporal_values(id)
}
Expand Down
30 changes: 30 additions & 0 deletions raphtory/src/python/graph/properties/temporal_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
utils::{PyGenericIterator, PyTime},
},
};
use chrono::NaiveDateTime;
use itertools::Itertools;
use pyo3::{
exceptions::{PyKeyError, PyTypeError},
Expand Down Expand Up @@ -121,6 +122,25 @@ impl PyTemporalProperties {
.collect()
}

/// Get the histories of all properties
///
/// Returns:
/// dict[str, list[(datetime, Any)]]: the mapping of property keys to histories
fn histories_date_time(&self) -> HashMap<ArcStr, Option<Vec<(NaiveDateTime, Prop)>>> {
self.props
.iter()
.map(|(k, v)| {
(
k.clone(),
match v.histories_date_time() {
None => None,
Some(history) => Some(history.collect()),
},
)
})
.collect()
}

/// __getitem__(key: str) -> TemporalProp
///
/// Get property value for `key`
Expand Down Expand Up @@ -213,6 +233,11 @@ impl PyTemporalProp {
self.prop.history()
}

/// Get the timestamps at which the property was updated
pub fn history_date_time(&self) -> Option<Vec<NaiveDateTime>> {
self.prop.history_date_time()
}

/// Get the property values for each update
pub fn values(&self) -> Vec<Prop> {
self.prop.values()
Expand All @@ -223,6 +248,11 @@ impl PyTemporalProp {
self.prop.iter().collect()
}

/// List update timestamps and corresponding property values
pub fn items_date_time(&self) -> Option<Vec<(NaiveDateTime, Prop)>> {
Some(self.prop.histories_date_time()?.collect())
}

/// Iterate over `items`
pub fn __iter__(&self) -> PyGenericIterator {
self.prop.iter().into()
Expand Down