Class: SmarterMeter::Sample
- Inherits:
-
Object
- Object
- SmarterMeter::Sample
- 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
-
#kwh ⇒ Object
Returns the value of attribute kwh.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
-
#initialize(time, kwh) ⇒ Sample
constructor
Creates a new Sample.
-
#inspect ⇒ Object
Interrogates the current state of the Sample.
-
#utc_start_time ⇒ String
The start time of this measurement in UTC.
-
#utc_stop_time ⇒ String
The stop time of this measurement in UTC.
Constructor Details
#initialize(time, kwh) ⇒ Sample
Creates a new Sample.
15 16 17 18 |
# File 'lib/smartermeter/sample.rb', line 15 def initialize(time, kwh) @time = time @kwh = kwh end |
Instance Attribute Details
#kwh ⇒ Object
Returns the value of attribute kwh.
8 9 10 |
# File 'lib/smartermeter/sample.rb', line 8 def kwh @kwh end |
#time ⇒ Object
Returns the value of attribute time.
8 9 10 |
# File 'lib/smartermeter/sample.rb', line 8 def time @time end |
Instance Method Details
#inspect ⇒ Object
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_time ⇒ String
The start time of this measurement in UTC.
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_time ⇒ String
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.
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 |