blazer 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of blazer might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eedba409f17c85953be66d2b295f1857fb61de146d5c88288509440f419853e7
4
- data.tar.gz: ad0f8f433ad5be3052eb0237f86121c6a59147b2e240fb2a41d68611e69d3022
3
+ metadata.gz: 10aff02b2f4ebe93012af611e329c3a0a0be23c208d89d46db940c1bd21a97ed
4
+ data.tar.gz: b629339fcc448a079ce4759623a8906c9e4977435419ec2109c86a34d354f70a
5
5
  SHA512:
6
- metadata.gz: 8e4236c254472fb2bdc9a8cb107306d7263a11ade5b8f223cefc2363431f6f9ffeb7087d373a95823bf53112c9869871d132764232754898f8740c72ea01ceea
7
- data.tar.gz: bb12b6473ef4702adea12a9847ef020e0f8277d9714816cbfc511262345bffbbc8aa5530a7310dd4a263f634a493286f446bc8c4db48428f6c396109b2dce474
6
+ metadata.gz: ac3263567e689625741e0fa03a46fff1c1e8100f184245e130ed2e7b9b301173d5e8e6472a1fe6d5d7fb4e9bbc162ae2f3b4eeab5a14efc9bc7b59b605d96735
7
+ data.tar.gz: 800fa336c7c998345e0f1d047496ae7c6d39095714953d65a3ef5286b376da029fe885ae997afccb7f4adc86a3371e6658565e8bdd80cfb7bd7cb352fe64df72
@@ -1,27 +1,33 @@
1
- ## 2.2.1
1
+ ## 2.2.2 (2020-04-13)
2
+
3
+ - Added experimental support for the Socrata Open Data API (SODA)
4
+ - Added experimental Prophet forecasting
5
+ - Fixed query search for non-ASCII characters
6
+
7
+ ## 2.2.1 (2019-10-08)
2
8
 
3
9
  - Added support for Sprockets 4
4
10
  - Improved Snowflake table preview
5
11
  - Fixed bug with refresh link not showing
6
12
 
7
- ## 2.2.0
13
+ ## 2.2.0 (2019-07-12)
8
14
 
9
15
  - Added schema to table preview for Postgres and Redshift
10
16
  - Fixed bug with Slack notifications not sending
11
17
  - Dropped support for Rails 4.2
12
18
 
13
- ## 2.1.0
19
+ ## 2.1.0 (2019-06-04)
14
20
 
