influxer 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9ee310f2d14e4f751007c7631ac2100b6bf32ac
4
- data.tar.gz: cabdf7aff563d6ff739bf87dade3dd854902a215
3
+ metadata.gz: a9483ba238ca5ac211fc174ae7dd81c49fd5aa08
4
+ data.tar.gz: 1915d412dc2bd255e4460e7448d8e007ec9dadf2
5
5
  SHA512:
6
- metadata.gz: 74c94e618b70f37cfd7ae18ab5c7d7f0b15ab812173edfe5e5a23a1707c8b2e9bbeb3abdd931e739a762829f5666d8cedfe6dc8a5a26bdcd2ecb8e695816cdc6
7
- data.tar.gz: cf738ba3405153292bfd23336a81e2cff9cba551de404551bc6dd646271e529b4b3b03698107cfbc97c11495302028cacc2bef846cdb434daf9c9c4a38e9d0e4
6
+ metadata.gz: ba9f6fc956de4fbf97e30a4f7dcf2ed248082ef4f1260ae18080b6cfd4d606239a3bc82346cfe815b77d355fe739ca2fecfb61ee8ed0ff5f037f7f900283ebea
7
+ data.tar.gz: 89bf51a352e1c83bf5a02d793aa7d43c820dbbc3275ef0447f6195d7c15fe5d94242989e2f75f728b575a3de8c58d71702163776887964ddfd2f547c9ec68d24
data/.hound.yml ADDED
@@ -0,0 +1,2 @@
1
+ ruby:
2
+ enabled: true
data/influxer.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_runtime_dependency "rails", '~> 4.0'
19
19
  s.add_dependency "influxdb", "~> 0.1.0", ">= 0.1.8"
20
- s.add_dependency "anyway_config", "~> 0.3"
20
+ s.add_dependency "anyway_config", "~> 0.4"
21
21
 
22
22
  s.add_development_dependency "timecop"
23
23
  s.add_development_dependency "simplecov", ">= 0.3.8"
data/lib/influxer.rb CHANGED
@@ -4,7 +4,6 @@ module Influxer
4
4
  require 'influxer/config'
5
5
  require 'influxer/client'
6
6
  require 'influxer/metrics/metrics'
7
- require 'influxer/metrics/relation'
8
7
 
9
8
  module Model
10
9
  require 'influxer/model'
@@ -1,3 +1,4 @@
1
+ require 'influxer/metrics/relation'
1
2
  require 'influxer/metrics/scoping'
2
3
  require 'influxer/metrics/fanout'
3
4
 
@@ -17,7 +18,13 @@ module Influxer
17
18
 
18
19
  class << self
19
20
  # delegate query functions to all
20
- delegate :write, :select, :where, :group, :merge, :time, :past, :since, :limit, :fill, :delete_all, to: :all
21
+ delegate *(
22
+ [
23
+ :write, :select, :where, :group,
24
+ :merge, :time, :past, :since, :limit,
25
+ :fill, :delete_all
26
+ ]+Influxer::Calculations::CALCULATION_METHODS),
27
+ to: :all
21
28
 
22
29
  def attributes(*attrs)
23
30
  attrs.each do |name|
@@ -1,5 +1,6 @@
1
1
  require 'influxer/metrics/relation/time_query'
2
2
  require 'influxer/metrics/relation/fanout_query'
3
+ require 'influxer/metrics/relation/calculations'
3
4
 
4
5
  module Influxer
5
6
  class Relation
@@ -7,6 +8,7 @@ module Influxer
7
8
 
8
9
  include Influxer::TimeQuery
9
10
  include Influxer::FanoutQuery
11
+ include Influxer::Calculations
10
12
 
11
13
  MULTI_VALUE_METHODS = [:select, :where, :group]
12
14
 
