milk_maid 0.1.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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/milkmaid +5 -0
- data/bin/setup +7 -0
- data/config/firebase.yml.sample +1 -0
- data/lib/milkmaid/batch.rb +51 -0
- data/lib/milkmaid/cli.rb +48 -0
- data/lib/milkmaid/console_notifier.rb +23 -0
- data/lib/milkmaid/firebase_notifier/batch_record.rb +78 -0
- data/lib/milkmaid/firebase_notifier.rb +31 -0
- data/lib/milkmaid/parse_notifier.rb +34 -0
- data/lib/milkmaid/remote_notifier/batch_record.rb +80 -0
- data/lib/milkmaid/temperature_sensor.rb +38 -0
- data/lib/milkmaid/version.rb +3 -0
- data/lib/milkmaid.rb +13 -0
- data/milkmaid.gemspec +37 -0
- metadata +181 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 60b61c742362d8e47611594ae8d749eb21c0e196
         | 
| 4 | 
            +
              data.tar.gz: e30619de06cb423bfb20929b45b6e39a2d45086d
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: fc59278709740c167a7e3167586b02b5d2829ae33f92f3699dc1d897b23363a47bec834e7cb2c9002c7a2811c98873b46a8c57224c3c6c72c3572c2d7f351cd5
         | 
| 7 | 
            +
              data.tar.gz: 9ee3ce7b156b4902cd29abd5ca0327571666f3256619ae9cfd3b68af6087643ed850e6d6f39655013e225a5ec92e68bb163ad9fbd3ea6b3cd6bb5c9aaa4bb362
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    
    
        data/.ruby-version
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            2.2.1
         | 
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,36 @@ | |
| 1 | 
            +
            # Milkmaid
         | 
| 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/milkmaid`. 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 'milkmaid'
         | 
| 13 | 
            +
            ```
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            And then execute:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ bundle
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            Or install it yourself as:
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                $ gem install milkmaid
         | 
