nightfury 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/nightfury.rb CHANGED
@@ -10,16 +10,6 @@ require 'active_support/core_ext/date_time/calculations'
10
10
  require 'active_support/core_ext/numeric/time'
11
11
  require 'active_support/concern'
12
12
 
13
- class Time
14
- def round(seconds = 60)
15
- Time.at((self.to_f / seconds).round * seconds)
16
- end
17
-
18
- def floor(seconds = 60)
19
- Time.at((self.to_f / seconds).floor * seconds)
20
- end
21
- end
22
-
23
13
  module Nightfury
24
14
  class << self
25
15
  attr_accessor :redis, :namespace
@@ -1,6 +1,10 @@
1
1
  module Nightfury
2
2
  module Metric
3
3
  class TimeSeries < Base
4
+
5
+ def self.round_time(time, seconds=60)
6
+ Time.at((time.to_f / seconds).round * seconds)
7
+ end
4
8
 
5
9
  def initialize(name, options={})
6
10
  super(name, options)
@@ -102,13 +106,17 @@ module Nightfury
102
106
  redis.zadd redis_key, 0, default_meta.to_json
103
107
  end
104
108
 
109
+ def round_time(time, seconds=60)
110
+ self.class.round_time(time, seconds)
111
+ end
112
+
105
113
  def get_step_time(time)
106
114
  case step
107
- when :minute then time.round(60)
108
- when :hour then time.round(1.hour)
109
- when :day then time.round(1.day)
110
- when :week then time.round(1.week)
111
- when :month then time.round(Time.days_in_month(time.month, time.year))
115
+ when :minute then round_time(time, 60)
116
+ when :hour then round_time(time, 1.hour)
117
+ when :day then round_time(time, 1.day)
118
+ when :week then round_time(time, 1.week)
119
+ when :month then round_time(time, Time.days_in_month(time.month, time.year))
112
120
  end
113
121
  end
114
122
  end
@@ -1,3 +1,3 @@
1
1
  module Nightfury
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
@@ -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 == { time_later.round(60).to_i.to_s => "2"}
42
+ count_series.get.should == { round_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 == { time_now.round(60).to_i.to_s => "2"}
51
+ count_series.get.should == { round_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 == { time_later.round(60).to_i.to_s => "0"}
94
+ count_series.get.should == { round_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 == { time_now.round(60).to_i.to_s => "-2"}
103
+ count_series.get.should == { round_time(time_now, 60).to_i.to_s => "-2"}
104
104
  end
105
105
  end
106
106
  end
@@ -154,7 +154,7 @@ describe Nightfury::Metric::TimeSeries do
154
154
 
155
155
  flexmock(ts_metric.redis).should_receive(:zadd)
156
156
  .with(ts_metric.redis_key,
157
- time_now.round(60).to_i,
157
+ round_time(time_now, 60).to_i,
158
158
  FlexMock.any)
159
159
  .once
160
160
 
@@ -170,7 +170,7 @@ describe Nightfury::Metric::TimeSeries do
170
170
 
171
171
  flexmock(ts_metric.redis).should_receive(:zadd)
172
172
  .with(ts_metric.redis_key,
173
- time.round(60).to_i,
173
+ round_time(time, 60).to_i,
174
174
  FlexMock.any)
175
175
  .once
176
176
 
data/spec/spec_helper.rb CHANGED
@@ -33,3 +33,7 @@ RSpec.configure do |config|
33
33
  REDIS_CLIENT.flushdb
34
34
  end
35
35
  end
36
+
37
+ def round_time(time, seconds=60)
38
+ Nightfury::Metric::TimeSeries.round_time(time, 60)
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nightfury
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-21 00:00:00.000000000 Z
13
+ date: 2013-02-26 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Nightfury is a reporting/analytics backend written on Redis
16
16
  email: