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

New: Return default value of fieldvalue when possible #252

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
02157fb
Return default value when possible
samuelduchesne Aug 5, 2019
cc29bbe
Code cleanup
samuelduchesne Aug 6, 2019
1ebec2a
Adds a test for default values
samuelduchesne Aug 6, 2019
610a345
Since __getattr__ now returns the default value when a fieldvalue is …
samuelduchesne Aug 6, 2019
7d3ccf4
Adds more types to parse_idd_type
samuelduchesne Aug 6, 2019
4f9ea7a
Extends the default logic to all returned values that are equal to an…
samuelduchesne Aug 6, 2019
a4ec709
Adds another test
samuelduchesne Aug 6, 2019
b713149
Fixes an issue where run errors could not be read because of suffix d…
samuelduchesne Aug 6, 2019
fd8789c
Adds expandobject=True to testrunners to assert tests
samuelduchesne Aug 6, 2019
79db7d1
Merge branch 'develop' into feature/defaults
samuelduchesne Aug 20, 2019
a0d2ef5
Revert "Adds expandobject=True to testrunners to assert tests"
samuelduchesne Aug 6, 2019
e6375ac
Black
samuelduchesne Jul 8, 2020
1422b91
addresses issue #303
samuelduchesne Sep 2, 2020
8216057
Merge branch 'develop' into 303-eppy-suffers-from-performance-issues
samuelduchesne Sep 3, 2020
8f8eba0
Moves the creation of the IDD index and the addition of idd groups to…
samuelduchesne Sep 3, 2020
a84753c
Merge branch 'develop' into feature/defaults
samuelduchesne Sep 3, 2020
eb671c7
Merge branch '303-eppy-suffers-from-performance-issues' into feature/…
samuelduchesne Sep 3, 2020
cab7bda
Using regex improves speed (a little bit slower then encode/decode) b…
samuelduchesne Sep 3, 2020
588b3fe
group info must happen before idd_index
samuelduchesne Sep 3, 2020
841d376
Merge branch '303-eppy-suffers-from-performance-issues' into feature/…
samuelduchesne Sep 3, 2020
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
15 changes: 12 additions & 3 deletions eppy/EPlusInterfaceFunctions/parse_idd.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ def embedgroupdata(extract_func, fname, debug):
return blocklst, commlst, commdct


