-
Notifications
You must be signed in to change notification settings - Fork 32
Reorganize ecm_prep.py #473
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
Open
aspeake
wants to merge
8
commits into
master
Choose a base branch
from
ecm_prep_reorg
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
abf4eef
Breakout ecm_prep shared methods and variable classes in separate mod…
aspeake 6b1fc41
Make breakout_mseg an instance method in Measure.
aspeake 975ceaa
Further encapsulate ecm_prep methods; remove unused EPlusGlobals class.
aspeake daa9455
New class ECMPrep, store all ecm_prep functions in classes
aspeake 46d393b
Pass logger to verboseprint method, style fixes
aspeake ff1da71
Remove EnergyPlus mapping functions and tests.
aspeake 1e5d0b2
Rename ECMUtils, move method into it
aspeake 4b4900a
Delete unused methods
aspeake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import json | ||
import numpy | ||
import logging | ||
from pathlib import Path, PurePath | ||
|
||
|
||
class JsonIO: | ||
@staticmethod | ||
def load_json(filepath: Path) -> dict: | ||
"""Loads data from a .json file | ||
|
||
Args: | ||
filepath (pathlib.Path): filepath of .json file | ||
|
||
Returns: | ||
dict: .json data as a dict | ||
""" | ||
with open(filepath, 'r') as handle: | ||
try: | ||
data = json.load(handle) | ||
except ValueError as e: | ||
raise ValueError(f"Error reading in '{filepath}': {str(e)}") from None | ||
return data | ||
|
||
@staticmethod | ||
def dump_json(data, filepath: Path): | ||
"""Export data to .json file | ||
|
||
Args: | ||
data: data to write to .json file | ||
filepath (pathlib.Path): filepath of .json file | ||
""" | ||
with open(filepath, "w") as handle: | ||
json.dump(data, handle, indent=2, cls=MyEncoder) | ||
|
||
|
||
class MyEncoder(json.JSONEncoder): | ||
"""Convert numpy arrays to list for JSON serializing.""" | ||
|
||
def default(self, obj): | ||
"""Modify 'default' method from JSONEncoder.""" | ||
# Case where object to be serialized is numpy array | ||
if isinstance(obj, numpy.ndarray): | ||
return obj.tolist() | ||
if isinstance(obj, PurePath): | ||
return str(obj) | ||
# All other cases | ||
else: | ||
return super(MyEncoder, self).default(obj) | ||
|
||
|
||
class PrintFormat: | ||
"""Class for customizing print messages.""" | ||
|
||
@staticmethod | ||
def custom_showwarning(message, category, filename, lineno, file=None, line=None): | ||
"""Define a custom warning message format.""" | ||
# Other message details suppressed because error location and type are not relevant | ||
print(message) | ||
|
||
@staticmethod | ||
def verboseprint(verbose, msg, log_type, logger=None): | ||
"""Print input message when the code is run in verbose mode. | ||
|
||
Args: | ||
verbose (boolean): Indicator of verbose mode | ||
msg (string): Message to print to console when in verbose mode | ||
logger: Logger instance to use for logging | ||
""" | ||
if not verbose: | ||
return | ||
if not logger: | ||
logger = logging.getLogger(__name__) | ||
|
||
if log_type == "info": | ||
logger.info(msg) | ||
elif log_type == "warning": | ||
logger.warning(msg) | ||
elif log_type == "error": | ||
logger.error(msg) | ||
|
||
@staticmethod | ||
def format_console_list(list_to_format): | ||
return [f" {elem}\n" for elem in list_to_format] |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.