past_yer_eyes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 420c5d25bad82618367469612b1c89d7bd29b63b
4
+ data.tar.gz: 051819a5c8bd93f52d84319f299de10d1fb7c827
5
+ SHA512:
6
+ metadata.gz: f9d5796fef38d04bb39dfa48fb652c2004ec69de499e84939e82320523c3e5c9c1383a488f13acb9ebfeb8f09d986a5fcaeb607729c636d8e92a08f6ceddf83e
7
+ data.tar.gz: fb4e5e06f74dbbb9922f957aff9e968d3723e1f1a90755149d9a6a0a0bdc62639ba59857d27a6de175fd72ba865032f29d7f593c55e6c532a9d600f5f9ebd391
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ session.json
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in past_yer_eyes.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # PastYerEyes
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/past_yer_eyes`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'past_yer_eyes'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install past_yer_eyes
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/past_yer_eyes.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "past_yer_eyes"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/past_yer_eyes ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'past_yer_eyes'
4
+
5
+ PastYerEyes::CLI.start(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ require "thor"
2
+
3
+ module PastYerEyes
4
+ class CLI < Thor
5
+ desc "parse_logs", "Parse Batch Reports and create a Google sheet"
6
+ long_desc <<-DESC
7
+ DESC
8
+
9
+ option :log_name, :type => :string, :default => "./pasteurization.json", :aliases => "-l"
10
+ option :sheet_name, :type => :string, :aliases => "-s"
11
+ option :session, :type => :string, :default => "./session.json", :aliases => "-e"
12
+
13
+ def create_spreadsheet
14
+ spreadsheet_name = options.fetch(:log_name, default_spreadsheet_name)
15
+ logfile_name = options[:log_name]
16
+ session_file = options[:session]
17
+
18
+ fail "#{session_file} does not exist" unless File.exist?(session_file)
19
+ fail "#{logfile_name} does not exist" unless File.exist?(logfile_name)
20
+
21
+ ::PastYerEyes::LogParser.parse(session_file, logfile_name, spreadsheet_name)
22
+ end
23
+
24
+ default_task :create_spreadsheet
25
+
26
+ no_commands do
27
+ def default_spreadsheet_name
28
+ "Pasteurization Batches #{Time.now}"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,61 @@
1
+ require "json"
2
+ require "google/api_client"
3
+ require "google_drive"
4
+
5
+ TIMESTAMP_COL = 1
6
+ READING_COL = 2
7
+ DATA_COL = 3
8
+
9
+ module PastYerEyes
10
+ 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
+
16
+ file = File.read(logfile_name)
17
+
18
+ records = JSON.parse(file)
19
+
20
+ records.each do |record|
21
+ print_record(sheet, record)
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
56
+ end
57
+
58
+ print_footer(ws, row + 1, batch_name, batch_record)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module PastYerEyes
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "past_yer_eyes/cli"
2
+ require "past_yer_eyes/log_parser"
3
+
4
+ require "past_yer_eyes/version"
5
+
6
+ module PastYerEyes
7
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'past_yer_eyes/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "past_yer_eyes"
8
+ spec.version = PastYerEyes::VERSION
9
+ spec.authors = ["Steve Newell"]
10
+ spec.email = ["newellista@gmail.com"]
11
+
12
+ spec.summary = %q{Parse Pasteurization logs}
13
+ spec.description = %q{Parse Pasteurization logs}
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "bin"
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "thor", "~> 0.19"
21
+ spec.add_dependency "google_drive", "~> 1.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: past_yer_eyes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Steve Newell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: google_drive
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Parse Pasteurization logs
84
+ email:
85
+ - newellista@gmail.com
86
+ executables:
87
+ - console
88
+ - past_yer_eyes
89
+ - setup
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".travis.yml"
96
+ - Gemfile
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/past_yer_eyes
101
+ - bin/setup
102
+ - lib/past_yer_eyes.rb
103
+ - lib/past_yer_eyes/cli.rb
104
+ - lib/past_yer_eyes/log_parser.rb
105
+ - lib/past_yer_eyes/version.rb
106
+ - past_yer_eyes.gemspec
107
+ homepage:
108
+ licenses: []
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.8
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Parse Pasteurization logs
130
+ test_files: []