Sha256: 74e81bb09ba5e48d92e7eb031e2c756f08caf52b56b37cdd2794e05c0ade70f8

Contents?: true

Size: 1.6 KB

Versions: 22

Compression:

Stored size: 1.6 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 StandardError
end

data_json_hash = CSV.open(csv_file, headers: true).map(&: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

22 entries across 22 versions & 1 rubygems

Version Path
openstudio-standards-0.7.0 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.7.0.rc1 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.6.3 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.6.0.rc2 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.6.0.rc1 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.5.0 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.5.0.rc1 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.4.0 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.3.1.rc2 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.3.1.rc1 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.3.0 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.17.rc2 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.17.rc1 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.16 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.16.rc2 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.16.rc1 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.15 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.15.pre.rc2 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.15.pre.rc1 lib/openstudio-standards/btap/utilities/weatherData1_xlsx_to_json.rb
openstudio-standards-0.2.14 lib/openstudio-standards/utilities/weatherData1_xlsx_to_json.rb