@@ -0,0 +1,21 @@
1
+ module Influxer
2
+ module Calculations
3
+ CALCULATION_METHODS =
4
+ [
5
+ :count, :min, :max, :mean,
6
+ :mode, :median, :distinct, :derivative,
7
+ :stddev, :sum, :first, :last, :difference,
8
+ :percentile, :histogram, :top, :bottom
9
+ ]
10
+
11
+ CALCULATION_METHODS.each do |name|
12
+ class_eval <<-CODE, __FILE__, __LINE__ + 1
13
+ def #{name}(val, option=nil) # def count(val)
14
+ @values[:has_calculations] = true # @values[:has_calculations] = true
15
+ select_values << "#{name}(\#\{val\}\#\{option ? ','+option.to_s : ''\})" # select_values << "count(\#\{val\})"
16
+ self # self
17
+ end # end
18
+ CODE
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Influxer
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -25,7 +25,7 @@ describe Influxer::Relation do
25
25
  specify { expect(rel).to respond_to :to_sql }
26
26
 
27
27
 
28
- describe "merge relations" do
28
+ describe "#merge!" do
29
29
  it "should merge multi values" do
30
30
  r1 = rel.where(id: [1,2], dummy: 'qwe').time(:hour)
31
31
  r2 = Influxer::Relation.new(DummyMetrics).where.not(user_id: 0).group(:user_id)
@@ -49,7 +49,7 @@ describe Influxer::Relation do
49
49
  end
50
50
  end
51
51
 
52
- describe "select" do
52
+ describe "#select" do
53
53
  it "should select array of symbols" do
54
54
  expect(rel.select(:user_id, :dummy_id).to_sql).to eq "select user_id,dummy_id from \"dummy\""
55
55
  end
@@ -59,7 +59,7 @@ describe Influxer::Relation do
59
59
  end
60
60
  end
61
61
 
62
- describe "where" do
62
+ describe "#where" do
63
63
  it "should generate valid conditions from hash" do
64
64
  Timecop.freeze(Time.now) do
65
65
  expect(rel.where(user_id: 1, dummy: 'q', timer: Time.now).to_sql).to eq "select * from \"dummy\" where (user_id=1) and (dummy='q') and (timer=#{Time.now.to_i}s)"
@@ -83,7 +83,7 @@ describe Influxer::Relation do
83
83
  end
84
84
  end
85
85
 
86
- describe "not" do
86
+ describe "#not" do
87
87
  it "should negate simple values" do
88
88
  expect(rel.where.not(user_id: 1, dummy: :a).to_sql).to eq "select * from \"dummy\" where (user_id<>1) and (dummy<>'a')"
89
89
  end
@@ -101,7 +101,7 @@ describe Influxer::Relation do
101
101
  end
102
102
  end
103
103
 
104
- describe "merge" do
104
+ describe "#merge" do
105
105
  it "should merge with one series" do
106
106
  expect(rel.merge("dubby").to_sql).to eq "select * from \"dummy\" merge \"dubby\""
107
107
  end
@@ -111,7 +111,7 @@ describe Influxer::Relation do
111
111
  end
112
112
  end
113
113
 
114
- describe "past" do
114
+ describe "#past" do
115
115
  it "should work with predefined symbols" do
116
116
  expect(rel.past(:hour).to_sql).to eq "select * from \"dummy\" where (time > now() - 1h)"
117
117
  end
@@ -129,18 +129,18 @@ describe Influxer::Relation do
129
129
  end
130
130
  end
131
131
 
132
- describe "since" do
132
+ describe "#since" do
133
133
  it "should work with datetime" do
134
134
  expect(rel.since(Time.utc(2014,12,31)).to_sql).to eq "select * from \"dummy\" where (time > 1419984000s)"
135
135
  end
136
136
  end
137
137
 
138
- describe "group" do
138
+ describe "#group" do
139
139
  it "should generate valid groups" do
140
140
  expect(rel.group(:user_id, "time(1m) fill(0)").to_sql).to eq "select * from \"dummy\" group by user_id,time(1m) fill(0)"
141
141
  end
142
142
 
143
- describe "group by time predefined values" do
143
+ context "group by time predefined values" do
144
144
  it "should group by hour" do
145
145
  expect(rel.time(:hour).to_sql).to eq "select * from \"dummy\" group by time(1h)"
146
146
  end
@@ -187,29 +187,53 @@ describe Influxer::Relation do
187
187
  end
188
188
  end
189
189
 
190
- describe "limit" do
190
+ describe "#limit" do
191
191
  it "should generate valid limi" do
