Sha256: 51d22458c2b43f86f1120f74db910e05f46ca69fe3c4394eff8209eeecacf54e

Contents?: true

Size: 1.56 KB

Versions: 26

Compression:

Stored size: 1.56 KB

Contents

#converts the WeatherData1.xlsx spreadsheet into a ruby hash using the rubyXL gem

require 'csv'
require 'json'
require 'rubyXL'

begin

csv_file = "#{File.dirname(__FILE__)}/../btap/csvFile1.csv"

input_file = "#{File.dirname(__FILE__)}/../btap/WeatherData1.xlsx"

CSV.open(csv_file, "wb") do |csv|
  workbook = RubyXL::Parser.parse input_file
  worksheet = workbook[0]

  worksheet.each_with_index do |row, row_idx|
    row_data = []
    (0...row.size).each do |col_idx|
      begin
        cell = row[col_idx]
        val = cell.value
        row_data << val
      rescue NoMethodError
        row_data << ""
      end
    end
    csv << row_data
  end
end

rescue; 
end

data_json_hash = CSV.open(csv_file, :headers => true).map { |x| x.to_h }.to_json

File.write("#{File.dirname(__FILE__)}/../btap/csvToJsonUpdate.json",data_json_hash)

data_hash = JSON.parse(File.read("#{File.dirname(__FILE__)}/../btap/csvToJsonUpdate.json"))

data_hash.each do |info|
  info['hdd18'] = info['hdd18'].to_i
  info['hdd15'] = info['hdd15'].to_i
  info['cdd18'] = info['cdd18'].to_i
  info['latitude'] = info['latitude'].to_f
  info['longitude'] = info['longitude'].to_f
  info['elevation'] = info['elevation'].to_i
  info['deltadb'] = info['deltadb'].to_f
  info['mau_type'] = true

end

pretty_output = JSON.pretty_generate(data_hash)

File.delete("#{File.dirname(__FILE__)}/../btap/csvToJsonUpdate.json")

File.delete("#{File.dirname(__FILE__)}/../btap/csvFile1.csv")

File.write("#{File.dirname(__FILE__)}/../btap/WeatherData1.json", pretty_output)

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
openstudio-standards-0.2.12 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.12.rc7 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.12.rc6 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.12.rc5 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.12.rc4 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.12.rc2 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.12.rc1 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.11 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.11.rc2 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.11.rc1 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.10 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.10.rc3 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.10.rc2 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.10.rc1 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.9 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.8 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.7 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.6 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.5 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.4 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb