milk_maid 0.5.1 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Dockerfile.template +30 -0
- data/lib/milk_maid.rb +2 -2
- data/lib/milk_maid/batch.rb +1 -0
- data/lib/milk_maid/cli.rb +5 -1
- data/lib/milk_maid/google_sheet_notifier.rb +65 -0
- data/lib/milk_maid/spreadsheet_writer.rb +55 -0
- data/lib/milk_maid/version.rb +1 -1
- data/milk_maid.gemspec +8 -9
- metadata +34 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 037860fab1c6f5fa56e71f5fb223ada051e8231c
|
4
|
+
data.tar.gz: fa12bff10a10f22b10a626b5e142de820061176d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a93045950a4c0d7eb1a1fcd3fafe68b6cd8ce6193b636fbec58f1cde67f6755616f5238048997179475da48492d93c0d1efd2a6254074b6fe99c3f56b1c5388
|
7
|
+
data.tar.gz: 5adc08a0168158703647ed0d47ab3fae9e55c283422f202424d4aad2da81467c68792212242eed3880b4464653d66ee9b6d93fdd9bd65f98875e39ab2288447d
|
data/.gitignore
CHANGED
data/Dockerfile.template
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
FROM resin/%%RESIN_MACHINE_NAME%%-debian:jessie
|
2
|
+
ENV PATH /opt/elixir/bin:$PATH
|
3
|
+
ENV LANG C.UTF-8
|
4
|
+
ENV MIX_ENV production
|
5
|
+
RUN apt-get update && apt-get install -y \
|
6
|
+
less \
|
7
|
+
vim \
|
8
|
+
tree \
|
9
|
+
curl \
|
10
|
+
unzip \
|
11
|
+
git \
|
12
|
+
ca-certificates \
|
13
|
+
build-essential \
|
14
|
+
&& echo "deb http://packages.erlang-solutions.com/debian wheezy contrib" >> /etc/apt/sources.list \
|
15
|
+
&& curl 'http://packages.erlang-solutions.com/debian/erlang_solutions.asc' -o 'esolutions.asc' \
|
16
|
+
&& apt-key add esolutions.asc \
|
17
|
+
&& rm esolutions.asc \
|
18
|
+
&& apt-get update \
|
19
|
+
&& apt-get install -y --force-yes erlang-mini \
|
20
|
+
&& mkdir /opt/elixir \
|
21
|
+
&& curl -k -L https://github.com/elixir-lang/elixir/releases/download/v1.2.4/Precompiled.zip -o /opt/elixir/precompiled.zip \
|
22
|
+
&& cd /opt/elixir \
|
23
|
+
&& unzip precompiled.zip \
|
24
|
+
&& mix local.hex --force \
|
25
|
+
&& mix local.rebar --force \
|
26
|
+
&& rm -rf /var/lib/apt/lists/*
|
27
|
+
COPY . /app
|
28
|
+
WORKDIR /app
|
29
|
+
RUN mix hex.registry fetch && mix deps.get && mix compile
|
30
|
+
CMD modprobe w1-gpio && modprobe w1-therm && elixir -S mix run --no-halt --no-deps-check
|
data/lib/milk_maid.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'milk_maid/batch'
|
2
2
|
require 'milk_maid/cli'
|
3
3
|
require 'milk_maid/console_notifier'
|
4
|
-
require 'milk_maid/
|
5
|
-
require 'milk_maid/
|
4
|
+
require 'milk_maid/spreadsheet_writer'
|
5
|
+
require 'milk_maid/google_sheet_notifier'
|
6
6
|
require 'milk_maid/temperature_sensor'
|
7
7
|
require 'milk_maid/version'
|
8
8
|
|
data/lib/milk_maid/batch.rb
CHANGED
data/lib/milk_maid/cli.rb
CHANGED
@@ -12,7 +12,7 @@ module MilkMaid
|
|
12
12
|
option :batch_name, :type => :string, :aliases => "-b"
|
13
13
|
option :temperature, :type => :numeric, :required => :false, :default => 30, :aliases => '-t'
|
14
14
|
option :duration, :type => :numeric, :required => false, :default => 30, :aliases => '-d'
|
15
|
-
option :logger, :type => :string, :required => false, :default => '
|
15
|
+
option :logger, :type => :string, :required => false, :default => 'Spreadsheet', :aliases => '-l'
|
16
16
|
option :sensor, :type => :boolean, :required => false, :default => true, :aliases => '-s'
|
17
17
|
option :nap, :type => :numeric, :required => false, :default => 5, :aliases => '-n'
|
18
18
|
def monitor_batch
|
@@ -27,6 +27,8 @@ module MilkMaid
|
|
27
27
|
notifier = get_logger(logger_type)
|
28
28
|
batch = ::MilkMaid::Batch.new(name: batch_name, temperature: temperature, duration: duration, notifier: notifier, sensor: sensor, nap_time: nap_time)
|
29
29
|
|
30
|
+
puts batch.inspect
|
31
|
+
|
30
32
|
batch.start
|
31
33
|
rescue ::MilkMaid::SensorException => e
|
32
34
|
puts e.message
|
@@ -49,6 +51,8 @@ module MilkMaid
|
|
49
51
|
::MilkMaid::ConsoleNotifier.new
|
50
52
|
when 'WEB'
|
51
53
|
::MilkMaid::ParseNotifier.new
|
54
|
+
when 'SPREADSHEET'
|
55
|
+
::MilkMaid::GoogleSheetNotifier.new
|
52
56
|
end
|
53
57
|
end
|
54
58
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module MilkMaid
|
2
|
+
class GoogleSheetNotifier < ::MilkMaid::ConsoleNotifier
|
3
|
+
attr_accessor :batch_record
|
4
|
+
|
5
|
+
def batch_completed
|
6
|
+
super
|
7
|
+
batch_record.complete!
|
8
|
+
::MilkMaid::SpreadsheetWriter.write_spreadsheet("./session.json", "Pasteurization Batch #{Time.now}", batch_record)
|
9
|
+
end
|
10
|
+
|
11
|
+
def batch_started(batch_data = {})
|
12
|
+
super(batch_data)
|
13
|
+
@batch_record = ::MilkMaid::BatchRecord.new(batch_data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def log_temperature(temperature)
|
17
|
+
super(temperature)
|
18
|
+
batch_record.add_event(:temperature, temperature)
|
19
|
+
end
|
20
|
+
|
21
|
+
def post_warning(current_temperature, base_temperature)
|
22
|
+
super(current_temperature, base_temperature)
|
23
|
+
batch_record.add_event(:temperature_warning, current_temperature)
|
24
|
+
end
|
25
|
+
|
26
|
+
def temperature_reached
|
27
|
+
super
|
28
|
+
batch_record.add_event(:threshold_reached)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class BatchRecord
|
34
|
+
attr_accessor :name, :guid, :duration, :base_temperature, :batch_size, :status, :record
|
35
|
+
|
36
|
+
def initialize(batch_data = {})
|
37
|
+
batch_data.each { |key, value| send("#{key}=", value) }
|
38
|
+
@status = 'Started'
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_event(event_type, data = 0)
|
42
|
+
events << ::MilkMaid::Event.new(event_name_from_type(event_type), data, timestamp)
|
43
|
+
end
|
44
|
+
|
45
|
+
def complete!
|
46
|
+
add_event(:batch_completed)
|
47
|
+
@status = 'Completed'
|
48
|
+
end
|
49
|
+
|
50
|
+
def event_name_from_type(event)
|
51
|
+
event.to_s.split(/_/).map(&:capitalize).join(' ')
|
52
|
+
end
|
53
|
+
|
54
|
+
def events
|
55
|
+
@events ||= []
|
56
|
+
end
|
57
|
+
|
58
|
+
def timestamp
|
59
|
+
Time.now
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class Event < Struct.new(:name, :data, :timestamp)
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "google/api_client"
|
2
|
+
require "google_drive"
|
3
|
+
|
4
|
+
module MilkMaid
|
5
|
+
TIMESTAMP_COL = 1
|
6
|
+
READING_COL = 2
|
7
|
+
DATA_COL = 3
|
8
|
+
|
9
|
+
class SpreadsheetWriter
|
10
|
+
def self.write_spreadsheet(session_file, spreadsheet_name, record)
|
11
|
+
session = GoogleDrive.saved_session(session_file)
|
12
|
+
|
13
|
+
puts "Creating Spreadsheet #{spreadsheet_name}"
|
14
|
+
sheet = session.create_spreadsheet(spreadsheet_name)
|
15
|
+
|
16
|
+
print_record(sheet, record)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.print_footer(ws, row, record)
|
20
|
+
ws[row, 1] = "Batch Name"
|
21
|
+
ws[row, 2] = record.name
|
22
|
+
row += 1
|
23
|
+
ws[row, 1] = "Duration"
|
24
|
+
ws[row, 2] = record.duration
|
25
|
+
row += 1
|
26
|
+
ws[row, 1] = "Base Temperature"
|
27
|
+
ws[row, 2] = record.base_temperature
|
28
|
+
row += 1
|
29
|
+
ws[row, 1] = "Status"
|
30
|
+
ws[row, 2] = record.status
|
31
|
+
ws.save
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.print_record(sheet, record)
|
35
|
+
worksheet_name = "#{record.name}: #{record.status}"
|
36
|
+
puts "Creating worksheet for #{worksheet_name}"
|
37
|
+
ws = sheet.add_worksheet(worksheet_name)
|
38
|
+
|
39
|
+
ws[1,TIMESTAMP_COL] = "Timestamp"
|
40
|
+
ws[1,READING_COL] = "Reading"
|
41
|
+
ws[1,DATA_COL] = "Value"
|
42
|
+
|
43
|
+
row = 2
|
44
|
+
|
45
|
+
record.events.each do |event|
|
46
|
+
ws[row, TIMESTAMP_COL] = event.timestamp
|
47
|
+
ws[row, READING_COL] = event.name
|
48
|
+
ws[row, DATA_COL] = event.data unless event.data == 0
|
49
|
+
row += 1
|
50
|
+
end
|
51
|
+
|
52
|
+
print_footer(ws, row + 1, record)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/milk_maid/version.rb
CHANGED
data/milk_maid.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Steve Newell"]
|
10
10
|
spec.email = ["steve.newell@mx.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Reads data from Raspberry PI sensor
|
13
|
-
spec.description = %q{Reads data from Raspberry PI sensor and posts to
|
12
|
+
spec.summary = %q{Reads data from Raspberry PI sensor}
|
13
|
+
spec.description = %q{Reads data from Raspberry PI sensor and posts to somewhere}
|
14
14
|
|
15
15
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
16
16
|
# delete this section to allow pushing this gem to any host.
|
@@ -25,14 +25,13 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
|
-
spec.add_dependency "thor"
|
29
|
-
spec.
|
30
|
-
spec.add_runtime_dependency "
|
31
|
-
spec.add_runtime_dependency "firebase"
|
28
|
+
spec.add_dependency "thor", "~> 0.19"
|
29
|
+
spec.add_dependency "google_drive", "~> 1.0"
|
30
|
+
spec.add_runtime_dependency "w1temp", "~> 0.0.4"
|
32
31
|
|
33
32
|
spec.add_development_dependency "bundler", "~> 1.10"
|
34
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
-
spec.add_development_dependency "rspec"
|
36
|
-
spec.add_development_dependency "guard-rspec"
|
37
|
-
spec.
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
35
|
+
spec.add_development_dependency "guard-rspec", "~> 4.6"
|
36
|
+
spec.add_dependency "pry", "~> 0.10"
|
38
37
|
end
|
metadata
CHANGED
@@ -1,71 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: milk_maid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Newell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: w1temp
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
17
|
+
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
19
|
+
version: '0.19'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - "
|
24
|
+
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
26
|
+
version: '0.19'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
28
|
+
name: google_drive
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- - "
|
31
|
+
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
33
|
+
version: '1.0'
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - "
|
38
|
+
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
40
|
+
version: '1.0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
42
|
+
name: w1temp
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - "
|
45
|
+
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
47
|
+
version: 0.0.4
|
62
48
|
type: :runtime
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - "
|
52
|
+
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
54
|
+
version: 0.0.4
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: bundler
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,45 +84,45 @@ dependencies:
|
|
98
84
|
name: rspec
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
|
-
- - "
|
87
|
+
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
89
|
+
version: '3.3'
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- - "
|
94
|
+
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
96
|
+
version: '3.3'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: guard-rspec
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
|
-
- - "
|
101
|
+
- - "~>"
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
103
|
+
version: '4.6'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
|
-
- - "
|
108
|
+
- - "~>"
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
110
|
+
version: '4.6'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: pry
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
|
-
- - "
|
115
|
+
- - "~>"
|
130
116
|
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :
|
117
|
+
version: '0.10'
|
118
|
+
type: :runtime
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
|
-
- - "
|
122
|
+
- - "~>"
|
137
123
|
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
|
-
description: Reads data from Raspberry PI sensor and posts to
|
124
|
+
version: '0.10'
|
125
|
+
description: Reads data from Raspberry PI sensor and posts to somewhere
|
140
126
|
email:
|
141
127
|
- steve.newell@mx.com
|
142
128
|
executables:
|
@@ -148,6 +134,7 @@ files:
|
|
148
134
|
- ".rspec"
|
149
135
|
- ".ruby-version"
|
150
136
|
- ".travis.yml"
|
137
|
+
- Dockerfile.template
|
151
138
|
- Gemfile
|
152
139
|
- README.md
|
153
140
|
- Rakefile
|
@@ -159,7 +146,9 @@ files:
|
|
159
146
|
- lib/milk_maid/console_notifier.rb
|
160
147
|
- lib/milk_maid/firebase_notifier.rb
|
161
148
|
- lib/milk_maid/firebase_notifier/batch_record.rb
|
149
|
+
- lib/milk_maid/google_sheet_notifier.rb
|
162
150
|
- lib/milk_maid/parse_notifier.rb
|
151
|
+
- lib/milk_maid/spreadsheet_writer.rb
|
163
152
|
- lib/milk_maid/temperature_sensor.rb
|
164
153
|
- lib/milk_maid/version.rb
|
165
154
|
- milk_maid.gemspec
|
@@ -186,5 +175,5 @@ rubyforge_project:
|
|
186
175
|
rubygems_version: 2.4.8
|
187
176
|
signing_key:
|
188
177
|
specification_version: 4
|
189
|
-
summary: Reads data from Raspberry PI sensor
|
178
|
+
summary: Reads data from Raspberry PI sensor
|
190
179
|
test_files: []
|