Skip to content

Commit

Permalink
add Report, Utility, AuditDate, Contact classes; refactor to accomodate
Browse files Browse the repository at this point in the history
  • Loading branch information
corymosiman12 committed Dec 16, 2020
1 parent 3df7d16 commit 211ca8d
Show file tree
Hide file tree
Showing 20 changed files with 862 additions and 434 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ jobs:
- $SH "bundle exec rspec spec/tests/translator_scenario_simulations_spec.rb"
name: "Translator Scenario Simulation Spec"
- script:
- $SH "bundle exec rspec spec/tests/report_spec.rb"
- $SH "bundle exec rspec spec/tests/utility_spec.rb"
- $SH "bundle exec rspec spec/tests/scenario_spec.rb"
- $SH "bundle exec rspec spec/tests/time_series_spec.rb"
- $SH "bundle exec rspec spec/tests/resource_use_spec.rb"
- $SH "bundle exec rspec spec/tests/all_resource_total_spec.rb"
name: "Scenario Related Specs"
name: "Report and Scenario Related Specs"
- script:
- $SH "bundle exec rspec spec/tests/workflow_maker_spec.rb"
name: "WorkflowMaker Spec"
Expand Down
4 changes: 3 additions & 1 deletion lib/buildingsync/all_resource_total.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
# *******************************************************************************

module BuildingSync
# ResourceUse class
# AllResourceTotal class
class AllResourceTotal
include BuildingSync::Helper
include BuildingSync::XmlGetSet
# @param base_xml [REXML::Element]
# @param ns [String]
def initialize(base_xml, ns)
@base_xml = base_xml
@ns = ns
Expand Down
54 changes: 54 additions & 0 deletions lib/buildingsync/audit_date.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

# *******************************************************************************
# OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
# BuildingSync(R), Copyright (c) 2015-2020, Alliance for Sustainable Energy, LLC.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# (1) Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# (2) Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# (3) Neither the name of the copyright holder nor the names of any contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission from the respective party.
#
# (4) Other than as required in clauses (1) and (2), distributions in any form
# of modifications or other derivative works may not use the "OpenStudio"
# trademark, "OS", "os", or any other confusingly similar designation without
# specific prior written permission from Alliance for Sustainable Energy, LLC.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# *******************************************************************************

module BuildingSync
# AuditDate class
class AuditDate
include BuildingSync::Helper
include BuildingSync::XmlGetSet
# @param base_xml [REXML::Element]
# @param ns [String]
def initialize(base_xml, ns)
@base_xml = base_xml
@ns = ns

help_element_class_type_check(base_xml, 'AuditDate')
end
end
end
54 changes: 54 additions & 0 deletions lib/buildingsync/contact.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

# *******************************************************************************
# OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
# BuildingSync(R), Copyright (c) 2015-2020, Alliance for Sustainable Energy, LLC.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# (1) Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# (2) Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# (3) Neither the name of the copyright holder nor the names of any contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission from the respective party.
#
# (4) Other than as required in clauses (1) and (2), distributions in any form
# of modifications or other derivative works may not use the "OpenStudio"
# trademark, "OS", "os", or any other confusingly similar designation without
# specific prior written permission from Alliance for Sustainable Energy, LLC.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# *******************************************************************************

module BuildingSync
# Contact class
class Contact
include BuildingSync::Helper
include BuildingSync::XmlGetSet
# @param base_xml [REXML::Element]
# @param ns [String]
def initialize(base_xml, ns)
@base_xml = base_xml
@ns = ns

help_element_class_type_check(base_xml, 'Contact')
end
end
end
28 changes: 28 additions & 0 deletions lib/buildingsync/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -475,16 +475,44 @@ def get_first_building_section_element(doc)
return section
end

def get_first_report_element(doc)
report = doc.get_elements("/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Reports/#{@ns}:Report").first
return report
end

def get_first_scenario_element(doc)
scenario = doc.get_elements("/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Reports/#{@ns}:Report/#{@ns}:Scenarios/#{@ns}:Scenario").first
return scenario
end

def get_first_utility_element(doc)
scenario = doc.get_elements("/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Reports/#{@ns}:Report/#{@ns}:Utilities/#{@ns}:Utility").first
return scenario
end

def get_first_hvac_system_element(doc)
scenario = doc.get_elements("/#{@ns}:BuildingSync/#{@ns}:Facilities/#{@ns}:Facility/#{@ns}:Systems/#{@ns}:HVACSystems/#{@ns}:HVACSystem").first
return scenario
end

def get_utility_from_file(xml_file_path)
doc = nil
File.open(xml_file_path, 'r') do |file|
doc = REXML::Document.new(file)
end
report = get_first_utility_element(doc)
return BuildingSync::Utility.new(report, @ns)
end

def get_report_from_file(xml_file_path)
doc = nil
File.open(xml_file_path, 'r') do |file|
doc = REXML::Document.new(file)
end
report = get_first_report_element(doc)
return BuildingSync::Report.new(report, @ns)
end

