Module: AEMO::Market Abstract

Includes:
HTTParty
Defined in:
lib/aemo/market.rb,
lib/aemo/market/node.rb,
lib/aemo/market/interval.rb

Overview

This module is abstract.

AEMO::Market

Author:

  • Joel Courtney

Since:

  • 0.1.0

Defined Under Namespace

Classes: Interval, Node

Class Method Summary collapse

Class Method Details

.current_dispatch(region) ⇒ Array<AEMO::Market::Interval>

Return the current dispatch dataset for a region

Parameters:

Returns:

Since:

  • 0.1.0


19
20
21
22
23
24
25
# File 'lib/aemo/market.rb', line 19

def current_dispatch(region)
  region = AEMO::Region.new(region) if region.is_a?(String)

  response = get "/mms.GRAPHS/GRAPHS/GRAPH_5#{region}1.csv"
  values = parse_response(response)
  values
end

.current_trading(region) ⇒ Array<AEMO::Market::Interval>

Description of method

Parameters:

Returns:

Since:

  • 0.1.0


31
32
33
34
35
36
37
# File 'lib/aemo/market.rb', line 31

def current_trading(region)
  region = AEMO::Region.new(region) if region.is_a?(String)

  response = get "/mms.GRAPHS/GRAPHS/GRAPH_30#{region}1.csv"
  values = parse_response(response)
  values
end

.historic_trading(region, year, month) ⇒ Array<AEMO::Market::Interval>

Return an array of historic trading values for a Year, Month and Region

As per the historical data from AEMO

Parameters:

  • region (String, AEMO::Region)

    AEMO::Region

  • year (Integer)

    The year for the report from AEMO

  • month (Integer)

    The month for the report from AEMO

Returns:

Since:

  • 0.1.0


67
68
69
70
71
72
73
74
75
76
# File 'lib/aemo/market.rb', line 67

def historic_trading(region, year, month)
  region = AEMO::Region.new(region) if region.is_a?(String)

  month = Kernel.format('%02d', month)
  url = 'https://aemo.com.au/aemo/data/nem/priceanddemand/' \
        "PRICE_AND_DEMAND_#{year}#{month}_#{region}1.csv"

  response = HTTParty.get(url)
  parse_response(response)
end

.historic_trading_by_range(region, start, finish) ⇒ Array<AEMO::Market::Interval>

Return an array of historic trading values based on a start and finish

Parameters:

  • region (String, AEMO::Region)

    AEMO::Region

  • start (Time)

    this is inclusive not exclusive

  • finish (Time)

    this is inclusive not exclusive

Returns:

Since:

  • 0.1.0


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/aemo/market.rb', line 45

def historic_trading_by_range(region, start, finish)
  region = AEMO::Region.new(region) if region.is_a?(String)

  required_data = []
  (start..finish).map { |d| { year: d.year, month: d.month } }
                 .uniq.each do |period|
    required_data += historic_trading(region, period[:year],
                                      period[:month])
  end

  required_data.select do |values|
    values.datetime >= start && values.datetime <= finish
  end
end