timescaledb 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Fastfile +17 -0
- data/Gemfile.lock +2 -2
- data/README.md +41 -9
- data/bin/console +1 -1
- data/bin/tsdb +2 -2
- data/docs/command_line.md +178 -0
- data/docs/img/lttb_example.png +0 -0
- data/docs/img/lttb_sql_vs_ruby.gif +0 -0
- data/docs/img/lttb_zoom.gif +0 -0
- data/docs/index.md +61 -0
- data/docs/migrations.md +69 -0
- data/docs/models.md +78 -0
- data/docs/toolkit.md +394 -0
- data/docs/toolkit_lttb_tutorial.md +557 -0
- data/docs/toolkit_lttb_zoom.md +357 -0
- data/docs/videos.md +16 -0
- data/examples/all_in_one/all_in_one.rb +39 -5
- data/examples/all_in_one/benchmark_comparison.rb +108 -0
- data/examples/all_in_one/caggs.rb +93 -0
- data/examples/all_in_one/query_data.rb +78 -0
- data/examples/toolkit-demo/compare_volatility.rb +64 -0
- data/examples/toolkit-demo/lttb/README.md +15 -0
- data/examples/toolkit-demo/lttb/lttb.rb +92 -0
- data/examples/toolkit-demo/lttb/lttb_sinatra.rb +139 -0
- data/examples/toolkit-demo/lttb/lttb_test.rb +21 -0
- data/examples/toolkit-demo/lttb/views/index.erb +27 -0
- data/examples/toolkit-demo/lttb-zoom/README.md +13 -0
- data/examples/toolkit-demo/lttb-zoom/lttb_zoomable.rb +90 -0
- data/examples/toolkit-demo/lttb-zoom/views/index.erb +33 -0
- data/lib/timescaledb/acts_as_time_vector.rb +18 -0
- data/lib/timescaledb/dimensions.rb +1 -0
- data/lib/timescaledb/hypertable.rb +5 -1
- data/lib/timescaledb/job_stats.rb +1 -0
- data/lib/timescaledb/migration_helpers.rb +11 -0
- data/lib/timescaledb/schema_dumper.rb +1 -1
- data/lib/timescaledb/stats_report.rb +1 -1
- data/lib/timescaledb/toolkit/helpers.rb +20 -0
- data/lib/timescaledb/toolkit/time_vector.rb +66 -0
- data/lib/timescaledb/toolkit.rb +3 -0
- data/lib/timescaledb/version.rb +1 -1
- data/lib/timescaledb.rb +1 -0
- data/mkdocs.yml +33 -0
- metadata +31 -4
- data/examples/all_in_one/Gemfile +0 -11
- data/examples/all_in_one/Gemfile.lock +0 -51
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_record/connection_adapters/postgresql_adapter'
|
2
|
+
|
3
|
+
# Useful methods to run TimescaleDB with Toolkit functions in you Ruby app.
|
4
|
+
module Timescaledb
|
5
|
+
# Helpers methods to setup queries that uses the toolkit.
|
6
|
+
module Toolkit
|
7
|
+
module Helpers
|
8
|
+
|
9
|
+
# Includes toolkit_experimental in the search path to make it easy to have
|
10
|
+
# access to all the functions
|
11
|
+
def add_toolkit_to_search_path!
|
12
|
+
return if schema_search_path.include?("toolkit_experimental")
|
13
|
+
|
14
|
+
self.schema_search_path = "#{schema_search_path}, toolkit_experimental"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(Timescaledb::Toolkit::Helpers)
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Timescaledb
|
4
|
+
module Toolkit
|
5
|
+
module TimeVector
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def value_column
|
12
|
+
@value_column ||= time_vector_options[:value_column] || :val
|
13
|
+
end
|
14
|
+
|
15
|
+
def time_column
|
16
|
+
respond_to?(:time_column) && super || time_vector_options[:time_column]
|
17
|
+
end
|
18
|
+
def segment_by_column
|
19
|
+
time_vector_options[:segment_by]
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def define_default_scopes
|
25
|
+
scope :volatility, -> (segment_by: segment_by_column) do
|
26
|
+
select([*segment_by,
|
27
|
+
"timevector(#{time_column}, #{value_column}) -> sort() -> delta() -> abs() -> sum() as volatility"
|
28
|
+
].join(", "))
|
29
|
+
.group(segment_by)
|
30
|
+
end
|
31
|
+
|
32
|
+
scope :time_weight, -> (segment_by: segment_by_column) do
|
33
|
+
select([*segment_by,
|
34
|
+
"timevector(#{time_column}, #{value_column}) -> sort() -> delta() -> abs() -> time_weight() as time_weight"
|
35
|
+
].join(", "))
|
36
|
+
.group(segment_by)
|
37
|
+
end
|
38
|
+
|
39
|
+
scope :lttb, -> (threshold:, segment_by: segment_by_column, time: time_column, value: value_column) do
|
40
|
+
lttb_query = <<~SQL
|
41
|
+
WITH x AS ( #{select(*segment_by, time_column, value_column).to_sql})
|
42
|
+
SELECT #{"x.#{segment_by}," if segment_by}
|
43
|
+
(lttb( x.#{time_column}, x.#{value_column}, #{threshold})
|
44
|
+
-> toolkit_experimental.unnest()).*
|
45
|
+
FROM x
|
46
|
+
#{"GROUP BY device_id" if segment_by}
|
47
|
+
SQL
|
48
|
+
downsampled = unscoped
|
49
|
+
.select(*segment_by, "time as #{time_column}, value as #{value_column}")
|
50
|
+
.from("(#{lttb_query}) as x")
|
51
|
+
if segment_by
|
52
|
+
downsampled.inject({}) do |group,e|
|
53
|
+
key = e.send(segment_by)
|
54
|
+
(group[key] ||= []) << [e.send(time_column), e.send(value_column)]
|
55
|
+
group
|
56
|
+
end
|
57
|
+
else
|
58
|
+
downsampled.map{|e|[ e[time_column],e[value_column]]}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
data/lib/timescaledb/version.rb
CHANGED
data/lib/timescaledb.rb
CHANGED
@@ -2,6 +2,7 @@ require 'active_record'
|
|
2
2
|
|
3
3
|
require_relative 'timescaledb/acts_as_hypertable'
|
4
4
|
require_relative 'timescaledb/acts_as_hypertable/core'
|
5
|
+
require_relative 'timescaledb/toolkit'
|
5
6
|
require_relative 'timescaledb/chunk'
|
6
7
|
require_relative 'timescaledb/compression_settings'
|
7
8
|
require_relative 'timescaledb/continuous_aggregates'
|
data/mkdocs.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
site_name: The Timescaledb gem
|
2
|
+
repo_url: https://github.com/jonatas/timescaledb
|
3
|
+
edit_uri: edit/master/docs/
|
4
|
+
extra:
|
5
|
+
analytics:
|
6
|
+
provider: google
|
7
|
+
property: G-9B2BMB0TNQ
|
8
|
+
theme:
|
9
|
+
name: material
|
10
|
+
palette:
|
11
|
+
primary: indigo
|
12
|
+
accent: pink
|
13
|
+
markdown_extensions:
|
14
|
+
- admonition
|
15
|
+
- codehilite:
|
16
|
+
guess_lang: false
|
17
|
+
- toc:
|
18
|
+
permalink: true
|
19
|
+
- pymdownx.highlight:
|
20
|
+
anchor_linenums: true
|
21
|
+
- pymdownx.inlinehilite
|
22
|
+
- pymdownx.snippets
|
23
|
+
- pymdownx.superfences
|
24
|
+
|
25
|
+
nav:
|
26
|
+
- Introduction: index.md
|
27
|
+
- Migrations: migrations.md
|
28
|
+
- Models: models.md
|
29
|
+
- Toolkit Integration: toolkit.md
|
30
|
+
- Toolkit LTTB Tutorial: toolkit_lttb_tutorial.md
|
31
|
+
- Zooming with High Resolution: toolkit_lttb_zoom.md
|
32
|
+
- Command Line: command_line.md
|
33
|
+
- Videos: videos.md
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timescaledb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jônatas Davi Paganini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- ".tool-versions"
|
151
151
|
- ".travis.yml"
|
152
152
|
- CODE_OF_CONDUCT.md
|
153
|
+
- Fastfile
|
153
154
|
- Gemfile
|
154
155
|
- Gemfile.lock
|
155
156
|
- Gemfile.scenic
|
@@ -160,9 +161,21 @@ files:
|
|
160
161
|
- bin/console
|
161
162
|
- bin/setup
|
162
163
|
- bin/tsdb
|
163
|
-
-
|
164
|
-
-
|
164
|
+
- docs/command_line.md
|
165
|
+
- docs/img/lttb_example.png
|
166
|
+
- docs/img/lttb_sql_vs_ruby.gif
|
167
|
+
- docs/img/lttb_zoom.gif
|
168
|
+
- docs/index.md
|
169
|
+
- docs/migrations.md
|
170
|
+
- docs/models.md
|
171
|
+
- docs/toolkit.md
|
172
|
+
- docs/toolkit_lttb_tutorial.md
|
173
|
+
- docs/toolkit_lttb_zoom.md
|
174
|
+
- docs/videos.md
|
165
175
|
- examples/all_in_one/all_in_one.rb
|
176
|
+
- examples/all_in_one/benchmark_comparison.rb
|
177
|
+
- examples/all_in_one/caggs.rb
|
178
|
+
- examples/all_in_one/query_data.rb
|
166
179
|
- examples/ranking/.gitattributes
|
167
180
|
- examples/ranking/.gitignore
|
168
181
|
- examples/ranking/.ruby-version
|
@@ -212,9 +225,19 @@ files:
|
|
212
225
|
- examples/ranking/tmp/pids/.keep
|
213
226
|
- examples/ranking/tmp/storage/.keep
|
214
227
|
- examples/ranking/vendor/.keep
|
228
|
+
- examples/toolkit-demo/compare_volatility.rb
|
229
|
+
- examples/toolkit-demo/lttb-zoom/README.md
|
230
|
+
- examples/toolkit-demo/lttb-zoom/lttb_zoomable.rb
|
231
|
+
- examples/toolkit-demo/lttb-zoom/views/index.erb
|
232
|
+
- examples/toolkit-demo/lttb/README.md
|
233
|
+
- examples/toolkit-demo/lttb/lttb.rb
|
234
|
+
- examples/toolkit-demo/lttb/lttb_sinatra.rb
|
235
|
+
- examples/toolkit-demo/lttb/lttb_test.rb
|
236
|
+
- examples/toolkit-demo/lttb/views/index.erb
|
215
237
|
- lib/timescaledb.rb
|
216
238
|
- lib/timescaledb/acts_as_hypertable.rb
|
217
239
|
- lib/timescaledb/acts_as_hypertable/core.rb
|
240
|
+
- lib/timescaledb/acts_as_time_vector.rb
|
218
241
|
- lib/timescaledb/chunk.rb
|
219
242
|
- lib/timescaledb/compression_settings.rb
|
220
243
|
- lib/timescaledb/continuous_aggregates.rb
|
@@ -227,7 +250,11 @@ files:
|
|
227
250
|
- lib/timescaledb/scenic/extension.rb
|
228
251
|
- lib/timescaledb/schema_dumper.rb
|
229
252
|
- lib/timescaledb/stats_report.rb
|
253
|
+
- lib/timescaledb/toolkit.rb
|
254
|
+
- lib/timescaledb/toolkit/helpers.rb
|
255
|
+
- lib/timescaledb/toolkit/time_vector.rb
|
230
256
|
- lib/timescaledb/version.rb
|
257
|
+
- mkdocs.yml
|
231
258
|
- timescaledb.gemspec
|
232
259
|
homepage: https://github.com/jonatas/timescaledb
|
233
260
|
licenses:
|
data/examples/all_in_one/Gemfile
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ..
|
3
|
-
specs:
|
4
|
-
timescaledb (0.1.2)
|
5
|
-
activerecord
|
6
|
-
pg (~> 1.2)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activemodel (6.1.4.1)
|
12
|
-
activesupport (= 6.1.4.1)
|
13
|
-
activerecord (6.1.4.1)
|
14
|
-
activemodel (= 6.1.4.1)
|
15
|
-
activesupport (= 6.1.4.1)
|
16
|
-
activesupport (6.1.4.1)
|
17
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
-
i18n (>= 1.6, < 2)
|
19
|
-
minitest (>= 5.1)
|
20
|
-
tzinfo (~> 2.0)
|
21
|
-
zeitwerk (~> 2.3)
|
22
|
-
coderay (1.1.3)
|
23
|
-
composite_primary_keys (6.0.5)
|
24
|
-
activerecord (>= 4.0.0)
|
25
|
-
concurrent-ruby (1.1.9)
|
26
|
-
dotenv (2.7.6)
|
27
|
-
i18n (1.8.10)
|
28
|
-
concurrent-ruby (~> 1.0)
|
29
|
-
method_source (1.0.0)
|
30
|
-
minitest (5.14.4)
|
31
|
-
pg (1.2.3)
|
32
|
-
pry (0.14.0)
|
33
|
-
coderay (~> 1.1)
|
34
|
-
method_source (~> 1.0)
|
35
|
-
tzinfo (2.0.4)
|
36
|
-
concurrent-ruby (~> 1.0)
|
37
|
-
zeitwerk (2.4.2)
|
38
|
-
|
39
|
-
PLATFORMS
|
40
|
-
ruby
|
41
|
-
|
42
|
-
DEPENDENCIES
|
43
|
-
activerecord
|
44
|
-
composite_primary_keys (~> 6.0)
|
45
|
-
dotenv (~> 2.7)
|
46
|
-
pg
|
47
|
-
pry
|
48
|
-
timescaledb!
|
49
|
-
|
50
|
-
BUNDLED WITH
|
51
|
-
2.1.4
|