15
21
  - Require latest Chartkick to prevent possible XSS - see [#245](https://github.com/ankane/blazer/issues/245)
16
22
 
17
- ## 2.0.2
23
+ ## 2.0.2 (2019-05-26)
18
24
 
19
25
  - Added support for variable transformation for blind indexing
20
26
  - Added experimental support for Neo4j
21
27
  - Added experimental support for Salesforce
22
28
  - Fixed JavaScript sorting for numbers with commas
23
29
 
24
- ## 2.0.1
30
+ ## 2.0.1 (2019-01-07)
25
31
 
26
32
  - Added favicon
27
33
  - Added search for checks and schema
@@ -32,7 +38,7 @@
32
38
  - Improved docs for new installs
33
39
  - Fixed error with canceling queries
34
40
 
35
- ## 2.0.0
41
+ ## 2.0.0 (2019-01-03)
36
42
 
37
43
  - Added support for Slack
38
44
  - Added `async` option
@@ -45,68 +51,67 @@ Breaking changes
45
51
 
46
52
  - Dropped support for Rails < 4.2
47
53
 
48
- ## 1.9.0
54
+ ## 1.9.0 (2018-06-17)
49
55
 
50
56
  - Prompt developers to check custom `before_action`
51
57
  - Better ordering on home page
52
58
  - Added support for Snowflake
53
59
 
54
- ## 1.8.2
60
+ ## 1.8.2 (2018-02-22)
55
61
 
56
62
  - Added support for Cassandra
57
63
  - Fixes for Druid
58
-
59
- ## 1.8.1
60
-
61
64
  - Added support for Amazon Athena
62
65
  - Added support for Druid
63
66
  - Fixed query cancellation
64
67
 
65
- ## 1.8.0
68
+ There was no 1.8.1 release.
69
+
70
+ ## 1.8.0 (2017-05-01)
66
71
 
67
72
  - Added support for Rails 5.1
68
73
 
69
- ## 1.7.10
74
+ ## 1.7.10 (2017-04-03)
70
75
 
71
76
  - Added support for Google BigQuery
72
77
  - Require `drill-sergeant` gem for Apache Drill
73
78
  - Better handling of checks with variables
74
79
 
75
- ## 1.7.9
80
+ ## 1.7.9 (2017-03-20)
76
81
 
77
82
  - Added beta support for Apache Drill
78
83
  - Added email validation for checks
79
84
  - Updated Chart.js to 2.5.0
80
85
 
81
- ## 1.7.8
86
+ ## 1.7.8 (2017-02-06)
82
87
 
83
88
  - Added support for custom adapters
84
89
  - Fixed bug with scatter charts on dashboards
85
90
  - Fixed table preview for SQL Server
86
91
  - Fixed issue when `default_url_options` set
87
92
 
88
- ## 1.7.7
93
+ ## 1.7.7 (2016-12-17)
89
94
 
90
95
  - Fixed preview error for MySQL
91
96
  - Fixed error with timeouts for MySQL
92
97
 
93
- ## 1.7.6
98
+ ## 1.7.6 (2016-12-13)
94
99
 
95
100
  - Added scatter chart
96
101
  - Fixed issue with false values showing up blank
97
102
  - Fixed preview for table names with certain characters
98
103
 
99
- ## 1.7.5
104
+ ## 1.7.5 (2016-11-22)
100
105
 
101
106
  - Fixed issue with check emails sometimes failing for default Rails 5 ActiveJob adapter
102
107
  - Fixed sorting for new dashboards
103
108
 
104
- ## 1.7.4
109
+ ## 1.7.4 (2016-11-06)
105
110
 
106
111
  - Removed extra dependencies added in 1.7.1
107
112
  - Fixed `send_failing_checks` for default Rails 5 ActiveJob adapter
108
113
 
109
- ## 1.7.3
114
+ ## 1.7.3 (2016-11-01)
110
115
 
111
116
  - Fixed JavaScript errors
112
117
  - Fixed query cancel error
@@ -114,20 +119,20 @@ Breaking changes
114
119
  - Include sample data in email when bad data checks fail
115
120
  - Fixed deprecation warnings
116
121
 
117
- ## 1.7.2
122
+ ## 1.7.2 (2016-10-30)
118
123
 
119
124
  - Cancel all queries on page nav
120
125
  - Prevent Ace from taking over find command
121
126
  - Added ability to use hashes for smart columns
122
127
  - Added ability to inherit smart variables and columns from other data sources
123
128
 
124
- ## 1.7.1
129
+ ## 1.7.1 (2016-10-29)
125
130
 
126
131
  - Do not fork when enter key pressed
127
132
  - Use custom version of Chart.js to fix label overlap
128
133
  - Improved performance of home page
129
134
 
130
- ## 1.7.0
135
+ ## 1.7.0 (2016-09-07)
131
136
 
132
137
  - Added ability to cancel queries on backend for Postgres and Redshift
133
138
  - Only run 3 queries at a time on dashboards
@@ -135,65 +140,65 @@ Breaking changes
135
140
  - Attempt to reconnect when connection issues
136
141
  - Fixed issues with caching
137
142
 
138
- ## 1.6.2
143
+ ## 1.6.2 (2016-08-11)
139
144
 
140
145
  - Added basic query permissions
141
146
  - Added ability to use arrays and hashes for smart variables
142
147
  - Added cancel button for queries
143
148
  - Added `lat` and `lng` as map keys
144
149
 
145
- ## 1.6.1
150
+ ## 1.6.1 (2016-07-30)
146
151
 
147
152
  - Added support for Presto [beta]
148
153
  - Added support for Elasticsearch timeouts
149
154
  - Fixed error in Rails 5
150
155
 
151
- ## 1.6.0
156
+ ## 1.6.0 (2016-07-28)
152
157
 
153
158
  - Added support for MongoDB [beta]
154
159
  - Added support for Elasticsearch [beta]
155
160
  - Fixed deprecation warning in Rails 5
156
161
 
157
- ## 1.5.1
162
+ ## 1.5.1 (2016-07-24)
158
163
 
159
164
  - Added anomaly detection for data less than 2 weeks
160
165
  - Added autolinking urls
161
166
  - Added support for images
162
167
 
163
- ## 1.5.0
168
+ ## 1.5.0 (2016-06-29)
164
169
 
165
170
  - Added new bar chart format
166
171
  - Added anomaly detection checks
167
172
  - Added `async` option for polling
168
173
 
169
- ## 1.4.0
174
+ ## 1.4.0 (2016-06-09)
170
175
 
171
176
  - Added `slow` cache mode
172
177
  - Fixed `BLAZER_DATABASE_URL required` error
173
178
  - Fixed issue with duplicate column names
174
179
 
175
- ## 1.3.5
180
+ ## 1.3.5 (2016-05-11)
176
181
 
177
182
  - Fixed error with checks
178
183
 
179
- ## 1.3.4
184
+ ## 1.3.4 (2016-05-11)
180
185
 
181
186
  - Fixed issue with missing queries
182
187
 
183
- ## 1.3.3
188
+ ## 1.3.3 (2016-05-08)
184
189
 
185
190
  - Fixed error with Rails 4.1 and below
186
191
 
187
- ## 1.3.2
192
+ ## 1.3.2 (2016-05-07)
188
193
 
189
194
  - Added support for Rails 5
190
195
  - Attempt to reconnect for checks
191
196
 
192
- ## 1.3.1
197
+ ## 1.3.1 (2016-05-06)
193
198
 
194
199
  - Fixed migration error
195
200
 
196
- ## 1.3.0
201
+ ## 1.3.0 (2016-05-06)
197
202
 
198
203
  - Added schedule for checks
199
204
  - Switched to Chart.js for charts
@@ -202,11 +207,11 @@ Breaking changes
202
207
  - Raise error when timeout not supported
203
208
  - Added creator to dashboards and checks
204
209
 
205
- ## 1.2.1
210
+ ## 1.2.1 (2016-04-26)
206
211
 
207
212
  - Fixed checks
208
213
 
209
- ## 1.2.0
214
+ ## 1.2.0 (2016-03-22)
210
215
 
211
216
  - Added non-editable queries
212
217
  - Added variable defaults
@@ -215,7 +220,7 @@ Breaking changes
215
220
  - Hide variables from commented out lines
216
221
  - Fixed regex as variable names
217
222
 
218
- ## 1.1.1
223
+ ## 1.1.1 (2016-03-06)
219
224
 
220
225
  - Added `before_action` option
221
226
  - Added invert option for checks
@@ -224,7 +229,7 @@ Breaking changes
224
229
  - Fixed request URI too large
225
230
  - Prevent accidental backspace nav on query page
226
231
 
227
- ## 1.1.0
232
+ ## 1.1.0 (2015-12-27)
228
233
 
229
234
  - Replaced pie charts with column charts
230
235
  - Fixed error with datepicker
@@ -232,55 +237,55 @@ Breaking changes
232
237
  - Added a notice when editing a query that is part of a dashboard
233
238
  - Added refresh for dashboards
234
239
 
235
- ## 1.0.4
240
+ ## 1.0.4 (2015-11-04)
236
241
 
237
242
  - Added recently viewed queries and dashboards to home page
238
243
  - Fixed refresh when transform statement is used
239
244
  - Fixed error when no user model
240
245
 
241
- ## 1.0.3
246
+ ## 1.0.3 (2015-10-18)
242
247
 
243
248
  - Added maps
244
249
  - Added support for Rails 4.0
245
250
 
246
- ## 1.0.2
251
+ ## 1.0.2 (2015-10-11)
247
252
 
248
253
  - Fixed error when installing
249
254
  - Added `schemas` option
250
255
 
251
- ## 1.0.1
256
+ ## 1.0.1 (2015-10-08)
252
257
 
253
258
  - Added comments to queries
254
259
  - Added `cache` option
255
260
  - Added `user_method` option
256
261
  - Added `use_transaction` option
257
262
 
258
- ## 1.0.0
263
+ ## 1.0.0 (2015-10-04)
259
264
 
260
265
  - Added support for multiple data sources
261
266
  - Added dashboards
262
267
  - Added checks
263
268
  - Added support for Redshift
264
269
 
265
- ## 0.0.8
270
+ ## 0.0.8 (2015-09-05)
266
271
 
267
272
  - Easier to edit queries with variables
268
273
  - Dynamically expand editor height as needed
269
274
  - No need for spaces in search
270
275
 
271
- ## 0.0.7
276
+ ## 0.0.7 (2015-07-23)
272
277
 
273
278
  - Fixed error when no `User` class
274
279
  - Fixed forking a query with variables
275
280
  - Set time zone after Rails initializes
276
281
 
277
- ## 0.0.6
282
+ ## 0.0.6 (2015-06-18)
278
283
 
279
284
  - Added fork button
280
285
  - Fixed trending
281
286
  - Fixed time zones for date select
282
287
 
283
- ## 0.0.5
288
+ ## 0.0.5 (2015-01-31)
284
289
 
285
290
  - Added support for Rails 4.2
286
291
  - Fixed error with `mysql2` adapter
data/README.md CHANGED
@@ -4,9 +4,9 @@ Explore your data with SQL. Easily create charts and dashboards, and share them
4
4
 
5
5
  [Try it out](https://blazer.dokkuapp.com)
6
6
 
7
- [![Screenshot](https://blazer.dokkuapp.com/assets/screenshot-6ca3115a518b488026e48be83ba0d4c9.png)](https://blazer.dokkuapp.com)
7
+ [![Screenshot](https://blazer.dokkuapp.com/assets/blazer-90fb6ce8ad25614c6f9c3b4619cbfbd66fa3d6567dac34d83df540f6688665f1.png)](https://blazer.dokkuapp.com)
8
8
 
9
- Blazer 2.0 was recently released! See [instructions for upgrading](#20).
9
+ Blazer is also available as a [Docker image](https://github.com/ankane/blazer-docker).
10
10
 
11
11
  :tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
12
12
 
@@ -426,10 +426,32 @@ If you’re on Heroku, follow [these additional instructions](#anomaly-detection
426
426
 
427
427
  ## Forecasting
428
428
 
429
- Blazer has experimental support for forecasting through [Trend](https://trendapi.org/).
429
+ Blazer has experimental support for two different forecasting methods.
430
+
431
+ A forecast link will appear for queries that return 2 columns with types timestamp and numeric.
430
432
 
431
433
  [Example](https://blazer.dokkuapp.com/queries/18-forecast?forecast=t)
432
434
 
435
+ ### Prophet
436
+
437
+ **Note:** Prophet only supports daily forecasts right now.
438
+
439
+ Add [prophet](https://github.com/ankane/prophet) to your Gemfile:
440
+
441
+ ```ruby
442
+ gem 'prophet-rb'
443
+ ```
444
+
445
+ And add to `config/blazer.yml`:
446
+
447
+ ```yml
448
+ forecasting: prophet
449
+ ```
450
+
451
+ ### Trend
452
+
453
+ [Trend](https://trendapi.org/) uses an external service.
454
+
433
455
  Add [trend](https://github.com/ankane/trend) to your Gemfile:
434
456
 
435
457
  ```ruby
@@ -442,8 +464,6 @@ And add to `config/blazer.yml`:
442
464
  forecasting: trend
443
465
  ```
444
466
 
445
- A forecast link will appear for queries that return 2 columns with types timestamp and numeric.
446
-
447
467
  ## Data Sources
448
468
 
449
469
  Blazer supports multiple data sources :tada:
@@ -475,11 +495,12 @@ data_sources:
475
495
  - [IBM DB2 and Informix](#ibm-db2-and-informix)
476
496
  - [MongoDB](#mongodb-1)
477
497
  - [MySQL](#mysql-1)
478
- - [Neo4j](#neo4j-experimental)
498
+ - [Neo4j](#neo4j)
479
499
  - [Oracle](#oracle)
480
500
  - [PostgreSQL](#postgresql-1)
481
501
  - [Presto](#presto)
482
- - [Salesforce](#salesforce-experimental)
502
+ - [Salesforce](#salesforce)
503
+ - [Socrata Open Data API (SODA)](#socrata-open-data-api-soda)
483
504
  - [Snowflake](#snowflake)
484
505
  - [SQLite](#sqlite)
485
506
  - [SQL Server](#sql-server)
@@ -595,7 +616,9 @@ data_sources:
595
616
  url: mysql2://user:password@hostname:3306/database
596
617
  ```
597
618
 
598
- ### Neo4j [experimental]
619
+ ### Neo4j
620
+
621
+ *Experimental*
599
622
 
600
623
  Add [neo4j-core](https://github.com/neo4jrb/neo4j-core) to your Gemfile and set:
601
624
 
@@ -630,7 +653,9 @@ data_sources:
630
653
  url: presto://user@hostname:8080/catalog
631
654
  ```
632
655
 
633
- ### Salesforce [experimental]
656
+ ### Salesforce
657
+
658
+ *Experimental*
634
659
 
635
660
  Add [restforce](https://github.com/restforce/restforce) to your Gemfile and set:
636
661
 
@@ -653,6 +678,22 @@ SALESFORCE_API_VERSION="41.0"
653
678
 
654
679
  Supports [SOQL](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm)
655
680
 
681
+ ### Socrata Open Data API (SODA)
682
+
683
+ *Experimental [master]*
684
+
685
+ Set:
686
+
687
+ ```yml
688
+ data_sources:
689
+ my_source:
690
+ adapter: soda
691
+ url: https://soda.demo.socrata.com/resource/4tka-6guv.json
692
+ app_token: ...
693
+ ```
694
+
695
+ Supports [SoQL](https://dev.socrata.com/docs/functions/)
696
+
656
697
  ### Snowflake
657
698
 
658
699
  First, install ODBC. For Homebrew, use:
@@ -14,7 +14,7 @@ module Blazer
14
14
  def blazer_format_value(key, value)
15
15
  if value.is_a?(Numeric) && !key.to_s.end_with?("id") && !key.to_s.start_with?("id")
16
16
  number_with_delimiter(value)
17
- elsif value =~ BLAZER_URL_REGEX
17
+ elsif value.is_a?(String) && value =~ BLAZER_URL_REGEX
18
18
  # see if image or link
19
19
  if Blazer.images && (key.include?("image") || BLAZER_IMAGE_EXT.include?(value.split(".").last.split("?").first.try(:downcase)))
20
20
  link_to value, target: "_blank" do
@@ -71,7 +71,7 @@
71
71
  }
72
72
 
73
73
  var prepareQuery = function (str) {
74
- return str.toLowerCase().replace(/\W+/g, "")
74
+ return str.toLowerCase()
75
75
  }
76
76
 
77
77
  var app = new Vue({
@@ -80,7 +80,7 @@
80
80
  <%= blazer_js_var "mapboxAccessToken", Blazer.mapbox_access_token %>
81
81
  <%= blazer_js_var "markers", @markers %>
82
82
  L.mapbox.accessToken = mapboxAccessToken;
83
- var map = L.mapbox.map('map', 'ankane.ioo8nki0');
83
+ var map = L.mapbox.map('map', 'mapbox.streets');
84
84
  var featureLayer = L.mapbox.featureLayer().addTo(map);
85
85
  var geojson = [];
86
86
  for (var i = 0; i < markers.length; i++) {
@@ -11,8 +11,8 @@
11
11
  <%= blazer_js_var "rootPath", root_path %>
12
12
  </script>
13
13
  <% if blazer_maps? %>
14
- <%= stylesheet_link_tag "https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.css", integrity: "sha384-o8tecBIfqi9yU5yYK2Ne/9A9hlOGFV9MBvCpmemvJH1XxqOe6h8Bl4mLxMi6PgjG", crossorigin: "anonymous" %>
15
- <%= javascript_include_tag "https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.js", integrity: "sha384-j81LqvtvYigFzGSUgAoFijpvoq4yGoCJSOXI9DFaUEpenR029MBE3E/X5Gr+WdO0", crossorigin: "anonymous" %>
14
+ <%= stylesheet_link_tag "https://api.mapbox.com/mapbox.js/v3.2.1/mapbox.css", integrity: "sha384-vxzdEt+wZRPNQbhChjmiaFMLWg86IGuq1NGDehJHsD2mphYkxXll/eSs16WWi6Dq", crossorigin: "anonymous" %>
15
+ <%= javascript_include_tag "https://api.mapbox.com/mapbox.js/v3.2.1/mapbox.js", integrity: "sha384-dRMjy8ZlKk6czEwpaK3yySKItGPpGOplDM1+osgTwGhmxeTPpjB4kmRbDr2Y7lfQ", crossorigin: "anonymous" %>
16
16
  <% end %>
17
17
  <%= csrf_meta_tags %>
18
18
  </head>
@@ -22,6 +22,7 @@ require "blazer/adapters/mongodb_adapter"
22
22
  require "blazer/adapters/neo4j_adapter"
23
23
  require "blazer/adapters/presto_adapter"
24
24
  require "blazer/adapters/salesforce_adapter"
25
+ require "blazer/adapters/soda_adapter"
25
26
  require "blazer/adapters/sql_adapter"
26
27
  require "blazer/adapters/snowflake_adapter"
27
28
 
@@ -223,5 +224,6 @@ Blazer.register_adapter "neo4j", Blazer::Adapters::Neo4jAdapter
223
224
  Blazer.register_adapter "presto", Blazer::Adapters::PrestoAdapter
224
225
  Blazer.register_adapter "mongodb", Blazer::Adapters::MongodbAdapter
225
226
  Blazer.register_adapter "salesforce", Blazer::Adapters::SalesforceAdapter
227
+ Blazer.register_adapter "soda", Blazer::Adapters::SodaAdapter
226
228
  Blazer.register_adapter "sql", Blazer::Adapters::SqlAdapter
227
229
  Blazer.register_adapter "snowflake", Blazer::Adapters::SnowflakeAdapter
@@ -0,0 +1,96 @@
1
+ module Blazer
2
+ module Adapters
3
+ class SodaAdapter < BaseAdapter
4
+ def run_statement(statement, comment)
5
+ columns = []
6
+ rows = []
7
+ error = nil
8
+
9
+ # remove comments manually
10
+ statement = statement.gsub(/--.+/, "")
11
+ # only supports single line /* */ comments
12
+ # regex not perfect, but should be good enough
13
+ statement = statement.gsub(/\/\*.+\*\//, "")
14
+
15
+ # remove trailing semicolon
16
+ statement = statement.sub(/;\s*\z/, "")
17
+
18
+ # remove whitespace
19
+ statement = statement.squish
20
+
21
+ uri = URI(settings["url"])
22
+ uri.query = URI.encode_www_form("$query" => statement)
23
+
24
+ req = Net::HTTP::Get.new(uri)
25
+ req["X-App-Token"] = settings["app_token"] if settings["app_token"]
26
+
27
+ options = {
28
+ use_ssl: uri.scheme == "https",
29
+ open_timeout: 3,
30
+ read_timeout: 30
31
+ }
32
+
33
+ begin
34
+ # use Net::HTTP instead of soda-ruby for types and better error messages
35
+ res = Net::HTTP.start(uri.hostname, uri.port, options) do |http|
36
+ http.request(req)
37
+ end
38
+
39
+ if res.is_a?(Net::HTTPSuccess)
40
+ body = JSON.parse(res.body)
41
+
42
+ columns = JSON.parse(res["x-soda2-fields"])
43
+ column_types = columns.zip(JSON.parse(res["x-soda2-types"])).to_h
44
+
45
+ columns.reject! { |f| f.start_with?(":@") }
46
+ # rows can be missing some keys in JSON, so need to map by column
47
+ rows = body.map { |r| columns.map { |c| r[c] } }
48
+
49
+ columns.each_with_index do |column, i|
50
+ # nothing to do for boolean
51
+ case column_types[column]
52
+ when "number"
53
+ # check if likely an integer column
54
+ if rows.all? { |r| r[i].to_i == r[i].to_f }
55
+ rows.each do |row|
56
+ row[i] = row[i].to_i
57
+ end
58
+ else
59
+ rows.each do |row|
60
+ row[i] = row[i].to_f
61
+ end
62
+ end
63
+ when "floating_timestamp"
64
+ # check if likely a date column
65
+ if rows.all? { |r| r[i].end_with?("T00:00:00.000") }
66
+ rows.each do |row|
67
+ row[i] = Date.parse(row[i])
68
+ end
69
+ else
70
+ utc = ActiveSupport::TimeZone["Etc/UTC"]
71
+ rows.each do |row|
72
+ row[i] = utc.parse(row[i])
73
+ end
74
+ end
75
+ end
76
+ end
77
+ else
78
+ error = JSON.parse(res.body)["message"] rescue "Bad response: #{res.code}"
79
+ end
80
+ rescue => e
81
+ error = e.message
82
+ end
83
+
84
+ [columns, rows, error]
85
+ end
86
+
87
+ def preview_statement
88
+ "SELECT * LIMIT 10"
89
+ end
90
+
91
+ def tables
92
+ ["all"]
93
+ end
94
+ end
95
+ end
96
+ end
@@ -85,11 +85,45 @@ module Blazer
85
85
  @forecastable ||= Blazer.forecasting && column_types == ["time", "numeric"] && @rows.size >= 10
86
86
  end
87
87
 
88
+ # TODO cache it?
89
+ # don't want to put result data (even hashed version)
90
+ # into cache without developer opt-in
88
91
  def forecast
89
- # TODO cache it?
90
- # don't want to put result data (even hashed version)
91
- # into cache without developer opt-in
92
- forecast = Trend.forecast(Hash[@rows], count: 30)
92
+ count = (@rows.size * 0.25).round.clamp(30, 365)
93
+
94
+ case Blazer.forecasting
95
+ when "prophet"
96
+ require "prophet"
97
+
98
+ df =
99
+ Daru::DataFrame.new(
100
+ "ds" => @rows.map { |r| r[0] },
101
+ "y" => @rows.map { |r| r[1] }
102
+ )
103
+
104
+ # TODO determine frequency
105
+ freq = "D"
106
+
107
+ m = Prophet.new
108
+ m.fit(df)
109
+ future = m.make_future_dataframe(periods: count, freq: freq, include_history: false)
110
+ fcst = m.predict(future)
111
+ ds = fcst["ds"]
112
+ if @rows[0][0].is_a?(Date)
113
+ ds = ds.map { |v| v.to_date }
114
+ end
115
+ forecast = ds.zip(fcst["yhat"]).to_h
116
+ else
117
+ require "trend"
118
+
119
+ forecast = Trend.forecast(Hash[@rows], count: count)
120
+ end
121
+
122
+ # round integers
123
+ if @rows[0][1].is_a?(Integer)
124
+ forecast = forecast.map { |k, v| [k, v.round] }.to_h
125
+ end
126
+
93
127
  @rows.each do |row|
94
128
  row[2] = nil
95
129
  end
@@ -1,3 +1,3 @@
1
1
  module Blazer
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.2"
3
3
  end
@@ -67,7 +67,7 @@ check_schedules:
67
67
 
68
68
  # enable forecasting
69
69
  # note: with trend, time series are sent to https://trendapi.org
70
- # forecasting: trend
70
+ # forecasting: trend / prophet
71
71
 
72
72
  # enable map
73
73
  # mapbox_access_token: <%%= ENV["MAPBOX_ACCESS_TOKEN"] %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-09 00:00:00.000000000 Z
11
+ date: 2020-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -190,6 +190,7 @@ files:
190
190
  - lib/blazer/adapters/presto_adapter.rb
191
191
  - lib/blazer/adapters/salesforce_adapter.rb
192
192
  - lib/blazer/adapters/snowflake_adapter.rb
193
+ - lib/blazer/adapters/soda_adapter.rb
193
194
  - lib/blazer/adapters/sql_adapter.rb
194
195
  - lib/blazer/data_source.rb
195
196
  - lib/blazer/detect_anomalies.R
@@ -221,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
222
  - !ruby/object:Gem::Version
222
223
  version: '0'
223
224
  requirements: []
224
- rubygems_version: 3.0.3
225
+ rubygems_version: 3.1.2
225
226
  signing_key:
226
227
  specification_version: 4
227
228
  summary: Explore your data with SQL. Easily create charts and dashboards, and share