Struct TimeSeries

Source
pub struct TimeSeries {
    pub index: Vec<i64>,
    pub values: Array1<f64>,
}
Expand description

Time Series with normalized data

  • index - Index based on timestamp in millisecond resolution
  • values - Data points

Fields§

§index: Vec<i64>§values: Array1<f64>

Implementations§

Source§

impl TimeSeries

Source

pub fn empty() -> TimeSeries

Create empty Time Series

Source

pub fn new(index: Vec<i64>, values: Vec<f64>) -> TimeSeries

Create a new Time Series from from index and data

§Example
use timeseries::TimeSeries;

let index = vec![1, 2, 3, 4, 5];
let data = vec![1.0, 2.5, 3.2, 4.0, 3.0];
let ts = TimeSeries::new(index, data);
assert_eq!(ts.length(), 5);
Source

pub fn from_datapoints(datapoints: Vec<DataPoint>) -> TimeSeries

Create a new Time Series from from rows of tuples of timestamp and value

§Example
use timeseries::{TimeSeries, DataPoint};

let data = vec![DataPoint::new(1, 1.0), 
                DataPoint::new(2, 2.5), 
                DataPoint::new(3, 3.2), 
                DataPoint::new(4, 4.0), 
                DataPoint::new(5, 3.0)];
let ts = TimeSeries::from_datapoints(data);
assert_eq!(ts.length(), 5);
Source

pub fn length(&self) -> usize

Returns the number of elements in the series.

§Example
use timeseries::TimeSeries;

let index = vec![1, 2, 3, 4, 5];
let data = vec![1.0, 2.5, 3.2, 4.0, 3.0];
let ts = TimeSeries::new(index, data);
assert_eq!(ts.length(), 5);
Source

pub fn nth(&self, pos: usize) -> Option<DataPoint>

Return nth element of the series.

§Example
use timeseries::{TimeSeries, DataPoint};

let index = vec![1, 2, 3, 4, 5];
let data = vec![1.0, 2.5, 3.2, 4.0, 3.0];
let ts = TimeSeries::new(index, data);
assert_eq!(ts.nth(1), Some(DataPoint::new(2, 2.5)));
assert_eq!(ts.nth(10), None);
Source

pub fn at(&self, timestamp: i64) -> f64

Return element by its timestamp index. Or 0 if not found

§Example
use timeseries::TimeSeries;

let index = vec![100, 160, 220];
let data = vec![1.0, 2.5, 3.2];
let ts = TimeSeries::new(index, data);
assert_eq!(ts.at(10), 0.0);
assert_eq!(ts.at(110), 1.0);
assert_eq!(ts.at(165), 2.5);
assert_eq!(ts.at(500), 3.2);
Source

pub fn iter(&self) -> TimeSeriesIter<'_>

Create iterator

Source

pub fn merge(&self, other: &TimeSeries) -> TimeSeries

Merge 2 series. The resulting series will contain data points from both series If series contains data point with the same timestamp, then the value from first series is taken

§Example

Trait Implementations§

Source§

impl Clone for TimeSeries

Source§

fn clone(&self) -> TimeSeries

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TimeSeries

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TimeSeries

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromIterator<DataPoint> for TimeSeries

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = DataPoint>,

Creates a value from an iterator. Read more
Source§

impl PartialEq for TimeSeries

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.