Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate BETTER API from V1 to V2 #3881

Merged
merged 35 commits into from
Mar 22, 2023
Merged

Conversation

perryr16
Copy link
Contributor

@perryr16 perryr16 commented Feb 28, 2023

Any background context you want to provide?

The API service that the SEED platform uses to generate BETTER analysis has undergone a version change from V1 to V2. The V1 endpoints have been overwritten by the V2 endpoints breaking the existing functionality. It's worth noting that this is BETTER API V2, however, all endpoints still point to the api/v1/ URL.

V2 makes changes to how Portfolio Analyses are processed (a Portfolio is a collection of Buildings). In V1 a portfolio analysis was initiated and a building_analysis was created for each building in the portfolio. In V2 instead of creating building_analyses, a portfolio analysis will generate a portfolio_building_analysis for each building in the portfolio.

What's this PR do?

This PR migrates the BETTER pipeline functionality to the BETTER V2 endpoints.

  • new pathways to retrieve and store portfolio_building_analyses
  • updates to variable naming
  • Add a new Org Settings page button to verify the current token.

How should this be manually tested?

To test the BETTER token verification button

  • Go to organization settings > API Key > there is now a button to "Verify Token"
  • The button text and color will change to indicate a valid or invalid token.
  • You must save changes to reverify the token

To test the BETTER analyses

  • You must first have inventory that meets the better requirements. This includes meter data, property type, city, state, and gross floor area. Note that the property type "Office" is reliable.
  • select one property and run a better analysis > ensure a successful run and the property now displays the analysis results
  • select multiple properties and run a better analysis with "Run Portfolio Analysis" unchecked. Ensure a successful run and the selected properties show the analysis results
  • select multiple properties and run a better analysis with "Run Portfolio Analysis" checked. Ensure a successful run and the selected properties show the analysis results

What are the relevant tickets?

#3874

Screenshots (if appropriate)

Screenshot 2023-02-28 at 3 06 06 PM

Screenshot 2023-02-28 at 3 06 28 PM

Screenshot 2023-02-28 at 3 07 02 PM

Known issues

BETTER V2 introduces an enable_pvwatts analysis configuration key. This key has been hardcoded to false. Integrating this key will require further design.

Of the 3 active BETTER servers, production and staging are functional, while development is missing endpoints.

Within the /buildingsync.py file of SEED, there are a number of property_types that are defined as accepted BETTER (and bsync) properties, however several of them will cause a BETTER analysis to fail.

  • passing types: Office, Hotel, K-12 School, Multifamily Housing
  • failing types: Hospital (General Medical & Surgical), Bank Branch, Courthouse, Data Center, Distribution Center, Financial Office, Non-Refrigerated Warehouse, Refrigerated Warehouse, Retail Store, Senior Care Community, Supermarket/Grocery Store, Other

@perryr16 perryr16 added the Maintenance Tag as maintenance if the issue relates to general cleanup, maintenance, etc. Do not delete label. label Feb 28, 2023
Comment on lines +45 to +47
# BETTER_HOST = os.environ.get('BETTER_HOST', 'https://better.lbl.gov')
BETTER_HOST = os.environ.get('BETTER_HOST', 'https://better-lbnl-staging.herokuapp.com')
# BETTER_HOST = os.environ.get('BETTER_HOST', 'https://better-lbnl-development.herokuapp.com')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the writing of this, production and staging servers are functional and the development server is missing endpoints

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 47 doesn't seem necessary here.



def _store_better_portfolio_analysis_results(better_analysis_id, better_building_analyses, context):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better_analysis_id can be found in better_building_analyses

Comment on lines +359 to +362
_store_better_building_analysis_results(
better_building_analyses,
context,
)
Copy link
Contributor Author

@perryr16 perryr16 Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_store_better_building_analysis_results should only be run if better_portfolio_id is None

@perryr16 perryr16 marked this pull request as ready for review March 1, 2023 16:47
Copy link
Contributor

@anchapin anchapin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything from this PR works as intended. Good job!

Comment on lines +45 to +47
# BETTER_HOST = os.environ.get('BETTER_HOST', 'https://better.lbl.gov')
BETTER_HOST = os.environ.get('BETTER_HOST', 'https://better-lbnl-staging.herokuapp.com')
# BETTER_HOST = os.environ.get('BETTER_HOST', 'https://better-lbnl-development.herokuapp.com')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 47 doesn't seem necessary here.

@perryr16
Copy link
Contributor Author

perryr16 commented Mar 8, 2023

Below are the results from various Analysis configuration tests. Note that it's important that the analysis "Run" doesn't fail if BETTER returns an error for one building in an analysis. This allows results for other buildings in the analysis to be processed.

