-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheppystuff.py
110 lines (93 loc) · 3.27 KB
/
eppystuff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright (c) 2016 Santosh Philip
# =======================================================================
# Distributed under the MIT License.
# (See accompanying file LICENSE or copy at
# http://opensource.org/licenses/MIT)
# =======================================================================
"""just eppy stuff"""
import os
import StringIO
from eppy.iddcurrent import iddcurrent
import eppy.idf_helpers as idf_helpers
from eppy.modeleditor import IDF
from eppy.EPlusInterfaceFunctions.eplusdata import removecomment
from eppy.useful_scripts import loopdiagram
iddfile = './Energy+.idd'
def getfnames(fnametxt='./idffilenames.txt'):
"""return the idf filenames"""
fhandle = open(fnametxt, 'r')
lines = (removecomment(line.strip(), "#") for line in fhandle)
lines = (line for line in lines if line)
for line in lines:
yield line
fnames = getfnames()
if IDF.getiddname() == None:
IDF.setiddname(iddfile)
idfs = [IDF(fname) for fname in fnames]
alledges = [loopdiagram.getedges(idf.idfname, iddfile) for idf in idfs]
nodekeys = idf_helpers.getidfkeyswithnodes()
def getidfs():
"""return an idf"""
return idfs
def getalledges():
"""return edges"""
return alledges
def idfsandedges():
"""return idfs and edges"""
return idfs, alledges
def an_idfedges(index):
"""return a specific idf and it's edges"""
idfs, alledges = idfsandedges()
return idfs[index], alledges[index]
def getnodekeys():
"""return keys that have node fields"""
return nodekeys
def objnames():
"""return obj names"""
return idf_helpers.idfobjectkeys(idf)
def page2():
idf = getidf()
onames = objnames()
n_len = [(objname, len(idf.idfobjects[objname.upper()])) for objname in onames]
nlen = [(name, ln)for name, ln in n_len if ln > 0]
return nlen
def idfobjectindices(idf, idfobj):
"""return indices to construct the url for weppy"""
try:
objkey = idfobj.key
except AttributeError as e:
return None
key_id = idf_helpers.idfobjectkeys(idf).index(objkey.upper())
idfobjs = idf.idfobjects[objkey.upper()]
obj_id = idfobjs.index(idfobj)
return key_id, obj_id
def trimedges(edges, onlythis=None):
"""trim the edges with onlythis"""
if not onlythis:
return edges
trimmed = []
for item in edges:
a, b = item
if a in onlythis or b in onlythis:
trimmed.append(item)
return trimmed
def save_imagesnippets(imgfolder, imgname, trimmed):
"""save images if they do not exist"""
imgpath = '%s/%s' % (imgfolder, imgname, )
print imgpath
if os.path.exists('%s.png' % (imgpath, )):
print "image exists"
return True
if not os.path.exists(imgfolder):
os.mkdir(imgfolder)
loopdiagram.save_diagram(imgpath, loopdiagram.makediagram(trimmed))
# idf_helpers.name2idfobject(idf, Name=nnode)
def hvacname2idfobj(idf, aname):
"""return the idf object given it's name
does initial check on 'ZoneHVAC:EquipmentConnections.Zone_name'"""
equipconnections = idf_helpers.name2idfobject(idf,
objkeys=['ZoneHVAC:EquipmentConnections'.upper(), ],
Zone_Name=aname)
if equipconnections:
return equipconnections
return idf_helpers.name2idfobject(idf, Name=aname)