Skip to content

Commit

Permalink
Merge pull request #113 from urbanopt/develop
Browse files Browse the repository at this point in the history
Version 0.2.0
  • Loading branch information
kflemin authored Mar 30, 2020
2 parents a392792 + 9ae1e29 commit aa1af90
Show file tree
Hide file tree
Showing 49 changed files with 1,062 additions and 65 deletions.
35 changes: 34 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# URBANopt Scenario Gem


## Version 0.2.0


Date Range: 01/15/20 - 03/30/20:

- Fixed [#27]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/27 ), FeatureReports are not initialized with location information.
- Fixed [#38]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/38 ), Write documentation on how to configure ScenarioRunner to run multiple OSWs in parallel
- Fixed [#42]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/42 ), Scenario Report Instantiation from Hash
- Fixed [#43]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/43 ), Add timestep column to timeseries csv or add start and end timestep to feature and scenario reports
- Fixed [#46]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/46 ), add Validator class
- Fixed [#52]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/52 ), create a save as method that takes a file name
- Fixed [#54]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/54 ), Add constraint on the versions of ruby in the gemspec file
- Fixed [#56]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/56 ), Add folder for mapper csv files
- Fixed [#58]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/58 ), post process results
- Fixed [#59]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/59 ), figure out how UrbanOpt will select tariff structure for REopt
- Fixed [#65]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/65 ), make default timeseries csv for scenario; update adding feature timeseries
- Fixed [#67]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/67 ), update vuepress version
- Fixed [#70]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/70 ), updates to Scenario Gem to Support REopt Release
- Fixed [#74]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/74 ), Update copyrights
- Fixed [#75]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/75 ), make github_api a development dependency
- Fixed [#81]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/81 ), add thermal comfort results and timestamp to reports
- Fixed [#83]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/83 ), add multiple pV
- Fixed [#88]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/88 ), add units to CSV reports
- Fixed [#89]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/89 ), created Save feature report method
- Fixed [#91]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/91 ), add total_costruction_cost to reports
- Fixed [#95]( https://github.com/urbanopt/urbanopt-scenario-gem/issues/95 ), list datapoint failures
- Fixed [#98]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/98 ), add power, net power, net energy and apparent power to timeseries results
- Fixed [#101]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/101 ), fix for unit conversion when timeseries doe not exist
- Fixed [#102]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/102 ), add opendss post_processor
- Fixed [#104]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/104 ), add power distribution results to schema and reports
- Fixed [#110]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/110 ), save transformer features CSV and JSON reports
- Fixed [#112]( https://github.com/urbanopt/urbanopt-scenario-gem/pull/112 ), added additional timeseries results to CSV reports

## Version 0.1.1

Date Range: 10/16/19 - 01/14/20
Expand Down
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,3 @@ end

# simplecov has an unnecessary dependency on native json gem, use fork that does not require this
gem 'simplecov', github: 'NREL/simplecov'

# Fix rack version temporarily to work with Ruby 2.2.4
gem 'rack', '2.1.2'
28 changes: 25 additions & 3 deletions lib/measures/default_feature_reports/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ def energyPlusOutputRequests(runner, user_arguments)
result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,Gas:Facility,#{reporting_frequency};").get
result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,DistrictCooling:Facility,#{reporting_frequency};").get
result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,DistrictHeating:Facility,#{reporting_frequency};").get
# result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,Cooling:Electricity,#{reporting_frequency};").get
# result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,Heating:Electricity,#{reporting_frequency};").get
# result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,InteriorLights:Electricity,#{reporting_frequency};").get
# result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,ExteriorLights:Electricity,#{reporting_frequency};").get
# result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,InteriorEquipment:Electricity,#{reporting_frequency};").get
# result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,Fans:Electricity,#{reporting_frequency};").get
# result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,Pumps:Electricity,#{reporting_frequency};").get
# result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,WaterSystems:Electricity,#{reporting_frequency};").get
# result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,Heating:Gas,#{reporting_frequency};").get
# result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,WaterSystems:Gas,#{reporting_frequency};").get
# result << OpenStudio::IdfObject.load("Output:Meter:MeterFileOnly,InteriorEquipment:Gas,#{reporting_frequency};").get

timeseries_data = ['District Cooling Chilled Water Rate', 'District Cooling Mass Flow Rate',
'District Cooling Inlet Temperature', 'District Cooling Outlet Temperature',
Expand Down Expand Up @@ -608,6 +619,17 @@ def run(runner, user_arguments)
'Electricity:Facility',
'ElectricityProduced:Facility',
'Gas:Facility',
'Cooling:Electricity',
'Heating:Electricity',
'InteriorLights:Electricity',
'ExteriorLights:Electricity',
'InteriorEquipment:Electricity',
'Fans:Electricity',
'Pumps:Electricity',
'WaterSystems:Electricity',
'Heating:Gas',
'WaterSystems:Gas',
'InteriorEquipment:Gas',
'DistrictCooling:Facility',
'DistrictHeating:Facility',
'District Cooling Chilled Water Rate',
Expand Down Expand Up @@ -646,7 +668,7 @@ def run(runner, user_arguments)
total_seconds = (60 / timesteps_per_hour.to_f) * 60 # make sure timesteps_per_hour is a float in the division
total_hours = 1 / timesteps_per_hour.to_f # make sure timesteps_per_hour is a float in the division
# set power_conversion
power_conversion = total_hours
power_conversion = total_hours # we set the power conversio to total_hours since we want to convert lWh to kW
puts "Power Converion: to convert kWh to kW values will be divided by #{power_conversion}"

# number of values in each timeseries
Expand Down Expand Up @@ -768,7 +790,7 @@ def run(runner, user_arguments)
newVals[j] = (values[tsToKeepIndexes['Electricity:Facility']][j].to_f - values[tsToKeepIndexes['ElectricityProduced:Facility']][j].to_f) / power_conversion / powerFactor
j += 1
end
new_unit = 'kW'
new_unit = 'kVA'
elsif timeseries_name.include? 'Net Electric Energy'
(0..n - 1).each do |j|
newVals[j] = (values[tsToKeepIndexes['Electricity:Facility']][j].to_f - values[tsToKeepIndexes['ElectricityProduced:Facility']][j].to_f)
Expand Down Expand Up @@ -798,7 +820,7 @@ def run(runner, user_arguments)
newVals[j] = values[indexValue][j].to_f / power_conversion / powerFactor
j += 1
end
new_unit = 'kW'
new_unit = 'kVA'
else
# Power calculation
(0..n - 1).each do |j|
Expand Down
6 changes: 3 additions & 3 deletions lib/measures/default_feature_reports/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<schema_version>3.0</schema_version>
<name>default_feature_reports</name>
<uid>9ee3135a-8070-4408-bfa1-b75fecf9dd4f</uid>
<version_id>607df4a0-d1ff-4c14-8d2f-93cde078dc47</version_id>
<version_modified>20200308T020104Z</version_modified>
<version_id>dcf043ff-d992-4835-893d-8658a6365eb3</version_id>
<version_modified>20200329T155122Z</version_modified>
<xml_checksum>FB304155</xml_checksum>
<class_name>DefaultFeatureReports</class_name>
<display_name>DefaultFeatureReports</display_name>
Expand Down Expand Up @@ -137,7 +137,7 @@
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>DC29E5E6</checksum>
<checksum>DF6AAD06</checksum>
</file>
</files>
</measure>
1 change: 1 addition & 0 deletions lib/urbanopt/scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
require 'urbanopt/scenario/scenario_csv'
require 'urbanopt/scenario/scenario_post_processor_base'
require 'urbanopt/scenario/scenario_post_processor_default'
require 'urbanopt/scenario/scenario_post_processor_opendss'
require 'urbanopt/scenario/scenario_runner_base'
require 'urbanopt/scenario/scenario_runner_osw'
require 'urbanopt/scenario/simulation_dir_base'
Expand Down
11 changes: 8 additions & 3 deletions lib/urbanopt/scenario/default_reports/distributed_generation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ class DistributedGeneration
#
attr_accessor :total_storage_kw

##
# _Float_ - Installed storage capacity
#
attr_accessor :total_storage_kwh

##
# _Float_ - Installed generator capacity
#
Expand Down Expand Up @@ -286,15 +291,15 @@ def to_hash
result[:solar_pv].push pv.to_hash
end
result[:wind] = []
@wind.each do |pv|
@wind.each do |wind|
result[:wind].push wind.to_hash
end
result[:generator] = []
@generator.each do |pv|
@generator.each do |generator|
result[:generator].push generator.to_hash
end
result[:storage] = []
@storage.each do |pv|
@storage.each do |storage|
result[:storage].push storage.to_hash
end
return result
Expand Down
21 changes: 14 additions & 7 deletions lib/urbanopt/scenario/default_reports/feature_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
require 'urbanopt/scenario/default_reports/location'
require 'urbanopt/scenario/default_reports/reporting_period'
require 'urbanopt/scenario/default_reports/timeseries_csv'
require 'urbanopt/scenario/default_reports/validator'
require 'urbanopt/scenario/default_reports/distributed_generation'
require 'urbanopt/scenario/default_reports/power_distribution'

require 'urbanopt/scenario/default_reports/validator'
require 'json-schema'

require 'json'
Expand All @@ -52,7 +53,7 @@ module DefaultReports
##
class FeatureReport
attr_accessor :id, :name, :directory_name, :feature_type, :timesteps_per_hour, :simulation_status,
:timeseries_csv, :location, :program, :design_parameters, :construction_costs, :reporting_periods, :distributed_generation # :nodoc:
:timeseries_csv, :location, :program, :design_parameters, :construction_costs, :reporting_periods, :distributed_generation, :power_distribution # :nodoc:
##
# Each FeatureReport object corresponds to a single Feature.
##
Expand Down Expand Up @@ -84,7 +85,9 @@ def initialize(hash = {})
@reporting_periods << ReportingPeriod.new(rp)
end

@distributed_generation = DistributedGeneration.new(hash[:distributed_generation] || {})
@distributed_generation = DistributedGeneration.new(hash[:distributed_generation])

@power_distribution = PowerDistribution.new(hash[:power_distribution])

# initialize class variables @@validator and @@schema
@@validator ||= Validator.new
Expand All @@ -104,6 +107,8 @@ def defaults
hash[:program] = {}
hash[:construction_costs] = []
hash[:reporting_periods] = []
hash[:distributed_generation] = {}
hash[:power_distribution] = {}
return hash
end

Expand Down Expand Up @@ -203,6 +208,8 @@ def to_hash

result[:distributed_generation] = @distributed_generation.to_hash if @distributed_generation

result[:power_distribution] = @power_distribution.to_hash if @power_distribution

# validate feature_report properties against schema
if @@validator.validate(@@schema[:definitions][:FeatureReport][:properties], result).any?
raise "feature_report properties does not match schema: #{@@validator.validate(@@schema[:definitions][:FeatureReport][:properties], result)}"
Expand All @@ -216,7 +223,7 @@ def to_hash
##
# [parameters]:
# +file_name+ - _String_ - Assign a name to the saved feature report results file without an extension
def save_feature_report(file_name = 'updated_default_feature_report')
def save_feature_report(file_name = 'default_feature_report')
# reassign the initialize local variable @file_name to the file name input.
@file_name = file_name

Expand All @@ -232,13 +239,13 @@ def save_feature_report(file_name = 'updated_default_feature_report')
@timeseries_csv.path = File.join(@directory_name, 'feature_reports', file_name + '.csv')
@timeseries_csv.save_data

hash = {}
hash[:feature_report] = to_hash
# feature_hash
feature_hash = to_hash

json_name_path = File.join(@directory_name, 'feature_reports', file_name + '.json')

File.open(json_name_path, 'w') do |f|
f.puts JSON.pretty_generate(hash)
f.puts JSON.pretty_generate(feature_hash)
# make sure data is written to the disk one way or the other
begin
f.fsync
Expand Down
102 changes: 102 additions & 0 deletions lib/urbanopt/scenario/default_reports/power_distribution.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# *********************************************************************************
# URBANopt, Copyright (c) 2019-2020, Alliance for Sustainable Energy, LLC, and other
# contributors. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# 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.
#
# Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 OR CONTRIBUTORS 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.
# *********************************************************************************

require 'json'
require 'urbanopt/scenario/default_reports/validator'
require 'json-schema'

module URBANopt
module Scenario
module DefaultReports
##
# power_distributio include eletrical power distribution systems information.
##
class PowerDistribution
attr_accessor :under_voltage_hours, :over_voltage_hours # :nodoc:
##
# PowerDistrinution class intialize all power_distribution attributes:
# +:under_voltage_hours+ , +:over_voltage_hours+
##
# [parameters:]
# +hash+ - _Hash_ - A hash which may contain a deserialized power_distribution.
##
def initialize(hash = {})
hash.delete_if { |k, v| v.nil? }
hash = defaults.merge(hash)

@under_voltage_hours = hash[:under_voltage_hours]
@over_voltage_hours = hash[:over_voltage_hours]

# initialize class variables @@validator and @@schema
@@validator ||= Validator.new
@@schema ||= @@validator.schema
end

##
# Assigns default values if attribute values do not exist.
##
def defaults
hash = {}
hash[:under_voltage_hours] = nil
hash[:over_voltage_hours] = nil

return hash
end

##
# Converts to a Hash equivalent for JSON serialization.
##
# - Exclude attributes with nil values.
# - Validate power_distribution hash properties against schema.
##
def to_hash
result = {}
result[:under_voltage_hours] = @under_voltage_hours if @under_voltage_hours
result[:over_voltage_hours] = @over_voltage_hours if @over_voltage_hours

# validate power_distribution properties against schema
if @@validator.validate(@@schema[:definitions][:PowerDistribution][:properties], result).any?
raise "power_distribution properties does not match schema: #{@@validator.validate(@@schema[:definitions][:PowerDistribution][:properties], result)}"
end

return result
end

##
# Merges muliple power distribution results together.
##
# +new_costs+ - _Array_ - An array of ConstructionCost objects.
def merge_power_distribition
# method to be developed for any attributes to be aggregated or merged
end
end
end
end
end
8 changes: 7 additions & 1 deletion lib/urbanopt/scenario/default_reports/scenario_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def save(file_name = 'default_scenario_report')
# reassign the initialize local variable @file_name to the file name input.
@file_name = file_name

# save the csv data
# save the scenario reports csv and json data
old_timeseries_path = nil
if !@timeseries_csv.path.nil?
old_timeseries_path = @timeseries_csv.path
Expand Down Expand Up @@ -184,6 +184,12 @@ def save(file_name = 'default_scenario_report')
else
@timeseries_csv.path = File.join(@directory_name, file_name + '.csv')
end

# save the feature reports csv and json data
# @feature_reports.each do |feature_report|
# feature_report.save_feature_report()
# end

return true
end

Expand Down
Loading

0 comments on commit aa1af90

Please sign in to comment.