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

Updates the patches with the eppy.ext_field_functions.increaseIDDfields #252

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions geomeppy/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from eppy.EPlusInterfaceFunctions.eplusdata import Eplusdata # noqa
from eppy.bunch_subclass import EpBunch as BaseBunch
from eppy.idf_msequence import Idf_MSequence
from eppy.idfreader import convertallfields, iddversiontuple
from eppy.idfreader import convertallfields, iddversiontuple, convertfields
Copy link
Owner

Choose a reason for hiding this comment

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

imports in alphabetical order please

from eppy.modeleditor import IDF as BaseIDF
from eppy.modeleditor import IDDNotSetError, namebunch, newrawobject

Expand Down Expand Up @@ -161,7 +161,7 @@ def addthisbunch(
"""
key = thisbunch.key.upper()
obj = copy.copy(thisbunch.obj)
abunch = obj2bunch(data, commdct, obj)
abunch = obj2bunch(data, commdct, obj, thisbunch.theidf.block)
bunchdt[key].append(abunch)
return abunch

Expand Down Expand Up @@ -191,39 +191,65 @@ def makebunches(


def obj2bunch(
data, commdct, obj
data, commdct, obj, block=None
Copy link
Owner

Choose a reason for hiding this comment

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

block argument is missed from the typing

): # type: (Eplusdata, List[List[Dict[str, Any]]], List[str]) -> EpBunch
"""Make a new bunch object using the data object.

:param data: Eplusdata object containing representions of IDF objects.
:param commdct: Descriptions of IDF fields from the IDD.
:param obj: List of field values in an object.
:param block: EnergyPlus field ID names of the IDF from the IDD. Defaults to None.
:returns: EpBunch object.

"""
dtls = data.dtls
key = obj[0].upper()
key_i = dtls.index(key)
abunch = makeabunch(commdct, obj, key_i)
abunch = makeabunch(commdct, obj, key_i, block)
return abunch


def makeabunch(
commdct, # type: List[List[Dict[str, Any]]]
obj, # type: Union[List[Union[float, str]], List[str]]
obj_i, # type: int
block=None, # type:
Copy link
Owner

Choose a reason for hiding this comment

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

missing type

debugidd=True,
Copy link
Owner

Choose a reason for hiding this comment

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

missing type

):
# type: (...) -> EpBunch
"""Make a bunch from the object.

:param commdct: Descriptions of IDF fields from the IDD.
:param obj: List of field values in an object.
:param obj_i: Index of the object in commdct.
:param block: EnergyPlus field ID names of the IDF from the IDD. Defaults to None.
:returns: EpBunch object.

"""
objidd = commdct[obj_i]
objfields = [comm.get("field") for comm in commdct[obj_i]] # type: List
objfields = [comm.get("field") for comm in commdct[obj_i]]
if debugidd:
import eppy.ext_field_functions as extff

if len(obj) > len(objfields):
# there are not enough fields in the IDD to match the IDF
# -- increase the number of fields in the IDD (in block and commdct)
# -- start
n = len(obj) - len(objfields)
key_txt = obj[0]
objfields = extff.increaseIDDfields(block, commdct, obj_i, key_txt, n)
# -- increase the number of fields in the IDD (in block and commdct)
# -- end
#
# -- convertfields for added fields - start
key_i = obj_i
key_comm = commdct[obj_i]
try:
inblock = block[obj_i]
except TypeError as e:
inblock = None
obj = convertfields(key_comm, obj, inblock)
# -- convertfields for added fields - end
Comment on lines +235 to +252
Copy link
Owner

Choose a reason for hiding this comment

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

Appreciate this is probably taken directly from eppy, but I'd prefer it to be split out as a function with all those inline comments turned into a docstring.

objfields[0] = ["key"]
objfields = [field[0] for field in objfields]
obj_fields = [bunchhelpers.makefieldname(field) for field in objfields]
Expand Down