Code improvements for AEO Update#607
Draft
yingli-NREL wants to merge 9 commits into
Draft
Conversation
✅ Integration Test ResultsUbuntu (Baseline)
Cross-Platform Results
|
Collaborator
|
@yingli-NREL The network graph shows this PR as having commits that aren't covered by the aeo2026-update branch - #613 - so I think we don't want to close this yet? |
Collaborator
Author
Do not close it. Will first get the aeo2026-update branch done. Then work on this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Put this one on hold for now. Will focus on the AEO 2026 update first. #613
related issue: #503
Extract Hardcoded Constants to Config
Benefit: Single point of change, better documentation.
Replace Print Statements with Logging
Benefit: Better debugging, log filtering by severity.
Add Request Timeouts=30
Benefit: Prevents hanging requests, improves reliability.
Add Type Hints for
api_query(),data_processor()inconverter.pyBenefit: IDE support, type checking (mypy), self-documenting code.
Add API Response Validation
Benefit: Checks the JSON structure before accessing nested keys. Catches data corruption early, prevents silent failures
Create
validate_user_input()function with retry limitsBenefit: Eliminates infinite loops, improves user experience
Create safe_update() helper function to improve the Try-Except Error Handling in
converter.pyBenefit: Reduces code, eliminates duplication
Add Data Validation Before File Writes
Validate annual emissions/price JSON before writing to file. Checks that CO2 intensity data contains expected regions and that year-keyed values are numeric and non-negative
Validate hourly scaling factor JSON before writing to file. Checks that the expected metric key exists, each region has EXPECTED_HOURS_PER_YEAR values per year, and values are numeric.
Benefit: Prevents corrupted output files, catches calculation errors
Refactor Duplicated State/EMM Processing
Extract geographic processing into single parameterized function
Benefit: Eliminates code duplication, easier maintenance