Skip to content

Commit

Permalink
EpBunch extension added to return the dict representation of the obje…
Browse files Browse the repository at this point in the history
…ct (#210)

* EpBunch extension added to return the dict representation of the object

* Added for idf_msequence
  • Loading branch information
Samuel Letellier-Duchesne authored Aug 26, 2021
1 parent d5868e3 commit 85f513b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions archetypal/idfclass/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

from eppy.bunch_subclass import BadEPFieldError
from eppy.EPlusInterfaceFunctions.eplusdata import Eplusdata, Idd, removecomment
from eppy.idf_msequence import Idf_MSequence
from geomeppy.patches import EpBunch

from archetypal.utils import extend_class, log


@extend_class(EpBunch)
def __eq__(self, other):
def __eq__(self: EpBunch, other):
"""Test the equality of two EpBunch objects using all attribute values."""
if not isinstance(other, EpBunch):
return False
return all(str(a).upper() == str(b).upper() for a, b in zip(self.obj, other.obj))


@extend_class(EpBunch)
def nameexists(self):
def nameexists(self: EpBunch):
"""Return True if EpBunch Name already exists in idf.idfobjects[KEY]."""
existing_objs = self.theidf.idfobjects[self.key.upper()]
try:
Expand All @@ -28,7 +29,7 @@ def nameexists(self):


@extend_class(EpBunch)
def get_default(self, name):
def get_default(self: EpBunch, name):
"""Return the default value of a field"""
if "default" in self.getfieldidd(name).keys():
_type = _parse_idd_type(self, name)
Expand All @@ -38,8 +39,20 @@ def get_default(self, name):
return ""


@extend_class(EpBunch)
def to_dict(self: EpBunch):
"""Get the dict representation of the EpBunch."""
return {k: v for k, v in zip(self.fieldnames, self.fieldvalues)}


@extend_class(Idf_MSequence)
def to_dict(self: Idf_MSequence):
"""Get the list of dict representation of the Idf_Msequence."""
return [obj.to_dict() for obj in self]


@extend_class(Eplusdata)
def makedict(self, dictfile, fnamefobject):
def makedict(self: Eplusdata, dictfile, fnamefobject):
"""stuff file data into the blank dictionary."""
# fname = './exapmlefiles/5ZoneDD.idf'
# fname = './1ZoneUncontrolled.idf'
Expand Down

0 comments on commit 85f513b

Please sign in to comment.