oximeter 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/oximeter/base_controller.rb +4 -0
- data/lib/oximeter/configuration/model.rb +32 -0
- data/lib/oximeter/engine.rb +5 -0
- data/lib/oximeter/pulse_controller.rb +7 -0
- data/lib/oximeter/reports/period.rb +6 -0
- data/lib/oximeter/reports/report.rb +68 -0
- data/lib/oximeter/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f6dc4e5f0e06752dd9ed73f9f518b87553b6d15
|
4
|
+
data.tar.gz: 334b9c25d483e07ac06d31b1d69ff73e4a7d9e81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a0637083b3c98a3b3d37ee88432fa952ca515cc18ff02648a7b43ccf447e9d570244a76d5b7e43baa315c3de42890bbfd9568779f14890b25909dc2c31bf3ef
|
7
|
+
data.tar.gz: f90496095e8db7226c53ebb1395fe77d76e2bbc403d9c726c5d6246b6de5f692f8752661ea014ce8585a0c64003825c881797b67c8e9f3dddac6c3c485f93767
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Oximeter
|
2
|
+
module Configuration
|
3
|
+
class Model
|
4
|
+
attr_reader :entity, :setup
|
5
|
+
|
6
|
+
ATTRIBUTES = %w(
|
7
|
+
label
|
8
|
+
pull_last
|
9
|
+
period
|
10
|
+
group_field
|
11
|
+
).freeze
|
12
|
+
|
13
|
+
def initialize(entity)
|
14
|
+
@entity = entity
|
15
|
+
@setup = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
# Define methods for setting model section configuration setup
|
19
|
+
ATTRIBUTES.each do |attribute_name|
|
20
|
+
define_method(attribute_name) do |attribute_value = nil|
|
21
|
+
if attribute_value
|
22
|
+
@setup[attribute_name.to_sym] = attribute_value
|
23
|
+
else
|
24
|
+
@setup[attribute_name.to_sym]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'groupdate'
|
2
|
+
|
3
|
+
module Oximeter
|
4
|
+
module Reports
|
5
|
+
class Report < Struct.new(:entity, :config)
|
6
|
+
include Math
|
7
|
+
|
8
|
+
def self.for_model(entity)
|
9
|
+
new(entity, Oximeter::Configuration::get_model(entity))
|
10
|
+
end
|
11
|
+
|
12
|
+
def has_data?
|
13
|
+
data.length > 0
|
14
|
+
end
|
15
|
+
|
16
|
+
def critical_value?
|
17
|
+
time_period_fraction = (Time.now - data.last.time).to_f / 1.send(config.period)
|
18
|
+
|
19
|
+
weighted_mean = time_period_fraction * mean
|
20
|
+
weighted_std_dev = time_period_fraction * std_dev
|
21
|
+
|
22
|
+
(data.last.count - weighted_mean).abs > weighted_std_dev
|
23
|
+
end
|
24
|
+
|
25
|
+
def data
|
26
|
+
@data ||= entity
|
27
|
+
.where('created_at BETWEEN ? AND ?', (config.pull_last + 1.minute).ago, Time.now)
|
28
|
+
.group_by_period(config.period, config.group_field)
|
29
|
+
.count
|
30
|
+
.map { |point| Period.new(point[0], point[1]) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def time_view_window
|
34
|
+
[data.first.time - 1.hour, data.last.time + 1.hour]
|
35
|
+
end
|
36
|
+
|
37
|
+
def counts_view_window
|
38
|
+
times = data.map(&:time)
|
39
|
+
[times.min, times.max]
|
40
|
+
end
|
41
|
+
|
42
|
+
def mean
|
43
|
+
sum = data.sum(&:count).to_f / data.length
|
44
|
+
end
|
45
|
+
|
46
|
+
# 1. Work out the Mean (the simple average of the numbers)
|
47
|
+
# 2. Then for each number: subtract the Mean and square the result
|
48
|
+
# 3. Then work out the mean of those squared differences.
|
49
|
+
# 4. Take the square root of that
|
50
|
+
def std_dev
|
51
|
+
n = data.length
|
52
|
+
sqrt data.sum { |x| (x.count - mean) ** 2 } / n
|
53
|
+
end
|
54
|
+
|
55
|
+
def charts_json
|
56
|
+
{
|
57
|
+
entity_name: entity.to_s,
|
58
|
+
view_window: {
|
59
|
+
time: time_view_window,
|
60
|
+
counts: counts_view_window
|
61
|
+
},
|
62
|
+
rows: data
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/oximeter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oximeter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad Tsvang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -101,7 +101,13 @@ extensions: []
|
|
101
101
|
extra_rdoc_files: []
|
102
102
|
files:
|
103
103
|
- lib/oximeter.rb
|
104
|
+
- lib/oximeter/base_controller.rb
|
104
105
|
- lib/oximeter/configuration/configuration.rb
|
106
|
+
- lib/oximeter/configuration/model.rb
|
107
|
+
- lib/oximeter/engine.rb
|
108
|
+
- lib/oximeter/pulse_controller.rb
|
109
|
+
- lib/oximeter/reports/period.rb
|
110
|
+
- lib/oximeter/reports/report.rb
|
105
111
|
- lib/oximeter/version.rb
|
106
112
|
homepage: https://github.com/entelo/oximeter
|
107
113
|
licenses:
|