Business intelligence made simple
Added experimental support for AnomalyDetection.rb
Andrew Kanec65f61c9d292
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2355f226..4a7e7bf5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,6 +1,7 @@## 2.5.0 (unreleased)- Added support for Slack OAuth tokens+- Added experimental support for AnomalyDetection.rb- Improved table preview for MySQL- Fixed cohort analysis for MySQLdiff --git a/Gemfile b/Gemfileindex 15e69b13..a49a4671 100644--- a/Gemfile+++ b/Gemfile@@ -15,5 +15,6 @@ gem "mysql2"gem "sqlite3"# anomaly detection and forecasting+gem "anomaly_detection" if ENV["TEST_ANOMALY_DETECTION"]gem "prophet-rb" if ENV["TEST_PROPHET"]gem "trend" if ENV["TEST_TREND"]diff --git a/README.md b/README.mdindex e71531fa..8f5d963b 100644--- a/README.md+++ b/README.md@@ -456,46 +456,20 @@ For the [self-hosted API](https://github.com/ankane/trend-api), create an initiaTrend.url = "http://localhost:8000"```-### R+### AnomalyDetection.rb (unreleased, experimental)-R uses Twitter’s [AnomalyDetection](https://github.com/twitter/AnomalyDetection) library.+Add [anomaly_detection](https://github.com/ankane/AnomalyDetection.rb) to your Gemfile:-First, [install R](https://cloud.r-project.org/). Then, run:--```R-install.packages("remotes")-remotes::install_github("twitter/AnomalyDetection")+```ruby+gem 'anomaly_detection'```And add to `config/blazer.yml`:```yml-anomaly_checks: r-```--If upgrading from version 1.4 or below, also follow the [upgrade instructions](#15).--If you’re on Heroku, follow the additional instructions below.--### R on Heroku--Add the [R buildpack](https://github.com/virtualstaticvoid/heroku-buildpack-r) to your app.--```sh-heroku buildpacks:add --index 1 https://github.com/virtualstaticvoid/heroku-buildpack-r.git+anomaly_checks: anomaly_detection```-And create an `init.R` with:--```r-if (!"AnomalyDetection" %in% installed.packages()) {- install.packages("remotes")- remotes::install_github("twitter/AnomalyDetection")-}-```--Commit and deploy away. The first deploy may take a few minutes.-## ForecastingBlazer supports for two different forecasting methods. [Example](https://blazer.dokkuapp.com/queries/18-forecast?forecast=t)diff --git a/lib/blazer/result.rb b/lib/blazer/result.rbindex 27490d41..8456ea7c 100644--- a/lib/blazer/result.rb+++ b/lib/blazer/result.rb@@ -189,6 +189,10 @@ module Blazerwhen "trend"anomalies = Trend.anomalies(Hash[series])anomalies.include?(series.last[0])+ when "anomaly_detection"+ period = 7 # TODO determine period+ anomalies = AnomalyDetection.detect(Hash[series], period: period)+ anomalies.include?(series.last[0])elsecsv_str =CSV.generate do |csv|diff --git a/lib/generators/blazer/templates/config.yml.tt b/lib/generators/blazer/templates/config.yml.ttindex eddde94e..66abf6cc 100644--- a/lib/generators/blazer/templates/config.yml.tt+++ b/lib/generators/blazer/templates/config.yml.tt@@ -63,7 +63,7 @@ check_schedules:# enable anomaly detection# note: with trend, time series are sent to https://trendapi.org-# anomaly_checks: prophet / trend / r+# anomaly_checks: prophet / trend / anomaly_detection# enable forecasting# note: with trend, time series are sent to https://trendapi.orgdiff --git a/test/checks_test.rb b/test/checks_test.rbindex c1f1ab7b..6832a924 100644--- a/test/checks_test.rb+++ b/test/checks_test.rb@@ -61,6 +61,12 @@ class ChecksTest < ActionDispatch::IntegrationTestassert_anomaly("trend")end+ def test_anomaly_anomaly_detection+ skip unless ENV["TEST_ANOMALY_DETECTION"]++ assert_anomaly("anomaly_detection")+ end+def test_emailsquery = create_querycheck = create_check(query: query, check_type: "bad_data", emails: "[email protected],[email protected]")