class EnergyPlus::StatFile

Attributes

cdd10[RW]
cdd18[RW]
elevation[RW]
gmt[RW]
hdd10[RW]
hdd18[RW]
lat[RW]
lon[RW]
monthlyDB[RW]
path[RW]
valid[RW]

Public Class Methods

new(path) click to toggle source
# File lib/energyplus/StatFile.rb, line 37
def initialize(path)
  @path = Pathname.new(path)
  @valid = false
  @lat = []
  @lon = []
  @gmt = []
  @elevation = []
  @hdd18 = []
  @cdd18 = []
  @hdd10 = []
  @cdd10 = []
  @monthlyDB = []
  @deltaDB = []
  init
end

Public Instance Methods

deltaDB() click to toggle source

max - min of the mean monthly dry bulbs

# File lib/energyplus/StatFile.rb, line 70
def deltaDB
  if not @monthlyDB.empty? then
    deltaT = @monthlyDB.max-@monthlyDB.min
  else
    deltaT = ""
  end

  return deltaT
end
meanDB() click to toggle source

the mean of the mean monthly dry bulbs

# File lib/energyplus/StatFile.rb, line 58
def meanDB
  if not @monthlyDB.empty? then
    thisSum = 0
    @monthlyDB.each { |db| thisSum += db }
    thisMean = thisSum/@monthlyDB.size
  else
    thisMean = ""
  end
  return thisMean
end
valid?() click to toggle source
# File lib/energyplus/StatFile.rb, line 53
def valid?
  return @valid
end

Private Instance Methods

init() click to toggle source

initialize

# File lib/energyplus/StatFile.rb, line 83
def init
  if @path.exist?
    File.open(@path) do |f|
      text = f.read
      parse(text)
    end
  end
end
parse(text) click to toggle source
# File lib/energyplus/StatFile.rb, line 92
def parse(text)

  # get lat, lon, gmt
  regex = /\{(N|S)\s*([0-9]*).\s*([0-9]*)'\}\s*\{(E|W)\s*([0-9]*).\s*([0-9]*)'\}\s*\{GMT\s*(.*)\s*Hours\}/
  matchData = text.match(regex)
  if matchData.nil?
    puts "Can't find lat/lon/gmt"
    return
  else

    @lat = matchData[2].to_f + (matchData[3].to_f)/60.0
    if matchData[1] == 'S'
      @lat = -@lat
    end

    @lon = matchData[5].to_f + (matchData[6].to_f)/60.0
    if matchData[4] == 'W'
      @lon = -@lon
    end

    @gmt = matchData[7]

  end

  # get elevation
  regex = /Elevation --\s*(.*)m (above|below) sea level/
  matchData = text.match(regex)
  if matchData.nil?
    puts "Can't find elevation"
    return
  else
    @elevation = matchData[1].to_f
    if matchData[2] == 'below'
      @elevation = -@elevation
    end
  end


  # get heating and cooling degree days
  cdd10Regex = /-\s*(.*) annual \(standard\) cooling degree-days \(10.C baseline\)/
  matchData = text.match(cdd10Regex)
  if matchData.nil?
    puts "Can't find CDD 10"
    return
  else
    @cdd10 = matchData[1].to_f
  end

  hdd10Regex = /-\s*(.*) annual \(standard\) heating degree-days \(10.C baseline\)/
  matchData = text.match(hdd10Regex)
  if matchData.nil?
    puts "Can't find HDD 10"
    return
  else
    @hdd10 = matchData[1].to_f
  end

  cdd18Regex = /-\s*(.*) annual \(standard\) cooling degree-days \(18.3.C baseline\)/
  matchData = text.match(cdd18Regex)
  if matchData.nil?
    puts "Can't find CDD 18"
    return
  else
    @cdd18 = matchData[1].to_f
  end

  hdd18Regex = /-\s*(.*) annual \(standard\) heating degree-days \(18.3.C baseline\)/
  matchData = text.match(hdd18Regex)
  if matchData.nil?
    puts "Can't find HDD 18"
    return
  else
    @hdd18 = matchData[1].to_f
  end


  #use regex to get the temperatures
  regex = /Daily Avg(.*)\n/
  matchData = text.match(regex)
  if matchData.nil?
    puts "Can't find outdoor air temps"
    return
  else
    # first match is outdoor air temps
    monthlyTemps = matchData[1].strip.split(/\s+/)

    # have to be 12 months
    if monthlyTemps.size != 12
      puts "Can't find outdoor air temps"
      return
    end

    # insert as numbers
    monthlyTemps.each {|temp| @monthlyDB << temp.to_f}
  end

  # now we are valid
  @valid = true
end