| 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 rspec` 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]/milkmaid.
         | 
| 36 | 
            +
             | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/console
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "bundler/setup"
         | 
| 4 | 
            +
            require "milkmaid"
         | 
| 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/milkmaid
    ADDED
    
    
    
        data/bin/setup
    ADDED
    
    
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            firebase_url: 'YOUR FIREBASE URL'
         | 
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            module Milkmaid
         | 
| 2 | 
            +
              class Batch
         | 
| 3 | 
            +
                attr_accessor :name, :batch_guid, :temperature, :duration, :size, :notifier, :sensor
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                NAP_TIME = 5
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def initialize(options = {})
         | 
| 8 | 
            +
                  options.each { |key, value| send("#{key}=", value) }
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  @batch_guid = generate_guid
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def compare_temperature(current_temperature)
         | 
| 14 | 
            +
                  notifier.log_temperature(current_temperature)
         | 
| 15 | 
            +
                  current_temperature.to_i >= temperature.to_i
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def start
         | 
| 19 | 
            +
                  notifier.batch_started(name: name, guid: batch_guid, duration: duration, base_temperature: temperature, batch_size: size)
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  until compare_temperature(sensor.reading)
         | 
| 22 | 
            +
                    take_a_nap
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  ending_time = Time.now + duration
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  notifier.temperature_reached
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  until Time.now > ending_time
         | 
| 30 | 
            +
                    current_temp = sensor.reading
         | 
| 31 | 
            +
                    notifier.log_temperature(current_temp)
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    notifier.post_warning(current_temp, temperature) if current_temp < temperature
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                    take_a_nap
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  notifier.batch_completed
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              private
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                def generate_guid
         | 
| 44 | 
            +
                  ::SecureRandom.uuid
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                def take_a_nap
         | 
| 48 | 
            +
                  sleep NAP_TIME
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
            end
         | 
    
        data/lib/milkmaid/cli.rb
    ADDED
    
    | @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            require 'thor'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Milkmaid
         | 
| 4 | 
            +
              class CLI < Thor
         | 
| 5 | 
            +
                desc 'monitor_batch BATCH_NAME', "Start Monitoring a batch"
         | 
| 6 | 
            +
                long_desc <<-DESC
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                `monitor_batch BATCH_NAME` will create a batch called BATCH_NAME
         | 
| 9 | 
            +
                and begin monitoring it for 30 minutes
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                DESC
         | 
| 12 | 
            +
                option :batch_name, :type => :string, :required => :true, :aliases => "-b"
         | 
| 13 | 
            +
                option :temperature, :type => :numeric, :required => :false, :default => 30, :aliases => '-t'
         | 
| 14 | 
            +
                option :duration, :type => :numeric, :required => false, :default => 30, :aliases => '-d'
         | 
| 15 | 
            +
                option :logger, :type => :string, :required => false, :default => 'Console', :aliases => '-l'
         | 
| 16 | 
            +
                option :sensor, :type => :boolean, :required => false, :default => true, :aliases => '-s'
         | 
| 17 | 
            +
                def monitor_batch
         | 
| 18 | 
            +
                  batch_name = options[:batch_name]
         | 
| 19 | 
            +
                  temperature = options[:temperature].to_i
         | 
| 20 | 
            +
                  duration = options[:duration].to_i
         | 
| 21 | 
            +
                  logger_type = options[:logger]
         | 
| 22 | 
            +
                  sensor_type = options[:sensor]
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  sensor = get_sensor(sensor_type)
         | 
| 25 | 
            +
                  notifier = get_logger(logger_type)
         | 
| 26 | 
            +
                  batch = ::Milkmaid::Batch.new(name: batch_name, temperature: temperature, duration: duration, notifier: notifier, sensor: sensor)
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  batch.start
         | 
| 29 | 
            +
                rescue ::Milkmaid::SensorException => e
         | 
| 30 | 
            +
                  puts e.message
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                no_commands do
         | 
| 34 | 
            +
                  def get_sensor(sensor_type)
         | 
| 35 | 
            +
                    sensor_type ? ::Milkmaid::TemperatureSensor.new : ::Milkmaid::MockTemperatureSensor.new(options[:temperature].to_i - 20, options[:temperature].to_i + 30)
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  def get_logger(logger_type)
         | 
| 39 | 
            +
                    case logger_type.upcase
         | 
| 40 | 
            +
                    when 'CONSOLE'
         | 
| 41 | 
            +
                      ::Milkmaid::ConsoleNotifier.new
         | 
| 42 | 
            +
                    when 'WEB'
         | 
| 43 | 
            +
                      ::Milkmaid::ParseNotifier.new
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
            end
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            module Milkmaid
         | 
| 2 | 
            +
              class ConsoleNotifier
         | 
| 3 | 
            +
                def batch_completed
         | 
| 4 | 
            +
                  puts "#{Time.now} - Batch Completed"
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def batch_started(_)
         | 
| 8 | 
            +
                  puts "#{Time.now} - Batch Started"
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def log_temperature(temperature)
         | 
| 12 | 
            +
                  puts "#{Time.now} - Temperature reading: #{temperature}"
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def post_warning(current_temperature, base_temperature)
         | 
| 16 | 
            +
                  puts "#{Time.now} - WARNING: Current Temperature: #{current_temperature} Base Temperature: #{base_temperature}"
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def temperature_reached
         | 
| 20 | 
            +
                  puts "#{Time.now} - Temperature reached!"
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| @@ -0,0 +1,78 @@ | |
| 1 | 
            +
            require 'firebase'
         | 
| 2 | 
            +
            require 'yaml'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Milkmaid
         | 
| 5 | 
            +
              module FirebaseNotifier
         | 
| 6 | 
            +
                class BatchRecord
         | 
| 7 | 
            +
                  attr_accessor :name, :guid, :duration, :base_temperature, :batch_size, :status, :record
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  CACHE_THRESHOLD = 20
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  def initialize
         | 
| 12 | 
            +
                    @firebase = ::Firebase::Client.new(::YAML.load_file(File.join(CONFIG_DIR, 'firebase.yml'))['firebase_url'])
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def start(batch_data = {})
         | 
| 16 | 
            +
                    batch_data.each { |key, value| send("#{key}=", value) }
         | 
| 17 | 
            +
                    @status = 'Started'
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    self.create_remote_record
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  def create_remote_record
         | 
| 23 | 
            +
                    @response = @firebase.push("batches", {
         | 
| 24 | 
            +
                      :guid => guid,
         | 
| 25 | 
            +
                      :name => name,
         | 
| 26 | 
            +
                      :duration => duration,
         | 
| 27 | 
            +
                      :base_temperature => base_temperature,
         | 
| 28 | 
            +
                      :batch_size => batch_size,
         | 
| 29 | 
            +
                      :status => status
         | 
| 30 | 
            +
                    })
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  def add_event(event_type, data = 0)
         | 
| 34 | 
            +
                    events << ::Milkmaid::FirebaseNotifier::Event.new(event_name_from_type(event_type), data, timestamp)
         | 
| 35 | 
            +
                    return if cache_event(event_type)
         | 
| 36 | 
            +
                    send_events!
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  def cache_event(event_type)
         | 
| 40 | 
            +
                    return false unless event_type == :temperature
         | 
| 41 | 
            +
                    return false if @events.length < CACHE_THRESHOLD
         | 
| 42 | 
            +
                    true
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  def close_batch
         | 
| 46 | 
            +
                    @firebase.update("/batches/#{guid}", :status => 'Completed')
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  def complete!
         | 
| 50 | 
            +
                    add_event(:batch_completed)
         | 
| 51 | 
            +
                    close_batch
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  def event_name_from_type(event)
         | 
| 55 | 
            +
                    event.to_s.split(/_/).map(&:capitalize).join(' ')
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  def events
         | 
| 59 | 
            +
                    @events ||= []
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  def send_events!
         | 
| 63 | 
            +
                    events.each do |event|
         | 
| 64 | 
            +
                      @firebase.push("/batches/#{guid}/events", event.to_h)
         | 
| 65 | 
            +
                    end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                    @events = []
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  def timestamp
         | 
| 71 | 
            +
                    Time.now
         | 
| 72 | 
            +
                  end
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                class Event < Struct.new(:name, :data, :timestamp)
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
            end
         | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            module Milkmaid
         | 
| 2 | 
            +
              class FirebaseNotifier < ::Milkmaid::ConsoleNotifier
         | 
| 3 | 
            +
                attr_accessor :batch_record
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def batch_completed
         | 
| 6 | 
            +
                  super
         | 
| 7 | 
            +
                  batch_record.complete!
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def batch_started(batch_data = {})
         | 
| 11 | 
            +
                  super(batch_data)
         | 
| 12 | 
            +
                  batch_record = ::Milkmaid::FirebaseNotifier::BatchRecord.new(batch_data)
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def log_temperature(temperature)
         | 
| 16 | 
            +
                  super(temperature)
         | 
| 17 | 
            +
                  batch_record.add_event(:temperature, temperature)
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def post_warning(current_temperature, base_temperature)
         | 
| 21 | 
            +
                  super(current_temperature, base_temperature)
         | 
| 22 | 
            +
                  batch_record.add_event(:temperature_warning, current_temperature)
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def temperature_reached
         | 
| 26 | 
            +
                  super
         | 
| 27 | 
            +
                  batch_record.add_event(:threshold_reached)
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            module Milkmaid
         | 
| 2 | 
            +
              class ParseNotifier < ::Milkmaid::ConsoleNotifier
         | 
| 3 | 
            +
                attr_accessor :batch_record
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def batch_completed
         | 
| 6 | 
            +
                  super
         | 
| 7 | 
            +
                  batch_record.complete!
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def batch_record
         | 
| 11 | 
            +
                  @batch_record ||= ::Milkmaid::FirebaseNotifier::BatchRecord.new
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def batch_started(batch_data = {})
         | 
| 15 | 
            +
                  super(batch_data)
         | 
| 16 | 
            +
                  batch_record.start(batch_data)
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def log_temperature(temperature)
         | 
| 20 | 
            +
                  super(temperature)
         | 
| 21 | 
            +
                  batch_record.add_event(:temperature, temperature)
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def post_warning(current_temperature, base_temperature)
         | 
| 25 | 
            +
                  super(current_temperature, base_temperature)
         | 
| 26 | 
            +
                  batch_record.add_event(:temperature_warning, current_temperature)
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def temperature_reached
         | 
| 30 | 
            +
                  super
         | 
| 31 | 
            +
                  batch_record.add_event(:threshold_reached)
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
            end
         | 
| @@ -0,0 +1,80 @@ | |
| 1 | 
            +
            require 'parse-ruby-client'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Milkmaid
         | 
| 4 | 
            +
              module RemoteNotifier
         | 
| 5 | 
            +
                class BatchRecord
         | 
| 6 | 
            +
                  attr_accessor :name, :guid, :duration, :base_temperature, :batch_size, :status, :record
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def initialize
         | 
| 9 | 
            +
                    Parse.init(
         | 
| 10 | 
            +
                      :application_id => 'JxuqdmEaI0DYwxcDV1imv2S64PWMLNjJq3wpGcVC',
         | 
| 11 | 
            +
                      :api_key => 'dsEh8Uqc3gwT9kYcG6OvR9W6pRlzcZlG6X9NeClS'
         | 
| 12 | 
            +
                    )
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def start(batch_data = {})
         | 
| 16 | 
            +
                    batch_data.each { |key, value| send("#{key}=", value) }
         | 
| 17 | 
            +
                    @status = 'Started'
         | 
| 18 | 
            +
                    self.create_remote_record
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  def create_remote_record
         | 
| 22 | 
            +
                    @record = ::Parse::Object.new('BatchRecords')
         | 
| 23 | 
            +
                    @record[:name] = name
         | 
| 24 | 
            +
                    @record[:guid] = guid
         | 
| 25 | 
            +
                    @record[:duration] = duration
         | 
| 26 | 
            +
                    @record[:base_temperature] = base_temperature
         | 
| 27 | 
            +
                    @record[:batch_size] = batch_size
         | 
| 28 | 
            +
                    @record[:status] = status
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                    @record.save
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  def add_event(event_type, data = 0)
         | 
| 34 | 
            +
                    events << ::Milkmaid::RemoteNotifier::Event.new(name: event_name_from_type(event_type), data: data, timestamp: timestamp)
         | 
| 35 | 
            +
                    return if event_type == :temperature
         | 
| 36 | 
            +
                    send_events!
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  def close_batch
         | 
| 40 | 
            +
                    @record[:status] = 'Completed'
         | 
| 41 | 
            +
                    @record.save
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  def complete!
         | 
| 45 | 
            +
                    add_event(:batch_completed)
         | 
| 46 | 
            +
                    close_batch
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  def event_name_from_type(event)
         | 
| 50 | 
            +
                    event.to_s.split(/_/).map(&:capitalize).join(' ')
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  def events
         | 
| 54 | 
            +
                    @events ||= []
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                  def send_events!
         | 
| 58 | 
            +
                    events.each do |event|
         | 
| 59 | 
            +
                      event.save
         | 
| 60 | 
            +
                      @record.array_add_relation("BatchRecordEvents", event.pointer)
         | 
| 61 | 
            +
                      @record.save
         | 
| 62 | 
            +
                    end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                  def timestamp
         | 
| 67 | 
            +
                    Time.now
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                class Event < ::Parse::Object
         | 
| 72 | 
            +
                  def initialize(params = {})
         | 
| 73 | 
            +
                    super('Events')
         | 
| 74 | 
            +
                    self[:name] = params.fetch(:name)
         | 
| 75 | 
            +
                    self[:data] = params.fetch(:data)
         | 
| 76 | 
            +
                    self[:timestamp] = params.fetch(:timestamp)
         | 
| 77 | 
            +
                  end
         | 
| 78 | 
            +
                end
         | 
| 79 | 
            +
              end
         | 
| 80 | 
            +
            end
         | 
| @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            require 'w1temp'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Milkmaid
         | 
| 4 | 
            +
              class SensorException < RuntimeError; end
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              class TemperatureSensor
         | 
| 7 | 
            +
                def initialize
         | 
| 8 | 
            +
                  @sensor = Temperature.new
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  fail ::Milkmaid::SensorException.new 'Sensor not available' unless @sensor.name
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def name
         | 
| 14 | 
            +
                  return "No sensor attached" unless @sensor.display
         | 
| 15 | 
            +
                  @sensor.name
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def reading
         | 
| 19 | 
            +
                  return "Reading: No sensor attached" unless @sensor.display
         | 
| 20 | 
            +
                  @sensor.reading
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              class MockTemperatureSensor
         | 
| 25 | 
            +
                def initialize(low_temp, high_temp)
         | 
| 26 | 
            +
                  @low_temp = low_temp.to_i
         | 
| 27 | 
            +
                  @high_temp = high_temp.to_i
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def name
         | 
| 31 | 
            +
                  'MockTemperatureSensor'
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                def reading
         | 
| 35 | 
            +
                  rand(@low_temp..@high_temp)
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
            end
         | 
    
        data/lib/milkmaid.rb
    ADDED
    
    | @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            require 'milkmaid/batch'
         | 
| 2 | 
            +
            require 'milkmaid/cli'
         | 
| 3 | 
            +
            require 'milkmaid/console_notifier'
         | 
| 4 | 
            +
            require 'milkmaid/parse_notifier'
         | 
| 5 | 
            +
            require 'milkmaid/remote_notifier/batch_record'
         | 
| 6 | 
            +
            require 'milkmaid/firebase_notifier/batch_record'
         | 
| 7 | 
            +
            require 'milkmaid/temperature_sensor'
         | 
| 8 | 
            +
            require 'milkmaid/version'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            CONFIG_DIR = File.join(File.dirname(__FILE__), '..', 'config')
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            module Milkmaid
         | 
| 13 | 
            +
            end
         | 
    
        data/milkmaid.gemspec
    ADDED
    
    | @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'milkmaid/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "milk_maid"
         | 
| 8 | 
            +
              spec.version       = Milkmaid::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Steve Newell"]
         | 
| 10 | 
            +
              spec.email         = ["steve.newell@mx.com"]
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              spec.summary       = %q{Reads data from Raspberry PI sensor and posts to Firebase}
         | 
| 13 | 
            +
              spec.description   = %q{Reads data from Raspberry PI sensor and posts to Firebase}
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
         | 
| 16 | 
            +
              # delete this section to allow pushing this gem to any host.
         | 
| 17 | 
            +
              if spec.respond_to?(:metadata)
         | 
| 18 | 
            +
                spec.metadata['allowed_push_host'] = "https://rubygems.org"
         | 
| 19 | 
            +
              else
         | 
| 20 | 
            +
                raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 24 | 
            +
              spec.bindir        = "bin"
         | 
| 25 | 
            +
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 26 | 
            +
              spec.require_paths = ["lib"]
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              spec.add_dependency "thor"
         | 
| 29 | 
            +
              spec.add_runtime_dependency "w1temp"
         | 
| 30 | 
            +
              spec.add_runtime_dependency "parse-ruby-client"
         | 
| 31 | 
            +
              spec.add_runtime_dependency "firebase"
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              spec.add_development_dependency "bundler", "~> 1.10"
         | 
| 34 | 
            +
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 35 | 
            +
              spec.add_development_dependency "rspec"
         | 
| 36 | 
            +
              spec.add_development_dependency "guard-rspec"
         | 
| 37 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,181 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: milk_maid
         | 
| 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: 2015-07-29 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'
         | 
| 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 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: parse-ruby-client
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :runtime
         | 
| 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: firebase
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
              type: :runtime
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: bundler
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - "~>"
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '1.10'
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - "~>"
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '1.10'
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: rake
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - "~>"
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '10.0'
         | 
| 90 | 
            +
              type: :development
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - "~>"
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '10.0'
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: rspec
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - ">="
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: '0'
         | 
| 104 | 
            +
              type: :development
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - ">="
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: '0'
         | 
| 111 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 112 | 
            +
              name: guard-rspec
         | 
| 113 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - ">="
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: '0'
         | 
| 118 | 
            +
              type: :development
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                requirements:
         | 
| 122 | 
            +
                - - ">="
         | 
| 123 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            +
                    version: '0'
         | 
| 125 | 
            +
            description: Reads data from Raspberry PI sensor and posts to Firebase
         | 
| 126 | 
            +
            email:
         | 
| 127 | 
            +
            - steve.newell@mx.com
         | 
| 128 | 
            +
            executables:
         | 
| 129 | 
            +
            - console
         | 
| 130 | 
            +
            - milkmaid
         | 
| 131 | 
            +
            - setup
         | 
| 132 | 
            +
            extensions: []
         | 
| 133 | 
            +
            extra_rdoc_files: []
         | 
| 134 | 
            +
            files:
         | 
| 135 | 
            +
            - ".gitignore"
         | 
| 136 | 
            +
            - ".rspec"
         | 
| 137 | 
            +
            - ".ruby-version"
         | 
| 138 | 
            +
            - ".travis.yml"
         | 
| 139 | 
            +
            - Gemfile
         | 
| 140 | 
            +
            - README.md
         | 
| 141 | 
            +
            - Rakefile
         | 
| 142 | 
            +
            - bin/console
         | 
| 143 | 
            +
            - bin/milkmaid
         | 
| 144 | 
            +
            - bin/setup
         | 
| 145 | 
            +
            - config/firebase.yml.sample
         | 
| 146 | 
            +
            - lib/milkmaid.rb
         | 
| 147 | 
            +
            - lib/milkmaid/batch.rb
         | 
| 148 | 
            +
            - lib/milkmaid/cli.rb
         | 
| 149 | 
            +
            - lib/milkmaid/console_notifier.rb
         | 
| 150 | 
            +
            - lib/milkmaid/firebase_notifier.rb
         | 
| 151 | 
            +
            - lib/milkmaid/firebase_notifier/batch_record.rb
         | 
| 152 | 
            +
            - lib/milkmaid/parse_notifier.rb
         | 
| 153 | 
            +
            - lib/milkmaid/remote_notifier/batch_record.rb
         | 
| 154 | 
            +
            - lib/milkmaid/temperature_sensor.rb
         | 
| 155 | 
            +
            - lib/milkmaid/version.rb
         | 
| 156 | 
            +
            - milkmaid.gemspec
         | 
| 157 | 
            +
            homepage: 
         | 
| 158 | 
            +
            licenses: []
         | 
| 159 | 
            +
            metadata:
         | 
| 160 | 
            +
              allowed_push_host: https://rubygems.org
         | 
| 161 | 
            +
            post_install_message: 
         | 
| 162 | 
            +
            rdoc_options: []
         | 
| 163 | 
            +
            require_paths:
         | 
| 164 | 
            +
            - lib
         | 
| 165 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 166 | 
            +
              requirements:
         | 
| 167 | 
            +
              - - ">="
         | 
| 168 | 
            +
                - !ruby/object:Gem::Version
         | 
| 169 | 
            +
                  version: '0'
         | 
| 170 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 171 | 
            +
              requirements:
         | 
| 172 | 
            +
              - - ">="
         | 
| 173 | 
            +
                - !ruby/object:Gem::Version
         | 
| 174 | 
            +
                  version: '0'
         | 
| 175 | 
            +
            requirements: []
         | 
| 176 | 
            +
            rubyforge_project: 
         | 
| 177 | 
            +
            rubygems_version: 2.4.6
         | 
| 178 | 
            +
            signing_key: 
         | 
| 179 | 
            +
            specification_version: 4
         | 
| 180 | 
            +
            summary: Reads data from Raspberry PI sensor and posts to Firebase
         | 
| 181 | 
            +
            test_files: []
         |