text stringlengths 81 112k |
|---|
convert and return inputs for E+ in pascal and m3/s
def watts2pascal(watts, cfm, fan_tot_eff):
"""convert and return inputs for E+ in pascal and m3/s"""
bhp = watts2bhp(watts)
return bhp2pascal(bhp, cfm, fan_tot_eff) |
return fan power in bhp given the fan IDF object
def fanpower_bhp(ddtt):
"""return fan power in bhp given the fan IDF object"""
from eppy.bunch_subclass import BadEPFieldError # here to prevent circular dependency
try:
fan_tot_eff = ddtt.Fan_Total_Efficiency # from V+ V8.7.0 onwards
except BadE... |
return fan power in bhp given the fan IDF object
def fanpower_watts(ddtt):
"""return fan power in bhp given the fan IDF object"""
from eppy.bunch_subclass import BadEPFieldError # here to prevent circular dependency
try:
fan_tot_eff = ddtt.Fan_Total_Efficiency # from V+ V8.7.0 onwards
except Ba... |
return the fan max cfm
def fan_maxcfm(ddtt):
"""return the fan max cfm"""
if str(ddtt.Maximum_Flow_Rate).lower() == 'autosize':
# str can fail with unicode chars :-(
return 'autosize'
else:
m3s = float(ddtt.Maximum_Flow_Rate)
return m3s2cfm(m3s) |
Get the install paths for EnergyPlus executable and weather files.
We prefer to get the install path from the IDD name but fall back to
getting it from the version number for backwards compatibility and to
simplify tests.
Parameters
----------
version : str, optional
EnergyPlus version... |
Get the EnergyPlus install directory and executable path.
Parameters
----------
iddname : str, optional
File path to the IDD.
Returns
-------
eplus_exe : str
Full path to the EnergyPlus executable.
eplus_home : str
Full path to the EnergyPlus install directory.
... |
Get the EnergyPlus install directory and executable path.
Parameters
----------
version : str, optional
EnergyPlus version in the format "X-X-X", e.g. "8-7-0".
Returns
-------
eplus_exe : str
Full path to the EnergyPlus executable.
eplus_home : str
Full path to the ... |
Decorator to pass through the documentation from a wrapped function.
def wrapped_help_text(wrapped_func):
"""Decorator to pass through the documentation from a wrapped function.
"""
def decorator(wrapper_func):
"""The decorator.
Parameters
----------
f : callable
... |
Wrapper for run() to be used when running IDF5 runs in parallel.
Parameters
----------
jobs : iterable
A list or generator made up of an IDF5 object and a kwargs dict
(see `run_functions.run` for valid keywords).
processors : int, optional
Number of processors to run on (default... |
Prepare run inputs for one of multiple EnergyPlus runs.
:param run_id: An ID number for naming the IDF.
:param run_data: Tuple of the IDF and keyword args to pass to EnergyPlus executable.
:return: Tuple of the IDF path and EPW, and the keyword args.
def prepare_run(run_id, run_data):
"""Prepare run i... |
Wrapper around the EnergyPlus command line interface.
Parameters
----------
idf : str
Full or relative path to the IDF file to be run, or an IDF object.
weather : str
Full or relative path to the weather file.
output_directory : str, optional
Full or relative path to an ou... |
Add contents of stderr and eplusout.err and put it in the exception message.
:param output_dir: str
:return: str
def parse_error(output_dir):
"""Add contents of stderr and eplusout.err and put it in the exception message.
:param output_dir: str
:return: str
"""
sys.stderr.seek(0)
std_... |
R value (W/K) of a construction or material.
thickness (m) / conductivity (W/m-K)
def rvalue(ddtt):
"""
R value (W/K) of a construction or material.
thickness (m) / conductivity (W/m-K)
"""
object_type = ddtt.obj[0]
if object_type == 'Construction':
rvalue = INSIDE_FILM_R + OUTSIDE_... |
Heat capacity (kJ/m2-K) of a construction or material.
thickness (m) * density (kg/m3) * specific heat (J/kg-K) * 0.001
def heatcapacity(ddtt):
"""
Heat capacity (kJ/m2-K) of a construction or material.
thickness (m) * density (kg/m3) * specific heat (J/kg-K) * 0.001
"""
object_type = ddtt.obj[... |
Test if two values are equal to a given number of places.
This is based on python's unittest so may be covered by Python's
license.
def almostequal(first, second, places=7, printit=True):
"""
Test if two values are equal to a given number of places.
This is based on python's unittest so may be cove... |
Make a new object for the given key.
Parameters
----------
data : Eplusdata object
Data dictionary and list of objects for the entire model.
commdct : list of dicts
Comments from the IDD file describing each item type in `data`.
key : str
Object type of the object to add (in... |
add a bunch to model.
abunch usually comes from another idf file
or it can be used to copy within the idf file
def addthisbunch(bunchdt, data, commdct, thisbunch, theidf):
"""add a bunch to model.
abunch usually comes from another idf file
or it can be used to copy within the idf file"""
key = ... |
make a new bunch object using the data object
def obj2bunch(data, commdct, obj):
"""make a new bunch object using the data object"""
dtls = data.dtls
key = obj[0].upper()
key_i = dtls.index(key)
abunch = makeabunch(commdct, obj, key_i)
return abunch |
add an object to the eplus model
def addobject(bunchdt, data, commdct, key, theidf, aname=None, **kwargs):
"""add an object to the eplus model"""
obj = newrawobject(data, commdct, key)
abunch = obj2bunch(data, commdct, obj)
if aname:
namebunch(abunch, aname)
data.dt[key].append(obj)
bun... |
allows you to pass a dict and named args
so you can pass ({'a':5, 'b':3}, c=8) and get
dict(a=5, b=3, c=8)
def getnamedargs(*args, **kwargs):
"""allows you to pass a dict and named args
so you can pass ({'a':5, 'b':3}, c=8) and get
dict(a=5, b=3, c=8)"""
adict = {}
for arg in args:
... |
add an object to the eplus model
def addobject1(bunchdt, data, commdct, key, **kwargs):
"""add an object to the eplus model"""
obj = newrawobject(data, commdct, key)
abunch = obj2bunch(data, commdct, obj)
data.dt[key].append(obj)
bunchdt[key].append(abunch)
# adict = getnamedargs(*args, **kwarg... |
get the object if you have the key and the name
returns a list of objects, in case you have more than one
You should not have more than one
def getobject(bunchdt, key, name):
"""get the object if you have the key and the name
returns a list of objects, in case you have more than one
You should not ... |
test if the idf object has the field values in kwargs
def __objecthasfields(bunchdt, data, commdct, idfobject, places=7, **kwargs):
"""test if the idf object has the field values in kwargs"""
for key, value in list(kwargs.items()):
if not isfieldvalue(
bunchdt, data, commdct,
... |
get all the objects of key that matches the fields in **kwargs
def getobjects(bunchdt, data, commdct, key, places=7, **kwargs):
"""get all the objects of key that matches the fields in **kwargs"""
idfobjects = bunchdt[key]
allobjs = []
for obj in idfobjects:
if __objecthasfields(
... |
from commdct, return the idd of the object key
def iddofobject(data, commdct, key):
"""from commdct, return the idd of the object key"""
dtls = data.dtls
i = dtls.index(key)
return commdct[i] |
get the index of the first extensible item
def getextensibleindex(bunchdt, data, commdct, key, objname):
"""get the index of the first extensible item"""
theobject = getobject(bunchdt, key, objname)
if theobject == None:
return None
theidd = iddofobject(data, commdct, key)
extensible_i = [
... |
remove the extensible items in the object
def removeextensibles(bunchdt, data, commdct, key, objname):
"""remove the extensible items in the object"""
theobject = getobject(bunchdt, key, objname)
if theobject == None:
return theobject
theidd = iddofobject(data, commdct, key)
extensible_i = ... |
get the idd comment for the field
def getfieldcomm(bunchdt, data, commdct, idfobject, fieldname):
"""get the idd comment for the field"""
key = idfobject.obj[0].upper()
keyi = data.dtls.index(key)
fieldi = idfobject.objls.index(fieldname)
thiscommdct = commdct[keyi][fieldi]
return thiscommdct |
test if case has to be retained for that field
def is_retaincase(bunchdt, data, commdct, idfobject, fieldname):
"""test if case has to be retained for that field"""
thiscommdct = getfieldcomm(bunchdt, data, commdct, idfobject, fieldname)
return 'retaincase' in thiscommdct |
test if idfobj.field == value
def isfieldvalue(bunchdt, data, commdct, idfobj, fieldname, value, places=7):
"""test if idfobj.field == value"""
# do a quick type check
# if type(idfobj[fieldname]) != type(value):
# return False # takes care of autocalculate and real
# check float
thiscommdct = ... |
returns true if the two fields are equal
will test for retaincase
places is used if the field is float/real
def equalfield(bunchdt, data, commdct, idfobj1, idfobj2, fieldname, places=7):
"""returns true if the two fields are equal
will test for retaincase
places is used if the field is float/real""... |
get the reference names for this object
def getrefnames(idf, objname):
"""get the reference names for this object"""
iddinfo = idf.idd_info
dtls = idf.model.dtls
index = dtls.index(objname)
fieldidds = iddinfo[index]
for fieldidd in fieldidds:
if 'field' in fieldidd:
if fiel... |
get all object-list fields for refname
return a list:
[('OBJKEY', refname, fieldindexlist), ...] where
fieldindexlist = index of the field where the object-list = refname
def getallobjlists(idf, refname):
"""get all object-list fields for refname
return a list:
[('OBJKEY', refname, fieldindexli... |
rename all the refrences to this objname
def rename(idf, objkey, objname, newname):
"""rename all the refrences to this objname"""
refnames = getrefnames(idf, objkey)
for refname in refnames:
objlists = getallobjlists(idf, refname)
# [('OBJKEY', refname, fieldindexlist), ...]
for re... |
zone area
def zonearea(idf, zonename, debug=False):
"""zone area"""
zone = idf.getobject('ZONE', zonename)
surfs = idf.idfobjects['BuildingSurface:Detailed'.upper()]
zone_surfs = [s for s in surfs if s.Zone_Name == zone.Name]
floors = [s for s in zone_surfs if s.Surface_Type.upper() == 'FLOOR']
... |
zone height = max-min
def zone_height_min2max(idf, zonename, debug=False):
"""zone height = max-min"""
zone = idf.getobject('ZONE', zonename)
surfs = idf.idfobjects['BuildingSurface:Detailed'.upper()]
zone_surfs = [s for s in surfs if s.Zone_Name == zone.Name]
surf_xyzs = [eppy.function_helpers.get... |
zone height
def zoneheight(idf, zonename, debug=False):
"""zone height"""
zone = idf.getobject('ZONE', zonename)
surfs = idf.idfobjects['BuildingSurface:Detailed'.upper()]
zone_surfs = [s for s in surfs if s.Zone_Name == zone.Name]
floors = [s for s in zone_surfs if s.Surface_Type.upper() == 'FLOOR... |
zone floor to roof height
def zone_floor2roofheight(idf, zonename, debug=False):
"""zone floor to roof height"""
zone = idf.getobject('ZONE', zonename)
surfs = idf.idfobjects['BuildingSurface:Detailed'.upper()]
zone_surfs = [s for s in surfs if s.Zone_Name == zone.Name]
floors = [s for s in zone_su... |
zone volume
def zonevolume(idf, zonename):
"""zone volume"""
area = zonearea(idf, zonename)
height = zoneheight(idf, zonename)
volume = area * height
return volume |
Set the path to the EnergyPlus IDD for the version of EnergyPlus which
is to be used by eppy.
Parameters
----------
iddname : str
Path to the IDD file.
testing : bool
Flag to use if running tests since we may want to ignore the
`IDDAlreadySetE... |
Set the IDD to be used by eppy.
Parameters
----------
iddinfo : list
Comments and metadata about fields in the IDD.
block : list
Field names in the IDD.
def setidd(cls, iddinfo, iddindex, block, idd_version):
"""Set the IDD to be used by eppy.
P... |
Use the current IDD and read an IDF from file. If the IDD has not yet
been initialised then this is done first.
Parameters
----------
idf_name : str
Path to an IDF file.
def initread(self, idfname):
"""
Use the current IDD and read an IDF from file. If the I... |
Use the current IDD and read an IDF from text data. If the IDD has not
yet been initialised then this is done first.
Parameters
----------
idftxt : str
Text representing an IDF file.
def initreadtxt(self, idftxt):
"""
Use the current IDD and read an IDF from... |
Read the IDF file and the IDD file. If the IDD file had already been
read, it will not be read again.
Read populates the following data structures:
- idfobjects : list
- model : list
- idd_info : list
- idd_index : dict
def read(self):
"""
Read the IDF ... |
Use the current IDD and create a new empty IDF. If the IDD has not yet
been initialised then this is done first.
Parameters
----------
fname : str, optional
Path to an IDF. This does not need to be set at this point.
def initnew(self, fname):
"""
Use the cur... |
Add a new idfobject to the model. If you don't specify a value for a
field, the default value will be set.
For example ::
newidfobject("CONSTRUCTION")
newidfobject("CONSTRUCTION",
Name='Interior Ceiling_class',
Outside_Layer='LW Concrete',
... |
Remove an IDF object from the IDF.
Parameters
----------
idfobject : EpBunch object
The IDF object to remove.
def removeidfobject(self, idfobject):
"""Remove an IDF object from the IDF.
Parameters
----------
idfobject : EpBunch object
Th... |
Add an IDF object to the IDF.
Parameters
----------
idfobject : EpBunch object
The IDF object to remove. This usually comes from another idf file,
or it can be used to copy within this idf file.
def copyidfobject(self, idfobject):
"""Add an IDF object to the IDF... |
Get the index of the first extensible item.
Only for internal use. # TODO : hide this
Parameters
----------
key : str
The type of IDF object. This must be in ALL_CAPS.
name : str
The name of the object to fetch.
Returns
-------
i... |
Remove extensible items in the object of key and name.
Only for internal use. # TODO : hide this
Parameters
----------
key : str
The type of IDF object. This must be in ALL_CAPS.
name : str
The name of the object to fetch.
Returns
------... |
String representation of the IDF.
Returns
-------
str
def idfstr(self):
"""String representation of the IDF.
Returns
-------
str
"""
if self.outputtype == 'standard':
astr = ''
else:
astr = self.model.__repr__()
... |
Save the IDF as a text file with the optional filename passed, or with
the current idfname of the IDF.
Parameters
----------
filename : str, optional
Filepath to save the file. If None then use the IDF.idfname
parameter. Also accepts a file handle.
linee... |
Save the IDF as a text file with the filename passed.
Parameters
----------
filename : str
Filepath to to set the idfname attribute to and save the file as.
lineendings : str, optional
Line endings to use in the saved file. Options are 'default',
'wi... |
Save a copy of the file with the filename passed.
Parameters
----------
filename : str
Filepath to save the file.
lineendings : str, optional
Line endings to use in the saved file. Options are 'default',
'windows' and 'unix' the default is 'default' ... |
Run an IDF file with a given EnergyPlus weather file. This is a
wrapper for the EnergyPlus command line interface.
Parameters
----------
**kwargs
See eppy.runner.functions.run()
def run(self, **kwargs):
"""
Run an IDF file with a given EnergyPlus weather fil... |
readfile
def readfile(filename):
"""readfile"""
fhandle = open(filename, 'rb')
data = fhandle.read()
try:
data = data.decode('ISO-8859-2')
except AttributeError:
pass
fhandle.close()
return data |
printdict
def printdict(adict):
"""printdict"""
dlist = list(adict.keys())
dlist.sort()
for i in range(0, len(dlist)):
print(dlist[i], adict[dlist[i]]) |
tabfile2list
def tabfile2list(fname):
"tabfile2list"
#dat = mylib1.readfileasmac(fname)
#data = string.strip(dat)
data = mylib1.readfileasmac(fname)
#data = data[:-2]#remove the last return
alist = data.split('\r')#since I read it as a mac file
blist = alist[1].split('\t')
clist = []
... |
tabstr2list
def tabstr2list(data):
"""tabstr2list"""
alist = data.split(os.linesep)
blist = alist[1].split('\t')
clist = []
for num in range(0, len(alist)):
ilist = alist[num].split('\t')
clist = clist+[ilist]
cclist = clist[:-1]
#the last element is turning out to be emp... |
list2doe
def list2doe(alist):
"""list2doe"""
theequal = ''
astr = ''
lenj = len(alist)
leni = len(alist[0])
for i in range(0, leni-1):
for j in range(0, lenj):
if j == 0:
astr = astr + alist[j][i + 1] + theequal + alist[j][0] + RET
else:
... |
tabfile2doefile
def tabfile2doefile(tabfile, doefile):
"""tabfile2doefile"""
alist = tabfile2list(tabfile)
astr = list2doe(alist)
mylib1.write_str2file(doefile, astr) |
makedoedict
def makedoedict(str1):
"""makedoedict"""
blocklist = str1.split('..')
blocklist = blocklist[:-1]#remove empty item after last '..'
blockdict = {}
belongsdict = {}
for num in range(0, len(blocklist)):
blocklist[num] = blocklist[num].strip()
linelist = blocklist[num].s... |
makedoetree
def makedoetree(ddict, bdict):
"""makedoetree"""
dlist = list(ddict.keys())
blist = list(bdict.keys())
dlist.sort()
blist.sort()
#make space dict
doesnot = 'DOES NOT'
lst = []
for num in range(0, len(blist)):
if bdict[blist[num]] == doesnot:#belong
ls... |
tree2doe
def tree2doe(str1):
"""tree2doe"""
retstuff = makedoedict(str1)
ddict = makedoetree(retstuff[0], retstuff[1])
ddict = retstuff[0]
retstuff[1] = {}# don't need it anymore
str1 = ''#just re-using it
l1list = list(ddict.keys())
l1list.sort()
for i in range(0, len(l1list)):
... |
mtabstr2doestr
def mtabstr2doestr(st1):
"""mtabstr2doestr"""
seperator = '$ =============='
alist = st1.split(seperator)
#this removes all the tabs that excel
#puts after the seperator and before the next line
for num in range(0, len(alist)):
alist[num] = alist[num].lstrip()
st2 = ... |
get the block bounded by start and end
doesn't work for multiple blocks
def getoneblock(astr, start, end):
"""get the block bounded by start and end
doesn't work for multiple blocks"""
alist = astr.split(start)
astr = alist[-1]
alist = astr.split(end)
astr = alist[0]
return astr |
doestr2tabstr
def doestr2tabstr(astr, kword):
"""doestr2tabstr"""
alist = astr.split('..')
del astr
#strip junk put .. back
for num in range(0, len(alist)):
alist[num] = alist[num].strip()
alist[num] = alist[num] + os.linesep + '..' + os.linesep
alist.pop()
lblock = []
... |
in string astr replace all occurences of thefind with thereplace
def myreplace(astr, thefind, thereplace):
"""in string astr replace all occurences of thefind with thereplace"""
alist = astr.split(thefind)
new_s = alist.split(thereplace)
return new_s |
Return the slice after at sub in string astr
def fsliceafter(astr, sub):
"""Return the slice after at sub in string astr"""
findex = astr.find(sub)
return astr[findex + len(sub):] |
same as pickle.dump(theobject, fhandle).takes filename as parameter
def pickledump(theobject, fname):
"""same as pickle.dump(theobject, fhandle).takes filename as parameter"""
fhandle = open(fname, 'wb')
pickle.dump(theobject, fhandle) |
writes a string to file
def write_str2file(pathname, astr):
"""writes a string to file"""
fname = pathname
fhandle = open(fname, 'wb')
fhandle.write(astr)
fhandle.close() |
volume of a irregular tetrahedron
def vol_tehrahedron(poly):
"""volume of a irregular tetrahedron"""
a_pnt = np.array(poly[0])
b_pnt = np.array(poly[1])
c_pnt = np.array(poly[2])
d_pnt = np.array(poly[3])
return abs(np.dot(
(a_pnt-d_pnt), np.cross((b_pnt-d_pnt), (c_pnt-d_pnt))) / 6) |
volume of a zone defined by two polygon bases
def vol_zone(poly1, poly2):
""""volume of a zone defined by two polygon bases """
c_point = central_p(poly1, poly2)
c_point = (c_point[0], c_point[1], c_point[2])
vol_therah = 0
num = len(poly1)
for i in range(num-2):
# the upper part
... |
open a new idf file
easy way to open a new idf file for particular version. Works only id Energyplus of that version is installed.
Parameters
----------
version: string
version of the new file you want to create. Will work only if this version of Energyplus has been installed.
R... |
automatically set idd and open idf file. Uses version from idf to set correct idd
It will work under the following circumstances:
- the IDF file should have the VERSION object.
- Needs the version of EnergyPlus installed that matches the IDF version.
- Energyplus should be installed in the default... |
return an wall:interzone object if the bsd (buildingsurface:detailed)
is an interaone wall
def wallinterzone(idf, bsdobject, deletebsd=True, setto000=False):
"""return an wall:interzone object if the bsd (buildingsurface:detailed)
is an interaone wall"""
# ('WALL:INTERZONE', Wall, Surface OR Zone OR ... |
return an door object if the fsd (fenestrationsurface:detailed) is
a door
def door(idf, fsdobject, deletebsd=True, setto000=False):
"""return an door object if the fsd (fenestrationsurface:detailed) is
a door"""
# ('DOOR', Door, None)
# test if it is aroof
if fsdobject.Surface_Type.upper() ==... |
convert a bsd (buildingsurface:detailed) into a simple surface
def simplesurface(idf, bsd, deletebsd=True, setto000=False):
"""convert a bsd (buildingsurface:detailed) into a simple surface"""
funcs = (wallexterior,
walladiabatic,
wallunderground,
wallinterzone,
roof,
ce... |
convert a bsd (fenestrationsurface:detailed) into a simple
fenestrations
def simplefenestration(idf, fsd, deletebsd=True, setto000=False):
"""convert a bsd (fenestrationsurface:detailed) into a simple
fenestrations"""
funcs = (window,
door,
glazeddoor,)
for func in funcs:
... |
convert the <br/> in <td> block into line ending (EOL = \n)
def tdbr2EOL(td):
"""convert the <br/> in <td> block into line ending (EOL = \n)"""
for br in td.find_all("br"):
br.replace_with("\n")
txt = six.text_type(td) # make it back into test
# would be unicode(id) in ... |
test if the table has only strings in the cells
def is_simpletable(table):
"""test if the table has only strings in the cells"""
tds = table('td')
for td in tds:
if td.contents != []:
td = tdbr2EOL(td)
if len(td.contents) == 1:
thecontents = td.contents[0]
... |
convert a table to a list of lists - a 2D matrix
def table2matrix(table):
"""convert a table to a list of lists - a 2D matrix"""
if not is_simpletable(table):
raise NotSimpleTable("Not able read a cell in the table as a string")
rows = []
for tr in table('tr'):
row = []
for td ... |
convert a table to a list of lists - a 2D matrix
Converts numbers to float
def table2val_matrix(table):
"""convert a table to a list of lists - a 2D matrix
Converts numbers to float"""
if not is_simpletable(table):
raise NotSimpleTable("Not able read a cell in the table as a string")
rows =... |
return a list of [(title, table), .....]
title = previous item with a <b> tag
table = rows -> [[cell1, cell2, ..], [cell1, cell2, ..], ..]
def titletable(html_doc, tofloat=True):
"""return a list of [(title, table), .....]
title = previous item with a <b> tag
table = rows -> [[cell1, cell2, ..], ... |
checks if soup_obj is really a soup object or just a string
If it has a name it is a soup object
def _has_name(soup_obj):
"""checks if soup_obj is really a soup object or just a string
If it has a name it is a soup object"""
try:
name = soup_obj.name
if name == None:
return ... |
return a list of [(lines, table), .....]
lines = all the significant lines before the table.
These are lines between this table and
the previous table or 'hr' tag
table = rows -> [[cell1, cell2, ..], [cell1, cell2, ..], ..]
The lines act as a description for what is in the table
def lines... |
make a named tuple grid
[["", "a b", "b c", "c d"],
["x y", 1, 2, 3 ],
["y z", 4, 5, 6 ],
["z z", 7, 8, 9 ],]
will return
ntcol(x_y=ntrow(a_b=1, b_c=2, c_d=3),
y_z=ntrow(a_b=4, b_c=5, c_d=6),
z_z=ntrow(a_b=7, b_c=8, c_d=9))
def _make_ntgrid(grid)... |
return only legal chars
def onlylegalchar(name):
"""return only legal chars"""
legalchar = ascii_letters + digits + ' '
return ''.join([s for s in name[:] if s in legalchar]) |
Check match between two strings, ignoring case and spaces/underscores.
Parameters
----------
a : str
b : str
Returns
-------
bool
def matchfieldnames(field_a, field_b):
"""Check match between two strings, ignoring case and spaces/underscores.
Parameters
----------... |
test if int in list
def intinlist(lst):
"""test if int in list"""
for item in lst:
try:
item = int(item)
return True
except ValueError:
pass
return False |
replace int in lst
def replaceint(fname, replacewith='%s'):
"""replace int in lst"""
words = fname.split()
for i, word in enumerate(words):
try:
word = int(word)
words[i] = replacewith
except ValueError:
pass
return ' '.join(words) |
make all the keys lower case
def cleaniddfield(acomm):
"""make all the keys lower case"""
for key in list(acomm.keys()):
val = acomm[key]
acomm[key.lower()] = val
for key in list(acomm.keys()):
val = acomm[key]
if key != key.lower():
acomm.pop(key)
return aco... |
return the csv to be displayed
def makecsvdiffs(thediffs, dtls, n1, n2):
"""return the csv to be displayed"""
def ishere(val):
if val == None:
return "not here"
else:
return "is here"
rows = []
rows.append(['file1 = %s' % (n1, )])
rows.append(['file2 = %s' % ... |
return the diffs between the two idfs
def idfdiffs(idf1, idf2):
"""return the diffs between the two idfs"""
# for any object type, it is sorted by name
thediffs = {}
keys = idf1.model.dtls # undocumented variable
for akey in keys:
idfobjs1 = idf1.idfobjects[akey]
idfobjs2 = idf2.id... |
print the csv
def printcsv(csvdiffs):
"""print the csv"""
for row in csvdiffs:
print(','.join([str(cell) for cell in row])) |
add heading row to table
def heading2table(soup, table, row):
"""add heading row to table"""
tr = Tag(soup, name="tr")
table.append(tr)
for attr in row:
th = Tag(soup, name="th")
tr.append(th)
th.append(attr) |
ad a row to the table
def row2table(soup, table, row):
"""ad a row to the table"""
tr = Tag(soup, name="tr")
table.append(tr)
for attr in row:
td = Tag(soup, name="td")
tr.append(td)
td.append(attr) |
print the html
def printhtml(csvdiffs):
"""print the html"""
soup = BeautifulSoup()
html = Tag(soup, name="html")
para1 = Tag(soup, name="p")
para1.append(csvdiffs[0][0])
para2 = Tag(soup, name="p")
para2.append(csvdiffs[1][0])
table = Tag(soup, name="table")
table.attrs.update(dict... |
extend the list so that you have i-th value
def extendlist(lst, i, value=''):
"""extend the list so that you have i-th value"""
if i < len(lst):
pass
else:
lst.extend([value, ] * (i - len(lst) + 1)) |
add functions to epbunch
def addfunctions(abunch):
"""add functions to epbunch"""
key = abunch.obj[0].upper()
#-----------------
# TODO : alternate strategy to avoid listing the objkeys in snames
# check if epbunch has field "Zone_Name" or "Building_Surface_Name"
# and is in group u'Thermal Z... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.