nightfury 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,8 +2,8 @@ module Nightfury
|
|
|
2
2
|
module Metric
|
|
3
3
|
class TimeSeries < Base
|
|
4
4
|
|
|
5
|
-
def self.
|
|
6
|
-
Time.at((time.to_f / seconds).
|
|
5
|
+
def self.floor_time(time, seconds=60)
|
|
6
|
+
Time.at((time.to_f / seconds).floor * seconds)
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def initialize(name, options={})
|
|
@@ -90,17 +90,17 @@ module Nightfury
|
|
|
90
90
|
[data_point[1], data_point[0], {}]
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
def
|
|
94
|
-
self.class.
|
|
93
|
+
def floor_time(time, seconds=60)
|
|
94
|
+
self.class.floor_time(time, seconds)
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
def get_step_time(time)
|
|
98
98
|
case step
|
|
99
|
-
when :minute then
|
|
100
|
-
when :hour then
|
|
101
|
-
when :day then
|
|
102
|
-
when :week then
|
|
103
|
-
when :month then
|
|
99
|
+
when :minute then floor_time(time, 60)
|
|
100
|
+
when :hour then floor_time(time, 1.hour)
|
|
101
|
+
when :day then floor_time(time, 1.day)
|
|
102
|
+
when :week then floor_time(time, 1.week)
|
|
103
|
+
when :month then floor_time(time, Time.days_in_month(time.month, time.year))
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
106
|
|
data/lib/nightfury/version.rb
CHANGED
|
@@ -39,7 +39,7 @@ describe Nightfury::Metric::CountTimeSeries do
|
|
|
39
39
|
# Add a data point
|
|
40
40
|
count_series.set(1, time_now - 10)
|
|
41
41
|
count_series.incr(1,time_later)
|
|
42
|
-
count_series.get.should == {
|
|
42
|
+
count_series.get.should == { floor_time(time_later, 60).to_i.to_s => "2"}
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
@@ -48,7 +48,7 @@ describe Nightfury::Metric::CountTimeSeries do
|
|
|
48
48
|
count_series = Nightfury::Metric::CountTimeSeries.new(1)
|
|
49
49
|
time_now = Time.now
|
|
50
50
|
count_series.incr(2, time_now)
|
|
51
|
-
count_series.get.should == {
|
|
51
|
+
count_series.get.should == { floor_time(time_now, 60).to_i.to_s => "2"}
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
end
|
|
@@ -91,7 +91,7 @@ describe Nightfury::Metric::CountTimeSeries do
|
|
|
91
91
|
# Add a data point
|
|
92
92
|
count_series.set(1, time_now - 10)
|
|
93
93
|
count_series.decr(1,time_later)
|
|
94
|
-
count_series.get.should == {
|
|
94
|
+
count_series.get.should == { floor_time(time_later, 60).to_i.to_s => "0"}
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
|
|
@@ -100,7 +100,7 @@ describe Nightfury::Metric::CountTimeSeries do
|
|
|
100
100
|
count_series = Nightfury::Metric::CountTimeSeries.new(1)
|
|
101
101
|
time_now = Time.now
|
|
102
102
|
count_series.decr(2, time_now)
|
|
103
|
-
count_series.get.should == {
|
|
103
|
+
count_series.get.should == { floor_time(time_now, 60).to_i.to_s => "-2"}
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
106
|
end
|
|
@@ -197,7 +197,7 @@ describe Nightfury::Metric::TimeSeries do
|
|
|
197
197
|
|
|
198
198
|
flexmock(ts_metric.redis).should_receive(:zadd)
|
|
199
199
|
.with(ts_metric.redis_key,
|
|
200
|
-
|
|
200
|
+
floor_time(time_now, 60).to_i,
|
|
201
201
|
FlexMock.any)
|
|
202
202
|
.once
|
|
203
203
|
|
|
@@ -213,7 +213,7 @@ describe Nightfury::Metric::TimeSeries do
|
|
|
213
213
|
|
|
214
214
|
flexmock(ts_metric.redis).should_receive(:zadd)
|
|
215
215
|
.with(ts_metric.redis_key,
|
|
216
|
-
|
|
216
|
+
floor_time(time, 60).to_i,
|
|
217
217
|
FlexMock.any)
|
|
218
218
|
.once
|
|
219
219
|
|
data/spec/spec_helper.rb
CHANGED