GithubHelp home page GithubHelp logo

time_series_utils's Introduction

Table of Contents

  1. TimeSeries Library for Rust
    1. Table of Contents
    2. Installation
    3. Usage
    4. Features
    5. Highlight Feature: The map Method
      1. Using a Lambda Function
      2. Using a Named Function
      3. Changing the Type
    6. Contributing

TimeSeries Library for Rust

A simple and flexible TimeSeries library in Rust.

Table of Contents

  • Installation
  • Usage
  • Features
  • Contributing
  • License

Installation

To install the TimeSeries library, add the following line to your Cargo.toml:

Usage

Import the library and start using it like so:

extern crate time_series;

use time_series::TimeSeries;
use time_series::Variation; // if you want to use the variation methods like diff and pct_change

Here's a quick example that demonstrates how to create a new TimeSeries instance, add elements, and perform a map operation:

let mut ts = TimeSeries::new();
ts.push(1);
ts.push(2);
ts.push(3);

let new_ts = ts.map(|&x| x * 2);
println!("{:?}", new_ts); // Should print TimeSeries([2, 4, 6])

Features

  • Basic TimeSeries manipulation methods such as push, pop, len, is_empty, and slice.
  • Variation trait for statistical calculations like diff and pct_change.
  • Generic design allows for storing any type that implements the Clone trait.

Highlight Feature: The map Method

One of the key features of this TimeSeries library is the map method. This method allows you to transform a TimeSeries<T> into a TimeSeries<U> by applying a function f: &T -> U to each element in the series.

The function takes a closure or a named function that receives an immutable reference to the data point and should return a new data point of possibly a different type.

Using a Lambda Function

Here's how you can use it with a lambda function:

let mut ts = TimeSeries::new();
ts.push(1);
ts.push(2);
ts.push(3);

let new_ts = ts.map(|&x| x * 2);
println!("{:?}", new_ts);  // Should print TimeSeries([2, 4, 6])

Using a Named Function

You can also use a named function to achieve the same transformation:

fn transform(x: &i32) -> i32 {
    x * 2
}

let mut ts = TimeSeries::new();
ts.push(1);
ts.push(2);
ts.push(3);

let new_ts = ts.map(transform);
println!("{:?}", new_ts);  // Should print TimeSeries([2, 4, 6])

Changing the Type

You can even change the type of data stored in the TimeSeries:

let mut ts = TimeSeries::new();
ts.push(1);
ts.push(2);
ts.push(3);

let new_ts: TimeSeries<String> = ts.map(|&x| format!("Value: {}", x));
println!("{:?}", new_ts);  // Should print TimeSeries(["Value: 1", "Value: 2", "Value: 3"])

This feature makes it incredibly easy to convert time series data into various time series indices or to apply any kind of transformations needed for your specific use-case.

Contributing

Contributions are welcome! Please fork the repository and open a pull request with your changes, or open an issue for discussion.

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.