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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0898262a63f0164a54f0c5b7bbb08d347313804
4
- data.tar.gz: e56659a2bd9e16205d9b822c3aa2d61b0e1cd877
3
+ metadata.gz: 70ad195a35d724e6055c48a83c79cc7b395571a5
4
+ data.tar.gz: e94fb1227b0a7d7526eaba95d554bbba5df3b5d8
5
5
  SHA512:
6
- metadata.gz: 4d8227a661bc931192432f35448b1c7d8fb429231bdcf847b132b674fd63c086d5889f7533e8a3423ac5dc0fcc47513e269169bace208ad0e9de7289e1f9e4ae
7
- data.tar.gz: 2beb06bb5b919344a9d8d2def12ea496e3cbcc0a6805211dfa3644df532e9e70b24a3faae468de7c07d151241fabd5eda8f3cf50d88c7b51b7098c48613550df
6
+ metadata.gz: 9f5f2a161e92ee1652e3a80c364be4c874f7e30d9588d5bacc03c1ff3cd1ee5da6317d71948c125d07001d9049bc4495401c665cb2d86dffc6fa114274ef84f1
7
+ data.tar.gz: a3e4cceb616b3aa00ea98b0b657bc05e564390c41f59b878f49d9859e4984a971dacaf72eacff69cd54cd2e0eca52a6621f9bcc906de3e154467900fdd76920d
data/co2-notify.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "activesupport"
24
24
  spec.add_dependency "co2mon"
25
25
  spec.add_dependency "plist"
26
+ spec.add_dependency "ruby-fann"
26
27
  end
@@ -1,20 +1,26 @@
1
1
  require "yaml"
2
2
 
3
3
  class Co2Notify::Config < OpenStruct
4
- CONFIG_FILE_NAME = ".co2-notify.yml".freeze
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
- DEFAULR_PING_TIMEOUT = 10.freeze
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(ENV['HOME'], CONFIG_FILE_NAME)
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
@@ -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
 
@@ -7,6 +7,10 @@ class Co2Notify::Status
7
7
  @config, @co2, @previous, @time = config, co2, previous, time
8
8
  end
9
9
 
10
+ def type_changed?
11
+ self.class != previous.class
12
+ end
13
+
10
14
  private
11
15
 
12
16
  def hc_mention
@@ -1,3 +1,3 @@
1
1
  class Co2Notify
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.9"
3
3
  end
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.3
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-15 00:00:00.000000000 Z
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