SINGLE BUILIDNGS

  1. 1 Valid Property Type ("Hotel")
    Analysis completes with data
  2. 1 Invalid Property Type ("Bank Branch")
    The analysis "completes", however, the building has the following under "latest message"
    - Building Analysis generation status returned "FAILED": Internal error. Could not generate building analytics. No benchmark data is defined for country US and space type BANK_BRANCH
  3. 1 building without a Property Type
    The analysis fails with the following "latest message"
    - Error preparing BETTER input: BETTER analysis requires the property's type must be one of the following: Office, Hotel, K-12 School, Hospital (General Medical & Surgical), Bank Branch, Courthouse, Data Center, Distribution Center, Financial Office, Mul..
  4. 1 building with unsupported Property Type ("Unsupported Type")
    The analysis fails with the following "latest message"
    - Error preparing BETTER input: BETTER analysis requires the property's type must be one of the following: Office, Hotel, K-12 School, Hospital (General Medical & Surgical), Bank Branch, Courthouse, Data Center, Distribution Center, Financial Office, Mul...

MULTIPLE BUILDINGS - NON PORTFOLIO

  1. 2 Valid Property Type ("Hotel"). Non-Portfolio
    Analysis completes and each building has valid and unique analysis data
  2. 2 Invalid Property Type ("Bank Branch"). Non-Portfolio
    The Analysis completes with the following errors on each building
    - Building Analysis generation status returned "FAILED": Internal error. Could not generate building analytics. No benchmark data is defined for country US and space type BANK_BRANCH
  3. 1 Valid and 1 Invalid building. Non-Portfolio
    The analysis completes, the valid property has analysis data while the unsuported type returns
    - BETTER analysis could not be fetched: Status Code: 404 Not found.
    - Building Analysis generation status returned "FAILED": Internal error. Could not generate building analytics. No benchmark data is defined for country US and space type BANK_BRANCH

PORTFOLIOS

  1. 2 Valid Property Type ("Hotel"). Portfolio. Default Benchmark Data Type
    The analysis completes with valid data
  2. 2 Valid Property Type ("Hotel"). Portfolio. Generate Benchmark Data Type
    The analysis completes with valid data
  3. 2 Invalid Property Type ("Bank Branch"). Portfolio. Default Benchmark Data Type
    The analysis completes with the following errors on each property
    - BETTER analysis could not be fetched: Status Code: 404 Not found.
    - Building Analysis generation status returned "FAILED": Internal error. Could not generate building analytics. No benchmark data is defined for country US and space type BANK_BRANCH
  4. 2 Invalid Property Type ("Bank Branch"). Portfolio. Generate Benchmark Data Type
    The analysis completes with valid data. This is expected, the BETTER documentation states that if all buildings in a portfolio are of the same type, but no default benchmark data, it can be run if the "GENERATE" option is selected as the Benchmark Data Type
  5. 1 Valid and 1 Invalid Property Type ("Hotel", "Bank Branch"). Portfolio. Default or Generate Benchmark Data Type
    The Analysis fails because portfolios must be of the same property type. The Portfolio Analysis's latest message is
    - Failed to generate BETTER portfolio analysis: All buildings in portfolio analytics must be of same space type (found space types: HOTEL,BANK_BRANCH)
  6. 1 Valid and 1 Unsupported Property Type ("Office", "Unsupported Type"). Portfolio. Default or Generate Benchmark Data
    The analysis completes but the unsupported property types have been excluded from the portfolio as no BETTER building was created. The results are present for those with valid property types.
    The failing building has the following error message
    - Error preparing BETTER input: BETTER analysis requires the property's type must be one of the following: Office, Hotel, K-12 School, Hospital (General Medical & Surgical), Bank Branch, Courthouse, Data Center, Distribution Center, Financial Office, Mul...

@perryr16
Copy link
Contributor Author

perryr16 commented Mar 9, 2023

Added the ability to display warning messages for portfolio analysis if it is created with less than 30 buildings.
Screenshot 2023-03-09 at 2 27 01 PM

@RDmitchell
Copy link

@perryr16 -- looks great ! Thx

@kflemin kflemin self-requested a review March 10, 2023 05:42
Copy link
Contributor

@kflemin kflemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Copy link
Member

@nllong nllong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worked as expected! The change of single vs portfolio of buildings is strange, but c'est la vie.

Good work!

perryr16 and others added 4 commits March 21, 2023 12:49
…date_range' to match other analyses functionality
# Conflicts:
#	seed/static/seed/partials/analyses.html
#	seed/static/seed/partials/analysis_details.html
#	seed/static/seed/partials/inventory_detail_analyses_modal.html
@axelstudios
Copy link
Member

I fixed a some minor issues, primarily that the BETTER_TOKEN_TEXT wasn't using translate correctly so the URL appeared in the hyperlink but not printed at the end.

Issues that remain to be fixed
  • There are tons of docstring errors in the BETTER code, where params and return values don't accurately reflect the inputs/outputs

@axelstudios axelstudios merged commit e07f088 into develop Mar 22, 2023
@axelstudios axelstudios deleted the 3874-BETTER-v2-migration branch March 22, 2023 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Tag as maintenance if the issue relates to general cleanup, maintenance, etc. Do not delete label.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants