Class: StandardsData
- Inherits:
-
Object
- Object
- StandardsData
- Defined in:
- lib/openstudio-standards/standards/necb/NECB2011/data/standards_data.rb
Instance Attribute Summary collapse
-
#standards_data ⇒ Object
Returns the value of attribute standards_data.
Instance Method Summary collapse
- #excel_to_json(xlsx_file = 'standards.xlsx', output_folder = File.dirname(__FILE__)) ⇒ Object
- #get_standards_constant(name) ⇒ Object
- #get_standards_formula(name) ⇒ Object
- #get_standards_table_row(table_name, search_criteria = nil) ⇒ Object
- #get_standards_table_rows(table_name, search_criteria = nil) ⇒ Object
- #json_to_excel(data_folder = __dir__, xlsx_file = 'standards.xlsx') ⇒ Object
- #load_standards_data(datafolder = File.dirname(__FILE__)) ⇒ Object
Instance Attribute Details
#standards_data ⇒ Object
Returns the value of attribute standards_data.
22 23 24 |
# File 'lib/openstudio-standards/standards/necb/NECB2011/data/standards_data.rb', line 22 def standards_data @standards_data end |
Instance Method Details
#excel_to_json(xlsx_file = 'standards.xlsx', output_folder = File.dirname(__FILE__)) ⇒ Object
88 89 90 91 |
# File 'lib/openstudio-standards/standards/necb/NECB2011/data/standards_data.rb', line 88 def excel_to_json(xlsx_file = 'standards.xlsx', output_folder = File.dirname(__FILE__)) self.extract_excel_tables(xlsx_file, output_folder) self.extract_excel_constants_and_formulas(xlsx_file, output_folder) end |
#get_standards_constant(name) ⇒ Object
24 25 26 27 28 |
# File 'lib/openstudio-standards/standards/necb/NECB2011/data/standards_data.rb', line 24 def get_standards_constant(name) object = @standards_data['constants'].detect {|constant| constant['name'] == name} raise("could not find #{name} in standards constants database. ") if object.nil? or object['value'].nil? return object['value'] end |
#get_standards_formula(name) ⇒ Object
30 31 32 33 34 |
# File 'lib/openstudio-standards/standards/necb/NECB2011/data/standards_data.rb', line 30 def get_standards_formula(name) object = @standards_data['formulas'].detect {|formula| formula['name'] == name} raise("could not find #{name} in standards formual database. ") if object.nil? or object['value'].nil? return object['value'] end |
#get_standards_table_row(table_name, search_criteria = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/openstudio-standards/standards/necb/NECB2011/data/standards_data.rb', line 36 def get_standards_table_row(table_name, search_criteria = nil) return_objects = nil object = @standards_data['tables'].detect {|table| table['name'] == table_name} raise("could not find #{table_name} in standards table database. ") if object.nil? or object['table'].nil? if search_criteria.nil? return object['table'] else return_objects = self.model_find_object(object['table'], search_criteria) return return_object end end |
#get_standards_table_rows(table_name, search_criteria = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/openstudio-standards/standards/necb/NECB2011/data/standards_data.rb', line 48 def get_standards_table_rows(table_name, search_criteria = nil) return_objects = nil object = @standards_data['tables'].detect {|table| table['name'] == table_name} raise("could not find #{table_name} in standards table database. ") if object.nil? or object['table'].nil? if search_criteria.nil? return object['table'] else return_objects = self.model_find_objects(object['table'], search_criteria) return return_objects end end |
#json_to_excel(data_folder = __dir__, xlsx_file = 'standards.xlsx') ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/openstudio-standards/standards/necb/NECB2011/data/standards_data.rb', line 61 def json_to_excel(data_folder = __dir__, xlsx_file = 'standards.xlsx') standards_data = self.load_standards_data(data_folder) workbook = RubyXL::Workbook.new workbook.worksheets.delete(workbook['Sheet1']) #Write Constants Sheet. #self.array_of_hashes_to_excel_sheet(workbook.add_worksheet('constants'), standards_data['constants']) #self.array_of_hashes_to_excel_sheet(workbook.add_worksheet('formulas'), standards_data['formulas']) standards_data['tables'].each do |table| #puts table puts table[0] sheet = workbook.add_worksheet(table[0]) row = 0 table[1].each do |key, value| unless key == 'table' sheet.add_cell(row, 0, key).change_font_bold(true) sheet.add_cell(row, 1, value) row += 1 end end row += 1 sheet.add_cell(row, 0, 'Table').change_font_bold(true) self.array_of_hashes_to_excel_sheet(sheet, table[1]['table'], (row + 1)) end workbook.write(xlsx_file) return xlsx_file end |
#load_standards_data(datafolder = File.dirname(__FILE__)) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/openstudio-standards/standards/necb/NECB2011/data/standards_data.rb', line 93 def load_standards_data(datafolder = File.dirname(__FILE__)) @standards_data = {} if __dir__[0] == ':' # Running from OpenStudio CLI files = ('./', /.*\.json/) files.each do |file| @standards_data = standards_data.deep_merge(JSON.parse(EmbeddedScripting.getFileAsString(file))) end else files = Dir.glob("#{datafolder}/**/*.json").select {|e| File.file? e} files.each do |file| @standards_data = standards_data.deep_merge (JSON.parse(File.read(file))) end end @standards_data = @standards_data.sort_by_key(true) return @standards_data end |