TimeWise
TimeWise is a Ruby gem for time series analysis and visualization. It offers intuitive tools for working with time-dependent data, perfect for e-commerce, healthcare, sports analytics, and more.
Features
- Core Statistical Functions: Calculate mean, median, standard deviation, variance, skewness, kurtosis, etc.
- Moving Averages: Simple, weighted, exponential, and advanced smoothing techniques
- Data Visualization: Basic visualization capabilities for analyzing trends
- Time Series Operations: Slicing, manipulating, and analyzing time-indexed data
Installation
Add this line to your application's Gemfile:
gem 'time_wise'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install time_wise
Usage
Creating a Time Series
require 'time_wise'
# Create a time series from an array of values
data = [100, 110, 120, 115, 125, 130, 140]
ts = TimeWise.create(data)
# With dates
dates = [
Date.new(2023, 1, 1),
Date.new(2023, 1, 2),
Date.new(2023, 1, 3),
Date.new(2023, 1, 4),
Date.new(2023, 1, 5),
Date.new(2023, 1, 6),
Date.new(2023, 1, 7)
]
ts_with_dates = TimeWise.create(data, dates)
# Load from CSV
ts_from_csv = TimeWise.load_csv('data.csv', 'value', 'date')
Basic Statistics
# Calculate basic statistics
mean = ts.stats.mean
median = ts.stats.median
std_dev = ts.stats.std_dev
# Get a summary of all statistics
summary = ts.stats.summary
puts summary[:mean]
puts summary[:std_dev]
# Calculate autocorrelation
acf = ts.stats.autocorrelation(5) # For lags 0-5
# Calculate correlation between two time series
correlation = ts1.stats.correlation(ts2)
Moving Averages
# Simple moving average with window size 3
sma = ts.moving_average.simple(3)
# Exponential moving average with alpha=0.2
ema = ts.moving_average.exponential(0.2)
# Weighted moving average with custom weights
weights = [0.1, 0.2, 0.3, 0.4]
wma = ts.moving_average.weighted(4, weights)
# Double exponential smoothing (Holt's method)
dema = ts.moving_average.double_exponential(0.2, 0.1)
Visualization
# Generate a line chart
ts.plot.line_chart(title: "My Time Series")
# Compare two time series
ts.plot.comparison_chart(another_ts, title: "Comparison")
# Export to CSV
ts.plot.export_csv("output.csv")
# Display data as a table
puts ts.plot.data_table(10) # Show first 10 rows
Coming Soon (in Future Releases)
- ARIMA Models: For advanced time series forecasting
- Seasonal Analysis: Tools for detecting and working with seasonal patterns
- Advanced Visualization: More chart types and interactive plotting
- Anomaly Detection: Methods for identifying outliers and unusual patterns
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/time_wise.
License
The gem is available as open source under the terms of the MIT License.