co2-notify 0.4.9 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70ad195a35d724e6055c48a83c79cc7b395571a5
4
- data.tar.gz: e94fb1227b0a7d7526eaba95d554bbba5df3b5d8
3
+ metadata.gz: 065abc8840072d9e343b09fd447661fad0a3ee1d
4
+ data.tar.gz: 93b77b9e0c84592dc4a6bb8a5be7123528aceefb
5
5
  SHA512:
6
- metadata.gz: 9f5f2a161e92ee1652e3a80c364be4c874f7e30d9588d5bacc03c1ff3cd1ee5da6317d71948c125d07001d9049bc4495401c665cb2d86dffc6fa114274ef84f1
7
- data.tar.gz: a3e4cceb616b3aa00ea98b0b657bc05e564390c41f59b878f49d9859e4984a971dacaf72eacff69cd54cd2e0eca52a6621f9bcc906de3e154467900fdd76920d
6
+ metadata.gz: 5523bfdb502d0d76f16d701f5ba0fc359faa6cf8ab0e1261380b4ec933a9fe21b4bb4f4df53484bd2a5eef23cc1647a5c3e25ca82ae42f6d0adc4d7c76f9f96d
7
+ data.tar.gz: 60e17f5aec5a814029398ca7258eef3fb9edc1c27da80c89d78784bc81931a414ecc7f6beab2349caedc5dd7c3c8ab13e833a6b177c7a740a88f4012bbd169b2
data/co2-notify.gemspec CHANGED
@@ -23,5 +23,4 @@ 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"
27
26
  end
data/lib/co2-notify.rb CHANGED
@@ -2,7 +2,6 @@ require "thor"
2
2
  require "co2mon"
3
3
  require "hipchat"
4
4
  require "plist"
5
- require "ruby-fann"
6
5
  require "active_support/core_ext/object/blank"
7
6
  require "active_support/core_ext/module/delegation"
8
7
 
@@ -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
@@ -8,6 +8,8 @@ class Co2Notify::HipchatClient
8
8
  end
9
9
 
10
10
  def send(status)
11
+ puts "Message sent: #{status.message}"
12
+
11
13
  client[room].send("#{location}", status.message, color: status.color, message_format: "text")
12
14
  end
13
15
  end
@@ -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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  class Co2Notify
2
- VERSION = "0.4.9"
2
+ VERSION = "0.5.0"
3
3
  end
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.9
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