Customization
Advanced developers may choose to customize the URBANopt REopt Gem. For example, more attributes are returned from the REopt API and saved to disk than currently can be recorded in a Feature or Scenario Report. In these cases, developers will want to clone the URBANopt REopt Gem and possibly the URBANopt Reporting Gem and make modifications to these codebases. Such changes can be made accessible through CLI commands (installed from a cloned URBANopt CLI repo) or a local project. See Developer Resources for more information about setting up local gems and installing them through modifications to your project’s Gemfile.
Adding additional REopt Responses to your Feature and Scenario Reports
To include additional REopt API responses to your Feature and Scenario Reports follow the steps we outline below for adding optimal lifecycle costs from a REopt API response to Feature and Scenario Reports.
-
We’ll need to update the Feature and Scenario Report schema to allow for new attributes, so clone URBANopt Reporting Gem to your local machine.
$ git clone https://github.com/urbanopt/urbanopt-reporting-gem -
Later we’ll need to also update the URBANopt REopt Gem to parse these additional attributes from the REopt API response, so clone this now in the same directory as the URBANopt Scenario Gem repository with:
$ git clone https://github.com/urbanopt/urbanopt-reopt-gem -
Let’s first update the URBANopt Reporting Gem. The
distributed_generationschema used by Feature and Scenario Reports is defined in this repository and needs to handle new attributes.We’ll add
lcc_us_dollarshere as an example.First, open
urbanopt-reporting-gem/lib/urbanopt/reporting/default_reports/distributed_generation.rbNext, in the
DistributedGenerationclass add a new attribute accessor:module URBANopt module Reporting module DefaultReports ## # Onsite distributed generation system (i.e. SolarPV, Wind, Storage, Generator) design attributes and financial metrics. ## class DistributedGeneration ## # _Float_ - Lifecycle costs for the complete distributed generation system in US Dollars # attr_accessor :lcc_us_dollarsThen, within the
initializefunction parse the attribute when the object is instantiated:def initialize(hash = {}) hash.delete_if { |k, v| v.nil? } @lcc_us_dollars = hash[:lcc_us_dollars]Also, within the
to_hashfunction, make sure the attribute will be exported when the report is saved:def to_hash result = {} result[:lcc_us_dollars] = @lcc_us_dollars if @lcc_us_dollarsFinally, within the
merge_distributed_generationfunction, make sure the attribute will be added when two reports are combined:def self.merge_distributed_generation(existing_dgen, new_dgen) existing_dgen.lcc_us_dollars = add_values(existing_dgen.lcc_us_dollars, new_dgen.lcc_us_dollars)You’re now all set updating the
distributed_generationschema. -
Let’s next update URBANopt REopt Gem to load lifecycle costs from the REopt API responses into the Feature and Scenario Report
distributed_generationschema’slcc_us_dollarsattribute.First, in
urbanopt-reopt-gem/Gemfilemake sure that theurbanopt-reportinggem is loaded as follows:gem 'urbanopt-reporting', path: '../urbanopt-reporting-gem'This will ensure that the
urbanopt-sceanriogem that theurbanopt-reoptgem uses includes the schema we just modified.Note: You can alternatively specify a gem from a branch on github as follows:
gem 'urbanopt-reporting', github: '<repo address>', branch: '<branch name>''Next, in
urbanopt-reopt-gem/lib/reopt/feature_report_adapter.rbin theupdate_feature_reportfunction, parse the REopt API response:# Update distributed generation sizing and financials feature_report.distributed_generation.lcc_us_dollars = reopt_output['outputs']['Scenario']['Site']['Financial']['lcc_us_dollars'] || 0For an example of a REopt API response refer to this file. Also, the REopt API output schema is documented here.
Finally, in
urbanopt-reopt-gem/lib/reopt/scenario_report_adapter.rbin theupdate_scenario_reportfunction, parse the lifecycle cost from the REopt API response:# Update distributed generation sizing and financials scenario_report.distributed_generation.lcc_us_dollars = reopt_output['outputs']['Scenario']['Site']['Financial']['lcc_us_dollars'] || 0You are now ready to navigate to the
urbanopt-reopt-gemfolder and run:$ bundle install $ bundle update -
Now, when you reference this modified
urbanopt-reoptimplementation you can access the lifecycle costs fromfeature_report.distributed_generation.lcc_us_dollarsorscenario_report.distributed_generation.lcc_us_dollars. The lifecycle costs will also be included when a Feature or Scenario Report is saved.