Method: AEMO::NEM12#to_nem12_300_csv

Defined in:
lib/aemo/nem12.rb

#to_nem12_300_csvString

Output the AEMO::NEM12 to a valid NEM12 300 row CSV string.

Since:

  • 0.1.4



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/aemo/nem12.rb', line 457

def to_nem12_300_csv
  lines = []

  daily_datas = interval_data.group_by do |x|
    AEMO::Time.format_timestamp8(x[:datetime] - 1.second)
  end
  daily_datas.keys.sort.each do |key|
    daily_data = daily_datas[key].sort_by { |x| x[:datetime] }
    has_flags = daily_data.map { |x| x[:flag]&.any? }.uniq.include?(true)

    lines << [
      '300',
      key,
      daily_data.map { |x| x[:value] },
      has_flags ? 'V' : 'A',
      '',
      '',
      daily_data.first[:updated_at] ? AEMO::Time.format_timestamp14(daily_data.first[:updated_at]) : nil,
      daily_data.first[:msats_load_at] ? AEMO::Time.format_timestamp14(daily_data.first[:msats_load_at]) : nil
    ].flatten.join(CSV_SEPARATOR)

    next unless has_flags

    lines << to_nem12_400_csv(daily_data:)
  end

  lines.join(CRLF) + CRLF
end