past_yer_eyes 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/past_yer_eyes/batch_record.rb +28 -0
- data/lib/past_yer_eyes/cli.rb +4 -2
- data/lib/past_yer_eyes/log_parser.rb +6 -48
- data/lib/past_yer_eyes/spreadsheet_writer.rb +66 -0
- data/lib/past_yer_eyes/version.rb +1 -1
- data/lib/past_yer_eyes.rb +2 -0
- data/past_yer_eyes.gemspec +2 -0
- metadata +31 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 333fad456bbf57ba8052aac6fc2376e776817ece
|
4
|
+
data.tar.gz: ee28f4d78a8cd09a4acd9e2fb7fd314f607a689e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90e29fc54c05e511f1a1713be3f54cd03073e3836b25952c103f3f316422cbc4c30d6e485ce9ece06827b9cac90c7a839951106dee7666741ad54ea974d9f766
|
7
|
+
data.tar.gz: ebed44de77d1d32b27e5b32e708e83a9f75d79d5e0c516c033055cdda338f0136c48cbc2aaa02d6d321582cab29673c150ed02bdc3b40587d2e945a5e098cbc5
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module PastYerEyes
|
2
|
+
class BatchRecord
|
3
|
+
attr_accessor :name, :guid, :status, :duration, :base_temperature, :batch_key, :events
|
4
|
+
|
5
|
+
def self.parse(key, data)
|
6
|
+
record = ::PastYerEyes::BatchRecord.new
|
7
|
+
record.batch_key = key
|
8
|
+
record.guid = data.fetch("guid", "")
|
9
|
+
record.status = data.fetch("status", "")
|
10
|
+
record.duration = data.fetch("duration", "")
|
11
|
+
record.base_temperature = data.fetch("base_temperature")
|
12
|
+
record.name = data.fetch("name", "")
|
13
|
+
|
14
|
+
record.events = data["events"].map do |key, value|
|
15
|
+
::PastYerEyes::BatchEvent.parse(key, value)
|
16
|
+
end
|
17
|
+
|
18
|
+
record
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class BatchEvent < Struct.new(:guid, :data_point, :data_type, :timestamp)
|
23
|
+
def self.parse(key, event_hash)
|
24
|
+
::PastYerEyes::BatchEvent.new(key, event_hash["data"], event_hash["name"], event_hash["timestamp"])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/lib/past_yer_eyes/cli.rb
CHANGED
@@ -20,16 +20,18 @@ module PastYerEyes
|
|
20
20
|
option :log_name, :type => :string, :default => "./pasteurization.json", :aliases => "-l"
|
21
21
|
option :sheet_name, :type => :string, :aliases => "-s"
|
22
22
|
option :session, :type => :string, :default => "./session.json", :aliases => "-e"
|
23
|
-
|
23
|
+
option :exclude, :type => :boolean, :default => false
|
24
24
|
def create_spreadsheet
|
25
25
|
spreadsheet_name = options.fetch(:log_name, default_spreadsheet_name)
|
26
26
|
logfile_name = options[:log_name]
|
27
27
|
session_file = options[:session]
|
28
|
+
filter_options = {}
|
29
|
+
filter_options[:completed] = options[:exclude]
|
28
30
|
|
29
31
|
fail "#{session_file} does not exist" unless File.exist?(session_file)
|
30
32
|
fail "#{logfile_name} does not exist" unless File.exist?(logfile_name)
|
31
33
|
|
32
|
-
::PastYerEyes::LogParser.parse(session_file, logfile_name, spreadsheet_name)
|
34
|
+
::PastYerEyes::LogParser.parse(filter_options, session_file, logfile_name, spreadsheet_name)
|
33
35
|
end
|
34
36
|
|
35
37
|
default_task :create_spreadsheet
|
@@ -1,61 +1,19 @@
|
|
1
1
|
require "json"
|
2
|
-
require "
|
3
|
-
require "
|
4
|
-
|
5
|
-
TIMESTAMP_COL = 1
|
6
|
-
READING_COL = 2
|
7
|
-
DATA_COL = 3
|
2
|
+
require "pry"
|
3
|
+
require "awesome_print"
|
8
4
|
|
9
5
|
module PastYerEyes
|
10
6
|
class LogParser
|
11
|
-
def self.parse(session_file, logfile_name, spreadsheet_name)
|
12
|
-
session = GoogleDrive.saved_session(session_file)
|
13
|
-
|
14
|
-
sheet = session.create_spreadsheet(spreadsheet_name)
|
15
|
-
|
7
|
+
def self.parse(options, session_file, logfile_name, spreadsheet_name)
|
16
8
|
file = File.read(logfile_name)
|
17
9
|
|
18
10
|
records = JSON.parse(file)
|
19
11
|
|
20
|
-
records.
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.print_footer(ws, row, batch_name, batch_record)
|
26
|
-
ws[row, 1] = "Batch Name"
|
27
|
-
ws[row, 2] = batch_name
|
28
|
-
row += 1
|
29
|
-
ws[row, 1] = "Duration"
|
30
|
-
ws[row, 2] = batch_record['duration']
|
31
|
-
row += 1
|
32
|
-
ws[row, 1] = "Base Temperature"
|
33
|
-
ws[row, 2] = batch_record['base_temperature']
|
34
|
-
row += 1
|
35
|
-
ws[row, 1] = "Status"
|
36
|
-
ws[row, 2] = batch_record['status']
|
37
|
-
ws.save
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.print_record(sheet, record)
|
41
|
-
batch_name = record.first
|
42
|
-
batch_record = record[1]
|
43
|
-
|
44
|
-
ws = sheet.add_worksheet("#{batch_record['name']}: #{batch_record['status']}")
|
45
|
-
|
46
|
-
ws[1,TIMESTAMP_COL] = "Timestamp"
|
47
|
-
ws[1,READING_COL] = "Reading"
|
48
|
-
ws[1,DATA_COL] = "Value"
|
49
|
-
|
50
|
-
row = 2
|
51
|
-
batch_record['events'].each do |key, value|
|
52
|
-
ws[row, TIMESTAMP_COL] = value["timestamp"]
|
53
|
-
ws[row, READING_COL] = value["name"]
|
54
|
-
ws[row, DATA_COL] = value["data"]
|
55
|
-
row += 1
|
12
|
+
batches = records["batches"].map do |key, value|
|
13
|
+
::PastYerEyes::BatchRecord.parse(key, value)
|
56
14
|
end
|
57
15
|
|
58
|
-
|
16
|
+
SpreadsheetWriter.write_spreadsheet(options, session_file, spreadsheet_name, batches)
|
59
17
|
end
|
60
18
|
end
|
61
19
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "google/api_client"
|
2
|
+
require "google_drive"
|
3
|
+
|
4
|
+
module PastYerEyes
|
5
|
+
TIMESTAMP_COL = 1
|
6
|
+
READING_COL = 2
|
7
|
+
DATA_COL = 3
|
8
|
+
|
9
|
+
class SpreadsheetWriter
|
10
|
+
def self.suppress_record(options, record)
|
11
|
+
if options[:completed]
|
12
|
+
return record.status != "Completed"
|
13
|
+
end
|
14
|
+
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.write_spreadsheet(options, session_file, spreadsheet_name, records)
|
19
|
+
session = GoogleDrive.saved_session(session_file)
|
20
|
+
|
21
|
+
puts "Creating Spreadsheet #{spreadsheet_name}"
|
22
|
+
sheet = session.create_spreadsheet(spreadsheet_name)
|
23
|
+
|
24
|
+
records.each do |record|
|
25
|
+
print_record(sheet, record) unless suppress_record(options, record)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.print_footer(ws, row, record)
|
30
|
+
ws[row, 1] = "Batch Name"
|
31
|
+
ws[row, 2] = record.name
|
32
|
+
row += 1
|
33
|
+
ws[row, 1] = "Duration"
|
34
|
+
ws[row, 2] = record.duration
|
35
|
+
row += 1
|
36
|
+
ws[row, 1] = "Base Temperature"
|
37
|
+
ws[row, 2] = record.base_temperature
|
38
|
+
row += 1
|
39
|
+
ws[row, 1] = "Status"
|
40
|
+
ws[row, 2] = record.status
|
41
|
+
ws.save
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.print_record(sheet, record)
|
45
|
+
worksheet_name = "#{record.name}: #{record.status}"
|
46
|
+
puts "Creating worksheet for #{worksheet_name}"
|
47
|
+
ws = sheet.add_worksheet(worksheet_name)
|
48
|
+
|
49
|
+
ws[1,TIMESTAMP_COL] = "Timestamp"
|
50
|
+
ws[1,READING_COL] = "Reading"
|
51
|
+
ws[1,DATA_COL] = "Value"
|
52
|
+
|
53
|
+
row = 2
|
54
|
+
|
55
|
+
record.events.each do |event|
|
56
|
+
ws[row, TIMESTAMP_COL] = event.timestamp
|
57
|
+
ws[row, READING_COL] = event.data_type
|
58
|
+
ws[row, DATA_COL] = event.data_point unless event.data_point == 0
|
59
|
+
row += 1
|
60
|
+
end
|
61
|
+
|
62
|
+
print_footer(ws, row + 1, record)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
data/lib/past_yer_eyes.rb
CHANGED
data/past_yer_eyes.gemspec
CHANGED
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_dependency "thor", "~> 0.19"
|
21
21
|
spec.add_dependency "google_drive", "~> 1.0"
|
22
22
|
|
23
|
+
spec.add_development_dependency "pry"
|
24
|
+
spec.add_development_dependency "awesome_print", "~> 1.6"
|
23
25
|
spec.add_development_dependency "bundler", "~> 1.11"
|
24
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: past_yer_eyes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Newell
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: awesome_print
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: bundler
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,8 +128,10 @@ files:
|
|
100
128
|
- bin/past_yer_eyes
|
101
129
|
- bin/setup
|
102
130
|
- lib/past_yer_eyes.rb
|
131
|
+
- lib/past_yer_eyes/batch_record.rb
|
103
132
|
- lib/past_yer_eyes/cli.rb
|
104
133
|
- lib/past_yer_eyes/log_parser.rb
|
134
|
+
- lib/past_yer_eyes/spreadsheet_writer.rb
|
105
135
|
- lib/past_yer_eyes/version.rb
|
106
136
|
- past_yer_eyes.gemspec
|
107
137
|
homepage:
|