def get_facility_from_file(xml_file_path)
doc = nil
File.open(xml_file_path, 'r') do |file|
Expand Down
19 changes: 17 additions & 2 deletions lib/buildingsync/helpers/xml_get_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ def xget_idrefs(element_name)
return to_return
end

def xget_plurals_text_value(element_name)
plurals = @base_xml.get_elements(".//#{@ns}:#{element_name}s/#{@ns}:#{element_name}")
to_return = []
plurals.each do |p|
to_return << help_get_text_value(p)
end
return to_return
end

# Get the linked premises ids of the @base_xml element
# @return [Hash] where keys are premise types and values are an array of ids
# @example {'Building' => ['Building-1', 'Building-1'], 'Section' => ['Section-4']]}
Expand Down Expand Up @@ -183,8 +192,14 @@ def xset_or_create(element_name, new_value, override = true)
element.text = new_value
end
else
new_element = REXML::Element.new("#{@ns}:#{element_name}", @base_xml)
new_element.text = new_value
element = REXML::Element.new("#{@ns}:#{element_name}", @base_xml)
element.text = new_value
end
if element.text.nil?
raise StandardError, "Unable to set #{element_name} to nil"
end
if element.text.empty?
raise StandardError, "Unable to set #{element_name} to be empty"
end
return element
end
Expand Down
14 changes: 7 additions & 7 deletions lib/buildingsync/makers/workflow_maker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_workflow
# get scenario elements
# @return [Array<BuildingSync::Scenario>]
def get_scenarios
return @facility.scenarios
return @facility.report.scenarios
end

# generate the baseline model as osm model
Expand Down Expand Up @@ -384,25 +384,25 @@ def write_osws(main_output_dir)
# make sure paths exist
super

if @facility.cb_modeled.nil?
if @facility.report.cb_modeled.nil?
OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.WorkflowMaker.write_osws', 'OSW cannot be written since no current building modeled scenario is defined. One can be added after file import using the add_cb_modeled method')
raise StandardError, 'OSW cannot be written since no current building modeled scenario is defined. One can be added after file import using the add_cb_modeled method'
end

# Write a workflow for the current building modeled scenario
cb_modeled_success = write_osw(main_output_dir, @facility.cb_modeled)
cb_modeled_success = write_osw(main_output_dir, @facility.report.cb_modeled)
number_successful = cb_modeled_success ? 1 : 0

# write an osw for each Package Of Measures scenario
@facility.poms.each do |scenario|
@facility.report.poms.each do |scenario|
successful = write_osw(main_output_dir, scenario)
if successful
number_successful += 1
end
end

# Compare the total number of potential successes to the number of actual successes
really_successful = number_successful == @facility.poms.size + 1
really_successful = number_successful == @facility.report.poms.size + 1
return really_successful
end

Expand Down Expand Up @@ -527,11 +527,11 @@ def cleanup_larger_files(osw_dir)
# @return [Boolean]
def gather_results(year_val = Date.today.year, baseline_only = false)
# Gather results for the Current Building Modeled (Baseline) Scenario
@facility.cb_modeled.os_gather_results(year_val)
@facility.report.cb_modeled.os_gather_results(year_val)

if !baseline_only
# Gather results for the Package of Measures scenarios
@facility.poms.each do |scenario|
@facility.report.poms.each do |scenario|
scenario.os_gather_results(year_val)
end
end
Expand Down
10 changes: 2 additions & 8 deletions lib/buildingsync/model_articulation/building.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,8 @@ def set_width_and_length
def check_occupancy_classification(site_occupancy_classification)
# Set the OccupancyClassification text as that defined by the Site
# ONLY if it is not already defined
if !site_occupancy_classification.nil? && !site_occupancy_classification.empty?
xset_or_create('OccupancyClassification', site_occupancy_classification, false)
end
xset_or_create('OccupancyClassification', site_occupancy_classification, false)

if xget_text('OccupancyClassification').nil? || xget_text('OccupancyClassification').empty?
OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.check_occupancy_classification', 'OccupancyClassification must be set at either the Site or Building')
raise StandardError, 'BuildingSync.Building.check_occupancy_classification: OccupancyClassification must be set at either the Site or Building'
end
end

# Set the @built_year based on YearOfConstruction / YearOfLastMajorRemodel
Expand Down Expand Up @@ -197,7 +191,7 @@ def read_stories_above_and_below_grade

if @num_stories_below_grade > 1.0
OpenStudio.logFree(OpenStudio::Error, 'BuildingSync.Building.read_stories_above_and_below_grade', "Number of stories below grade is larger than 1: #{@num_stories_below_grade}, currently only one basement story is supported.")
raise "Error : Number of stories below grade is larger than 1: #{@num_stories_below_grade}, currently only one basement story is supported."
raise StandardError, "Building ID: #{xget_id}. Number of stories below grade is > 1 (#{num_stories_below_grade}). Currently, only one story below grade is supported."
end
end

Expand Down
Loading

0 comments on commit 211ca8d

Please sign in to comment.