@make_idd_index
@embedgroupdata
def extractidddata(fname, debug=False):
"""
extracts all the needed information out of the idd file
Expand Down Expand Up @@ -375,7 +373,18 @@ def extractidddata(fname, debug=False):
# commlst = group2commlst(commlst, glist)
# commdct = group2commdct(commdct, glist)

return blocklst, commlst, commdct
# add group information to commlst and commdct
glist = iddgroups.iddtxt2grouplist(astr)
commlst = iddgroups.group2commlst(commlst, glist)
commdct = iddgroups.group2commdct(commdct, glist)

# Make IDD Index
name2refs = iddindex.makename2refdct(commdct)
ref2namesdct = iddindex.makeref2namesdct(name2refs)
idd_index = dict(name2refs=name2refs, ref2names=ref2namesdct)
commdct = iddindex.ref2names2commdct(ref2namesdct, commdct)

return blocklst, commlst, commdct, idd_index
# give blocklst a better name :-(


Expand Down
8 changes: 4 additions & 4 deletions eppy/EPlusInterfaceFunctions/readidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def readidf(idfname):
iddfile = "Energy+.idd"
# iddfile = './EPlusInterfaceFunctions/E1.idd' # TODO : can the path name be not hard coded
iddtxt = open(iddfile, "r").read()
block, commlst, commdct = parse_idd.extractidddata(iddfile)
block, commlst, commdct, idd_index = parse_idd.extractidddata(iddfile)

theidd = eplusdata.Idd(block, 2)
data = eplusdata.Eplusdata(theidd, idfname)
Expand All @@ -38,7 +38,7 @@ def readiddidf(idfname):
iddfile = "Energy+.idd"
# iddfile = './EPlusInterfaceFunctions/E1.idd' # TODO : can the path name be not hard coded
iddtxt = open(iddfile, "r").read()
block, commlst, commdct = parse_idd.extractidddata(iddfile)
block, commlst, commdct, idd_index = parse_idd.extractidddata(iddfile)

theidd = eplusdata.Idd(block, 2)
data = eplusdata.Eplusdata(theidd, idfname)
Expand All @@ -51,7 +51,7 @@ def readiddstuff(idfname):
iddfile = "Energy+.idd"
# iddfile = './EPlusInterfaceFunctions/E1.idd' # TODO : can the path name be not hard coded
iddtxt = open(iddfile, "r").read()
block, commlst, commdct = parse_idd.extractidddata(iddfile)
block, commlst, commdct, idd_index = parse_idd.extractidddata(iddfile)

theidd = eplusdata.Idd(block, 2)
data = eplusdata.Eplusdata(theidd, idfname)
Expand All @@ -64,7 +64,7 @@ def readdatacommlst(idfname):
iddfile = "Energy+.idd"
# iddfile = './EPlusInterfaceFunctions/E1.idd' # TODO : can the path name be not hard coded
iddtxt = open(iddfile, "r").read()
block, commlst, commdct = parse_idd.extractidddata(iddfile)
block, commlst, commdct, idd_index = parse_idd.extractidddata(iddfile)

theidd = eplusdata.Idd(block, 2)
data = eplusdata.Eplusdata(theidd, idfname)
Expand Down
41 changes: 39 additions & 2 deletions eppy/bunch_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,26 @@ def __getattr__(self, name):
elif name in self.fieldnames:
i = self.fieldnames.index(name)
try:
return self.fieldvalues[i]
i_ = self.fieldvalues[i]
if i_ == "":
return self.get_default(name)
else:
return i_
except IndexError:
return ""
# try to return the default value if defined in IDD.
return self.get_default(name)
else:
astr = "unable to find field %s" % (name,)
raise BadEPFieldError(astr)

def get_default(self, name):
if "default" in self.getfieldidd(name).keys():
_type = _parse_idd_type(self, name)
default_ = next(iter(self.getfieldidd_item(name, "default")), None)
return _type(default_)
else:
return ""

def __getitem__(self, key):
if key in ("obj", "objls", "objidd", "__functions", "__aliases", "theidf"):
return super(EpBunch, self).__getitem__(key)
Expand Down Expand Up @@ -395,6 +408,30 @@ def __dir__(self):
return super(EpBunch, self).__dir__() + fnames + func_names


def _parse_idd_type(epbunch, name):
"""parse the fieldvalue type into a python type. eg.: 'real' returns
'float'.

Possible types are:
- integer -> int
- real -> float
- alpha -> str (arbitrary string),
- choice -> str (alpha with specific list of choices, see \key)
- object-list -> str (link to a list of objects defined elsewhere, see \object-list and \reference)
- external-list -> str (uses a special list from an external source, see \external-list)
- node -> str (name used in connecting HVAC components)
"""
_type = next(iter(epbunch.getfieldidd_item(name, "type")), "").lower()
if _type == "real":
return float
elif _type == "alpha":
return str
elif _type == "integer":
return int
else:
return str


def getrange(bch, fieldname):
"""get the ranges for this field"""
keys = ["maximum", "minimum", "maximum<", "minimum>", "type"]
Expand Down
8 changes: 4 additions & 4 deletions eppy/bunchhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
from __future__ import print_function
from __future__ import unicode_literals

from string import ascii_letters, digits
import re
pattern = re.compile(r"[^a-zA-Z0-9\s]+")


def onlylegalchar(name):
def onlylegalchar(name: str):
"""return only legal chars"""
legalchar = ascii_letters + digits + " "
return "".join([s for s in name[:] if s in legalchar])
return pattern.sub("", name)


def makefieldname(namefromidd):
Expand Down
1 change: 1 addition & 0 deletions eppy/runner/run_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from __future__ import print_function
from __future__ import unicode_literals

import glob
import os
import platform
import pydoc
Expand Down
3 changes: 2 additions & 1 deletion tests/test_modeleditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ def test_newidfobject():
sim_deftrue = idf.newidfobject("SimulationControl".upper(), defaultvalues=True)
assert sim_deftrue.Do_Zone_Sizing_Calculation == "No"
sim_deffalse = idf.newidfobject("SimulationControl".upper(), defaultvalues=False)
assert sim_deffalse.Do_Zone_Sizing_Calculation == ""
assert sim_deffalse.Do_Zone_Sizing_Calculation == "No"
assert str(sim_deffalse) == "\n SIMULATIONCONTROL,;\n"


def test_newidfobject_warning():
Expand Down