192
192
  expect(rel.limit(100).to_sql).to eq "select * from \"dummy\" limit 100"
193
193
  end
194
194
  end
195
195
 
196
- describe "empty?" do
197
- after(:each) { Influxer.reset }
198
- it "should return false if has points" do
199
- Influxer.client.stub(:query) { {points: [{time: 1, id: 2}]} }
200
- expect(rel.empty?).to be_falsey
201
- expect(rel.present?).to be_truthy
196
+ describe "calculations" do
197
+ context "one arg calculation methods" do
198
+ [
199
+ :count, :min, :max, :mean,
200
+ :mode, :median, :distinct, :derivative,
201
+ :stddev, :sum, :first, :last, :difference, :histogram
202
+ ].each do |method|
203
+ describe "##{method}" do
204
+ it { expect(rel.where(user_id: 1).calc(method, :column_name).to_sql).to eq "select #{method}(column_name) from \"dummy\" where (user_id=1)"}
205
+ end
206
+ end
202
207
  end
203
208
 
204
- it "should return true if no points" do
205
- Influxer.client.stub(:query) { {} }
206
- expect(rel.empty?).to be_truthy
207
- expect(rel.present?).to be_falsey
209
+ context "two args calculation methods" do
210
+ [
211
+ :percentile, :histogram, :top, :bottom
212
+ ].each do |method|
213
+ describe "##{method}" do
214
+ it { expect(rel.where(user_id: 1).calc(method, :column_name, 10).to_sql).to eq "select #{method}(column_name,10) from \"dummy\" where (user_id=1)"}
215
+ end
216
+ end
208
217
  end
209
218
  end
210
219
  end
211
220
 
212
- describe "delete_all" do
221
+ describe "#empty?" do
222
+ after(:each) { Influxer.reset }
223
+ it "should return false if has points" do
224
+ Influxer.client.stub(:query) { {points: [{time: 1, id: 2}]} }
225
+ expect(rel.empty?).to be_falsey
226
+ expect(rel.present?).to be_truthy
227
+ end
228
+
229
+ it "should return true if no points" do
230
+ Influxer.client.stub(:query) { {} }
231
+ expect(rel.empty?).to be_truthy
232
+ expect(rel.present?).to be_falsey
233
+ end
234
+ end
235
+
236
+ describe "#delete_all" do
213
237
  it do
214
238
  Timecop.freeze(Time.now) do
215
239
  expect(rel.where(user_id: 1, dummy: 'q', timer: Time.now).delete_all).to eq "delete from \"dummy\" where (user_id=1) and (dummy='q') and (timer=#{Time.now.to_i}s)"
@@ -217,7 +241,7 @@ describe Influxer::Relation do
217
241
  end
218
242
  end
219
243
 
220
- describe "inspect" do
244
+ describe "#inspect" do
221
245
 
222
246
  after(:each) do
223
247
  Influxer.reset
@@ -4,4 +4,6 @@ class DummyMetrics < Influxer::Metrics
4
4
  validates_presence_of :dummy_id, :user_id
5
5
 
6
6
  before_write ->{ self.time = DateTime.now }
7
+
8
+ scope :calc, ->(method, *args) { send(method, *args) }
7
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Dem
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-27 00:00:00.000000000 Z
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.3'
53
+ version: '0.4'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0.3'
60
+ version: '0.4'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: timecop
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +164,7 @@ extensions: []
164
164
  extra_rdoc_files: []
165
165
  files:
166
166
  - ".gitignore"
167
+ - ".hound.yml"
167
168
  - ".travis.yml"
168
169
  - Changelog.md
169
170
  - Gemfile
@@ -181,6 +182,7 @@ files:
181
182
  - lib/influxer/metrics/fanout.rb
182
183
  - lib/influxer/metrics/metrics.rb
183
184
  - lib/influxer/metrics/relation.rb
185
+ - lib/influxer/metrics/relation/calculations.rb
184
186
  - lib/influxer/metrics/relation/fanout_query.rb
185
187
  - lib/influxer/metrics/relation/time_query.rb
186
188
  - lib/influxer/metrics/scoping.rb