co2-notify 0.4.9 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/co2-notify.gemspec +0 -1
- data/lib/co2-notify.rb +0 -1
- data/lib/co2-notify/config.rb +0 -5
- data/lib/co2-notify/hipchat_client.rb +2 -0
- data/lib/co2-notify/notifier.rb +2 -27
- data/lib/co2-notify/status.rb +4 -6
- data/lib/co2-notify/version.rb +1 -1
- metadata +1 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 065abc8840072d9e343b09fd447661fad0a3ee1d
|
4
|
+
data.tar.gz: 93b77b9e0c84592dc4a6bb8a5be7123528aceefb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5523bfdb502d0d76f16d701f5ba0fc359faa6cf8ab0e1261380b4ec933a9fe21b4bb4f4df53484bd2a5eef23cc1647a5c3e25ca82ae42f6d0adc4d7c76f9f96d
|
7
|
+
data.tar.gz: 60e17f5aec5a814029398ca7258eef3fb9edc1c27da80c89d78784bc81931a414ecc7f6beab2349caedc5dd7c3c8ab13e833a6b177c7a740a88f4012bbd169b2
|
data/co2-notify.gemspec
CHANGED
data/lib/co2-notify.rb
CHANGED
data/lib/co2-notify/config.rb
CHANGED
@@ -5,7 +5,6 @@ class Co2Notify::Config < OpenStruct
|
|
5
5
|
CONFIG_FILE_NAME = "config.yml".freeze
|
6
6
|
OUTPUT_FILE_NAME = "output.log".freeze
|
7
7
|
ERROR_FILE_NAME = "error.log".freeze
|
8
|
-
FANN_FILE_NAME = "co2.net".freeze
|
9
8
|
DEFAULT_TIMEOUT = 5.freeze
|
10
9
|
DEFAULT_COOLDOWN = 15.freeze
|
11
10
|
DEFAULT_HIGH_LEVEL = 800.freeze
|
@@ -68,8 +67,4 @@ class Co2Notify::Config < OpenStruct
|
|
68
67
|
def self.error_path
|
69
68
|
File.join(config_dir, ERROR_FILE_NAME)
|
70
69
|
end
|
71
|
-
|
72
|
-
def self.fann_path
|
73
|
-
File.join(config_dir, FANN_FILE_NAME)
|
74
|
-
end
|
75
70
|
end
|
data/lib/co2-notify/notifier.rb
CHANGED
@@ -6,8 +6,6 @@ class Co2Notify::Notifier
|
|
6
6
|
attr_reader :config, :client, :status
|
7
7
|
delegate :timeout, to: :status
|
8
8
|
|
9
|
-
NORMALIZATION_CONSTANT = 10000.0.freeze
|
10
|
-
|
11
9
|
def initialize(config)
|
12
10
|
@config = config
|
13
11
|
@client = Co2Notify::HipchatClient.new(config)
|
@@ -36,34 +34,11 @@ class Co2Notify::Notifier
|
|
36
34
|
def notify
|
37
35
|
new_status = Co2Notify::Status.build(get_data, Time.now, config, status)
|
38
36
|
|
37
|
+
puts "Status: #{new_status}"
|
38
|
+
|
39
39
|
if status.changed?(new_status)
|
40
40
|
client.send(new_status)
|
41
41
|
@status = new_status
|
42
|
-
|
43
|
-
if status.type_changed?
|
44
|
-
fann = if File.exist?(Co2Notify::Config.fann_path)
|
45
|
-
RubyFann::Standard.new(filename: Co2Notify::Config.fann_path)
|
46
|
-
else
|
47
|
-
RubyFann::Shortcut.new(num_inputs: 2, num_outputs: 1)
|
48
|
-
end
|
49
|
-
|
50
|
-
train = RubyFann::TrainData.new(
|
51
|
-
inputs: [
|
52
|
-
[
|
53
|
-
(status.co2 - (status.previous.co2 || 0)) / NORMALIZATION_CONSTANT,
|
54
|
-
status.time.hour / 100.0
|
55
|
-
]
|
56
|
-
],
|
57
|
-
desired_outputs: [
|
58
|
-
[
|
59
|
-
(status.time - status.previous.time) / NORMALIZATION_CONSTANT
|
60
|
-
]
|
61
|
-
]
|
62
|
-
)
|
63
|
-
|
64
|
-
fann.train_on_data(train, 1000, 10, 0.01)
|
65
|
-
fann.save(Co2Notify::Config.fann_path)
|
66
|
-
end
|
67
42
|
end
|
68
43
|
end
|
69
44
|
|
data/lib/co2-notify/status.rb
CHANGED
@@ -3,14 +3,12 @@ class Co2Notify::Status
|
|
3
3
|
attr_reader :co2, :config, :previous, :time
|
4
4
|
delegate :timeout, :cooldown, :mention, :user, :ping_timeout, to: :config
|
5
5
|
|
6
|
+
SAFE_RANGE = 100.freeze
|
7
|
+
|
6
8
|
def initialize(config, time, previous = nil, co2 = nil)
|
7
9
|
@config, @co2, @previous, @time = config, co2, previous, time
|
8
10
|
end
|
9
11
|
|
10
|
-
def type_changed?
|
11
|
-
self.class != previous.class
|
12
|
-
end
|
13
|
-
|
14
12
|
private
|
15
13
|
|
16
14
|
def hc_mention
|
@@ -33,7 +31,7 @@ class Co2Notify::Status
|
|
33
31
|
|
34
32
|
def changed?(new_status)
|
35
33
|
new_status.is_a?(Empty) ||
|
36
|
-
new_status.is_a?(Normal) ||
|
34
|
+
(new_status.is_a?(Normal) && new_status.co2 <= config.high_level - SAFE_RANGE) ||
|
37
35
|
(new_status.is_a?(VeryHigh) && new_status.co2 > co2)
|
38
36
|
end
|
39
37
|
|
@@ -53,7 +51,7 @@ class Co2Notify::Status
|
|
53
51
|
|
54
52
|
def changed?(new_status)
|
55
53
|
new_status.is_a?(Empty) ||
|
56
|
-
new_status.is_a?(Normal) ||
|
54
|
+
(new_status.is_a?(Normal) && new_status.co2 <= config.high_level - SAFE_RANGE) ||
|
57
55
|
(new_status.is_a?(High) && new_status.co2 > co2) ||
|
58
56
|
new_status.is_a?(VeryHigh)
|
59
57
|
end
|
data/lib/co2-notify/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: co2-notify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkadiy Butermanov
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: ruby-fann
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
description:
|
98
84
|
email:
|
99
85
|
- arkadiy.butermanov@flatstack.com
|