redis-time-series 0.1.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,23 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
  class Redis
3
3
  class TimeSeries
4
+ # A sample is an immutable value object that represents a single data point within a time series.
4
5
  class Sample
5
- TS_FACTOR = 1000.0
6
+ using TimeMsec
6
7
 
7
- attr_reader :time, :value
8
+ # @return [Time] the sample's timestamp
9
+ attr_reader :time
10
+ # @return [BigDecimal] the decimal value of the sample
11
+ attr_reader :value
8
12
 
13
+ # Samples are returned by time series query methods, there's no need to create one yourself.
14
+ # @api private
15
+ # @see TimeSeries#get
16
+ # @see TimeSeries#range
9
17
  def initialize(timestamp, value)
10
- @time = Time.at(timestamp / TS_FACTOR)
18
+ @time = Time.from_msec(timestamp)
11
19
  @value = BigDecimal(value)
12
20
  end
13
21
 
14
- def ts_msec
15
- (time.to_f * TS_FACTOR).to_i
22
+ # @return [Integer] the millisecond value of the sample's timestamp
23
+ # @note
24
+ # We're wrapping the method provided by the {TimeMsec} refinement for convenience,
25
+ # otherwise it wouldn't be callable on {time} and devs would have to litter
26
+ # +using TimeMsec+ or +* 1000.0+ wherever they wanted the value.
27
+ def to_msec
28
+ time.ts_msec
16
29
  end
17
30
 
31
+ # @return [Hash] a hash representation of the sample
32
+ # @example
33
+ # {:timestamp=>1595199272401, :value=>0.2e1}
18
34
  def to_h
19
35
  {
20
- timestamp: ts_msec,
36
+ timestamp: to_msec,
21
37
  value: value
22
38
  }
23
39
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ class Redis
3
+ class TimeSeries
4
+ VERSION = '0.5.0'
5
+ end
6
+ end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'redis-time-series'
4
+ require 'redis/time_series/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'redis-time-series'
8
- spec.version = RedisTimeSeries::VERSION
8
+ spec.version = Redis::TimeSeries::VERSION
9
9
  spec.authors = ['Matt Duszynski']
10
- spec.email = ['mattduszynski@gmail.com']
10
+ spec.email = ['dzunk@hey.com']
11
11
 
12
12
  spec.summary = %q{A Ruby adapter for the RedisTimeSeries module.}
13
13
  # spec.description = %q{TODO: Write a longer description or delete this line.}
@@ -38,4 +38,5 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency 'pry', '~> 0.13'
39
39
  spec.add_development_dependency 'rake', '~> 13.0'
40
40
  spec.add_development_dependency 'rspec', '~> 3.0'
41
+ spec.add_development_dependency 'simplecov', '< 0.18' # https://github.com/codeclimate/test-reporter/issues/413
41
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-time-series
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Duszynski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-26 00:00:00.000000000 Z
11
+ date: 2020-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -94,13 +94,28 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "<"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.18'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "<"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.18'
97
111
  description:
98
112
  email:
99
- - mattduszynski@gmail.com
113
+ - dzunk@hey.com
100
114
  executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
118
+ - ".github/workflows/rspec.yml"
104
119
  - ".gitignore"
105
120
  - ".rspec"
106
121
  - CHANGELOG.md
@@ -111,10 +126,17 @@ files:
111
126
  - Rakefile
112
127
  - bin/console
113
128
  - bin/setup
129
+ - lib/ext/time_msec.rb
114
130
  - lib/redis-time-series.rb
115
131
  - lib/redis/time_series.rb
132
+ - lib/redis/time_series/aggregation.rb
133
+ - lib/redis/time_series/client.rb
134
+ - lib/redis/time_series/errors.rb
135
+ - lib/redis/time_series/filters.rb
136
+ - lib/redis/time_series/info.rb
137
+ - lib/redis/time_series/rule.rb
116
138
  - lib/redis/time_series/sample.rb
117
- - lib/time/msec.rb
139
+ - lib/redis/time_series/version.rb
118
140
  - redis-time-series.gemspec
119
141
  homepage: https://github.com/dzunk/redis-time-series
120
142
  licenses:
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
- class Time
3
- # TODO: use refinemenets instead of monkey-patching Time
4
- def ts_msec
5
- (to_f * 1000.0).to_i
6
- end
7
- end