Class: SmarterMeter::Sample

Inherits:
Object
  • Object
show all
Defined in:
lib/smartermeter/sample.rb

Overview

Represents a single hourly sample taken from the PG&E hourly electricity data. It’s the most basic data unit of SmarterMeter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time, kwh) ⇒ Sample

Creates a new Sample.

Parameters:

  • time (Time)

    the start of the sample period.

  • kwh (Float)

    the number of killowatt hours used during the period of this sample.



15
16
17
18
# File 'lib/smartermeter/sample.rb', line 15

def initialize(time, kwh)
  @time = time
  @kwh = kwh
end

Instance Attribute Details

#kwhObject

Returns the value of attribute kwh.



8
9
10
# File 'lib/smartermeter/sample.rb', line 8

def kwh
  @kwh
end

#timeObject

Returns the value of attribute time.



8
9
10
# File 'lib/smartermeter/sample.rb', line 8

def time
  @time
end

Instance Method Details

#inspectObject

Interrogates the current state of the Sample.

Returns [String] a compact representation of the Sample.



39
40
41
# File 'lib/smartermeter/sample.rb', line 39

def inspect
  "<Sample #{@time} #{@kwh}>"
end

#utc_start_timeString

The start time of this measurement in UTC.

Returns:

  • (String)

    the time in the format of 2011-01-06T09:00:00.000Z



23
24
25
# File 'lib/smartermeter/sample.rb', line 23

def utc_start_time
  @time.utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
end

#utc_stop_timeString

The stop time of this measurement in UTC. It’s assumed to be 1 hour after the start as that is the current resolution of PG&E’s data.

Returns:

  • (String)

    the time in the format of 2011-01-06T09:00:00.000Z



31
32
33
34
# File 'lib/smartermeter/sample.rb', line 31

def utc_stop_time
  one_hour = 60*60
  (@time + one_hour).utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
end