pub trait DataConnector: Sync + Debug {
    // Required methods
    fn fetch_series_data<'life0, 'life1, 'async_trait>(
        &'life0 self,
        data_id: &'life1 str,
        timespec: Timerange,
        num_leading_points: u8
    ) -> Pin<Box<dyn Future<Output = Result<SeriesCache, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn fetch_spatial_data<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        data_id: &'life1 str,
        polygon: &'life2 Polygon,
        timestamp: Timestamp
    ) -> Pin<Box<dyn Future<Output = Result<SpatialCache, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

Trait for pulling data from data sources

Uses async_trait. It is recommended to tag your implementation with the async_trait macro to avoid having to deal with pinning, futures, and lifetimes manually. This trait has two required methods:

  • fetch_series_data: fetch sequential data, i.e. from a time series
  • fetch_spatial_data: fetch data that is distributed spatially, at a single timestamp

Here is an example implementation that just returns dummy data:

use async_trait::async_trait;
use chronoutil::RelativeDuration;
use rove::data_switch::{self, *};

// You can use the receiver type to store anything that should persist
// between requests, i.e a connection pool
#[derive(Debug)]
struct TestDataSource;

#[async_trait]
impl DataConnector for TestDataSource {
    async fn fetch_series_data(
        &self,
        // This is the part of spatial_id after the colon. You can
        // define its format any way you like, and use it to
        // determine what to fetch from the data source.
        _data_id: &str,
        // The timerange in the series that data is needed from.
        _timespec: Timerange,
        // Some timeseries QC tests require extra data from before
        // the start of the timerange to function. ROVE determines
        // how many extra data points are needed, and passes that in
        // here.
        num_leading_points: u8,
    ) -> Result<SeriesCache, data_switch::Error> {
        // Here you can do whatever is need to fetch real data, whether
        // that's a REST request, SQL call, NFS read etc.

        Ok(SeriesCache {
            start_time: Timestamp(0),
            period: RelativeDuration::minutes(5),
            data: vec![Some(1.); 1],
            num_leading_points,
        })
    }

    async fn fetch_spatial_data(
        &self,
        _data_id: &str,
        // This `Vec` of `GeoPoint`s represents a polygon defining the
        // area in which data should be fetched. It can be left empty,
        // in which case the whole data set should be fetched
        _polygon: &Polygon,
        // Unix timestamp representing the time of the data to be fetched
        _timestamp: Timestamp,
    ) -> Result<SpatialCache, data_switch::Error> {
        // As above, calls to the data source to get real data go here

        Ok(SpatialCache::new(
            vec![1.; 1],
            vec![1.; 1],
            vec![1.; 1],
            vec![1.; 1],
        ))
    }
}

Some real implementations can be found in rove/met_connectors

Required Methods§

source

fn fetch_series_data<'life0, 'life1, 'async_trait>( &'life0 self, data_id: &'life1 str, timespec: Timerange, num_leading_points: u8 ) -> Pin<Box<dyn Future<Output = Result<SeriesCache, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

fetch sequential data, i.e. from a time series

source

fn fetch_spatial_data<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, data_id: &'life1 str, polygon: &'life2 Polygon, timestamp: Timestamp ) -> Pin<Box<dyn Future<Output = Result<SpatialCache, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

fetch data that is distributed spatially, at a single timestamp

Implementors§