co2-notify 0.4.3 → 0.4.9
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 +1 -0
- data/lib/co2-notify/config.rb +25 -3
- data/lib/co2-notify/notifier.rb +27 -0
- data/lib/co2-notify/status.rb +4 -0
- data/lib/co2-notify/version.rb +1 -1
- data/lib/co2-notify.rb +4 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70ad195a35d724e6055c48a83c79cc7b395571a5
|
4
|
+
data.tar.gz: e94fb1227b0a7d7526eaba95d554bbba5df3b5d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f5f2a161e92ee1652e3a80c364be4c874f7e30d9588d5bacc03c1ff3cd1ee5da6317d71948c125d07001d9049bc4495401c665cb2d86dffc6fa114274ef84f1
|
7
|
+
data.tar.gz: a3e4cceb616b3aa00ea98b0b657bc05e564390c41f59b878f49d9859e4984a971dacaf72eacff69cd54cd2e0eca52a6621f9bcc906de3e154467900fdd76920d
|
data/co2-notify.gemspec
CHANGED
data/lib/co2-notify/config.rb
CHANGED
@@ -1,20 +1,26 @@
|
|
1
1
|
require "yaml"
|
2
2
|
|
3
3
|
class Co2Notify::Config < OpenStruct
|
4
|
-
|
4
|
+
CONFIG_DIR = ".co2-notify".freeze
|
5
|
+
CONFIG_FILE_NAME = "config.yml".freeze
|
6
|
+
OUTPUT_FILE_NAME = "output.log".freeze
|
7
|
+
ERROR_FILE_NAME = "error.log".freeze
|
8
|
+
FANN_FILE_NAME = "co2.net".freeze
|
5
9
|
DEFAULT_TIMEOUT = 5.freeze
|
6
10
|
DEFAULT_COOLDOWN = 15.freeze
|
7
11
|
DEFAULT_HIGH_LEVEL = 800.freeze
|
8
12
|
DEFAULT_VERY_HIGH_LEVEL = 1200.freeze
|
9
13
|
DEFAULT_START_TIME = "12:00".freeze
|
10
14
|
DEFAULT_STOP_TIME = "19:00".freeze
|
11
|
-
|
15
|
+
DEFAULT_PING_TIMEOUT = 60.freeze
|
12
16
|
|
13
17
|
def self.get
|
14
18
|
new YAML.load_file(config_file)
|
15
19
|
end
|
16
20
|
|
17
21
|
def self.set
|
22
|
+
FileUtils.mkdir_p(config_dir) unless File.directory?(config_dir)
|
23
|
+
|
18
24
|
data = {}.tap do |h|
|
19
25
|
print "Monitor location (required): "
|
20
26
|
h["location"] = STDIN.gets.chomp
|
@@ -47,7 +53,23 @@ class Co2Notify::Config < OpenStruct
|
|
47
53
|
end
|
48
54
|
end
|
49
55
|
|
56
|
+
def self.config_dir
|
57
|
+
File.join(ENV['HOME'], CONFIG_DIR)
|
58
|
+
end
|
59
|
+
|
50
60
|
def self.config_file
|
51
|
-
File.join(
|
61
|
+
File.join(config_dir, CONFIG_FILE_NAME)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.output_path
|
65
|
+
File.join(config_dir, OUTPUT_FILE_NAME)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.error_path
|
69
|
+
File.join(config_dir, ERROR_FILE_NAME)
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.fann_path
|
73
|
+
File.join(config_dir, FANN_FILE_NAME)
|
52
74
|
end
|
53
75
|
end
|
data/lib/co2-notify/notifier.rb
CHANGED
@@ -6,6 +6,8 @@ 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
|
+
|
9
11
|
def initialize(config)
|
10
12
|
@config = config
|
11
13
|
@client = Co2Notify::HipchatClient.new(config)
|
@@ -37,6 +39,31 @@ class Co2Notify::Notifier
|
|
37
39
|
if status.changed?(new_status)
|
38
40
|
client.send(new_status)
|
39
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
|
40
67
|
end
|
41
68
|
end
|
42
69
|
|
data/lib/co2-notify/status.rb
CHANGED
data/lib/co2-notify/version.rb
CHANGED
data/lib/co2-notify.rb
CHANGED
@@ -2,6 +2,7 @@ require "thor"
|
|
2
2
|
require "co2mon"
|
3
3
|
require "hipchat"
|
4
4
|
require "plist"
|
5
|
+
require "ruby-fann"
|
5
6
|
require "active_support/core_ext/object/blank"
|
6
7
|
require "active_support/core_ext/module/delegation"
|
7
8
|
|
@@ -37,7 +38,9 @@ class Co2Notify < Thor
|
|
37
38
|
path,
|
38
39
|
"go"
|
39
40
|
],
|
40
|
-
"RunAtLoad" => true
|
41
|
+
"RunAtLoad" => true,
|
42
|
+
"StandardOutPath" => Config.output_path,
|
43
|
+
"StandardErrorPath" => Config.error_path
|
41
44
|
}
|
42
45
|
|
43
46
|
File.open(plist_path, "w") do |f|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: co2-notify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkadiy Butermanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -80,6 +80,20 @@ 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'
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- arkadiy.butermanov@flatstack.com
|