Class: AEMO::Market::Interval Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/aemo/market/interval.rb

Overview

This class is abstract.

AEMO::Market::Interval

Author:

  • Joel Courtney

Since:

  • 0.1.0

Constant Summary collapse

INTERVALS =

Since:

  • 0.1.0

{
  trading: 'Trading',
  dispatch: 'Dispatch'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datetime, options = {}) ⇒ AEMO::Market::Interval

Create a new instance of an Interval

Parameters:

  • datetime (Time)
  • options (Hash) (defaults to: {})

    Hash of optional data values

Since:

  • 0.1.0



24
25
26
27
28
29
30
# File 'lib/aemo/market/interval.rb', line 24

def initialize(datetime, options = {})
  @datetime     = ::Time.parse("#{datetime} +1000")
  @region       = options['REGION']
  @total_demand = options['TOTALDEMAND']
  @rrp          = options['RRP']
  @period_type  = options['PERIODTYPE']
end

Instance Attribute Details

#datetime(trailing_edge: true) ⇒ Time

All AEMO Data operates in Australian Eastern Standard Time All AEMO Data aggregates to the trailing edge of the period (this makes it difficult to do daily aggregations :( )

Parameters:

  • trailing_edge (Boolean) (defaults to: true)

    selection of either the trailing edge of the period or the rising edge of the period for the date time

Returns:

  • (Time)

    a time object of the trailing edge of the interval

Since:

  • 0.1.0



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/aemo/market/interval.rb', line 38

def datetime(trailing_edge: true)
  t = @datetime
  # If the datetime requested is the trailing edge, offset as per interval requirement
  unless trailing_edge
    # This is for dispatch intervals of five minutes
    if dispatch?
      t -= 5 * 60
    elsif trading?
      t -= 30 * 60
    end
  end
  t
end

#period_typeObject

Since:

  • 0.1.0



16
17
18
# File 'lib/aemo/market/interval.rb', line 16

def period_type
  @period_type
end

#regionObject

Since:

  • 0.1.0



16
17
18
# File 'lib/aemo/market/interval.rb', line 16

def region
  @region
end

#rrpObject

Since:

  • 0.1.0



16
17
18
# File 'lib/aemo/market/interval.rb', line 16

def rrp
  @rrp
end

#total_demandObject

Since:

  • 0.1.0



16
17
18
# File 'lib/aemo/market/interval.rb', line 16

def total_demand
  @total_demand
end

Instance Method Details

#dispatch?Boolean

Returns true if the interval type is dispatch

Returns:

  • (Boolean)

    returns true if the interval type is dispatch

Since:

  • 0.1.0



63
64
65
# File 'lib/aemo/market/interval.rb', line 63

def dispatch?
  @period_type.nil? || @period_type.empty?
end

#interval_lengthTime

Returns the time of the.

Returns:

  • (Time)

    the time of the

Since:

  • 0.1.0



53
54
55
# File 'lib/aemo/market/interval.rb', line 53

def interval_length
  ::Time.at(300)
end

#interval_typeSymbol

Returns :dispatch or :trading.

Returns:

  • (Symbol)

    :dispatch or :trading

Since:

  • 0.1.0



58
59
60
# File 'lib/aemo/market/interval.rb', line 58

def interval_type
  dispatch? ? :dispatch : :trading
end

#trading?Boolean

Returns true if the interval type is trading

Returns:

  • (Boolean)

    returns true if the interval type is trading

Since:

  • 0.1.0



68
69
70
# File 'lib/aemo/market/interval.rb', line 68

def trading?
  !dispatch?
end

#valueFloat

Returns the value of the interval in Australian Dollars.

Returns:

  • (Float)

    the value of the interval in Australian Dollars

Since:

  • 0.1.0



73
74
75
76
77
# File 'lib/aemo/market/interval.rb', line 73

def value
  @value ||= Float::NAN
  @value = (@total_demand * @rrp).round(2) if @total_demand.instance_of?(Float) && @rrp.instance_of?(Float)
  @value
end