Sha256: 1a0b4e01c1a8a0df4006d9771c0879e518b61b9cf7d3a016dbf247f4bc76d3ba

Contents?: true

Size: 883 Bytes

Versions: 5

Compression:

Stored size: 883 Bytes

Contents

require 'ashikawa-core'
module Growbot
  module Web
    class Data
      attr_accessor :database

      def initialize
      end

      def get
        dataset = []
        query = <<-QUERY
          FOR row in readings
            FILTER row.moisture != 0
            FILTER row.light != 0
            FILTER row.time >= #{start_time}
            SORT row.time ASC
            RETURN row
        QUERY
        collection.query.execute(query).each do |document|
          dataset << document.to_h
        end
        dataset
      end

      private
      def start_time
        (Time.now - 6*24*60*60).to_i * 1000
      end

      def database
        @database ||= Ashikawa::Core::Database.new do |config|
          config.url = 'http://localhost:8529/_db/growbot'
        end
      end

      def collection
        @collection ||= database[:readings]
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
growbot-web-0.0.6 lib/growbot/web/data.rb
growbot-web-0.0.5 lib/growbot/web/data.rb
growbot-web-0.0.4 lib/growbot/web/data.rb
growbot-web-0.0.2 lib/growbot/web/data.rb
growbot-web-0.0.1 lib/growbot/web/data.rb