Coder Social home page Coder Social logo

datastreams-rs's Introduction

DataStreams-RS

DataStreams-RS maintain sliding data stream with fixed BUCKET_SIZE_MS for fixed HISTORY_SIZE. Data structure initialize with INITIAL_TS.

Measurements older {max_ts} - BUCKET_SIZE_MS * HISTORY_SIZE will be skipped. Measurements newer {max_ts} (initially =INITIAL_TS) will move data frame to future and remove old data.

Data structure maintain single value for each bucket. New values for same bucket will override previous one.

Supported operations:

  • Initialization
  • Insert new value
  • Iteration
  • Boundary fetch
  • Aggregation with custom AGGREGATION_MS (expect that AGGREGATION_MS >> BUCKET_SIZE_MS)
    • aggregation_min
    • aggregation_max
    • aggregation_avg
    • custom Fn(&Vec<f64>) -> f64

Installation

cargo install datastreams-rs

Usage

const HISTORY_SIZE: usize = 10;
const BUCKET_SIZE_MS: u64 = 1_000;
const INITIAL_TS: u64 = 1_714_321_497_981;

fn main() {
    let mut data_stream: DataStream = create_data_stream(INITIAL_TS, HISTORY_SIZE, BUCKET_SIZE_MS);

    // insert new values
    data_stream.add_value(INITIAL_TS + 0 * BUCKET_SIZE_MS, 1f64);
    data_stream.add_value(INITIAL_TS + 1 * BUCKET_SIZE_MS, 2f64);
    data_stream.add_value(INITIAL_TS + 2 * BUCKET_SIZE_MS, 2f64);
    data_stream.add_value(INITIAL_TS + 3 * BUCKET_SIZE_MS, 2f64);

    // iterate over data stream
    for data_stream_value in data_stream.into_iter() {
        let _t = data_stream_value.timestamp;
        let _v = data_stream_value.value;

        println!("{_t}={_v}");
    }

    // aggregation
    const AGGREGATION_MS: u64 = 2 * BUCKET_SIZE_MS;
    let mut out: Vec<f64> = Vec::new();
    data_stream.agg(aggregation_min, AGGREGATION_MS, &mut out);
    data_stream.agg(aggregation_max, AGGREGATION_MS, &mut out);
    data_stream.agg(aggregation_avg, AGGREGATION_MS, &mut out);
}

Release notes

0.3.0

  • Remove generics data streams configuration

0.2.0

  • Add aggregations

0.1.0

  • Initial release

For developers

Evaluate this commands before commit:

cargo fmt
cargo clippy --all-targets --all-features -- -D warnings

Author

Mark Andreev ( linkedin.com/in/mrk-andreev; mrkandreev.name )

datastreams-rs's People

Contributors

mrk-andreev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.