Skip to content

Commit

Permalink
Added updated output list table
Browse files Browse the repository at this point in the history
For #2223
  • Loading branch information
mwetter committed Dec 5, 2020
1 parent fc2c00e commit 542f777
Show file tree
Hide file tree
Showing 3 changed files with 1,138 additions and 6 deletions.
44 changes: 42 additions & 2 deletions Buildings/Resources/src/ThermalZones/EnergyPlus/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,45 @@ def get_output_vars_as_json():

ret = subprocess.run([spawn, '--output-vars'], stdout=subprocess.PIPE, check=True)
vars = json.loads(ret.stdout)
print(f"****** {vars}")
return vars

def get_output_var_html(allVars):
""" Returns an html-formatted table with all output variables in the json structure `allVars`
"""
import jinja2
import os

path_to_template = os.path.dirname(os.path.realpath(__file__))
env = jinja2.Environment(loader=jinja2.FileSystemLoader(path_to_template))
txt = None
template = env.get_template("output_vars_template.html")
html = template.render(vars=allVars)
# with open(os.path.join(path_to_template, "temp.html"), mode="w", encoding="utf-8") as fil:
# fil.write(txt)
return html

def replace_output_var_table_in_mo(html):
""" Replaces in the .mo file the table with the output variables
"""
import os
import re

mo_name = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"..", "..", "..", "..",
"ThermalZones", "EnergyPlus", "UsersGuide.mo")
mo_new = ""
with open(mo_name, 'r') as mo_fil:
mo_old = mo_fil.read()
# Start and end anchors in the mo file
staStr = "<!-- Start of table of output variables generated by install.py. Do not edit. -->"
endStr = "<!-- End of table of output variables generated by install.py. Do not edit. -->"
mo_new, count = re.subn(r'(?<=%s).*(?=%s)' % (staStr, endStr), f"\n{html}\n", mo_old, flags=re.MULTILINE|re.DOTALL)
# Raise an error if the table was not updated. (Updating the table with the same content won't raise an error.)
if count == 0:
raise RuntimeError(f"Failed to update list of output variables in {mo_name}. File was not modified.")
# Write new file.
with open(mo_name, 'w') as mo_fil:
mo_fil.write(mo_new)


if __name__ == "__main__":
Expand Down Expand Up @@ -125,4 +163,6 @@ def get_output_vars_as_json():

p = Pool(2)
#fixme p.map(get_distribution, dists)
get_output_vars_as_json()
js = get_output_vars_as_json()
html = get_output_var_html(js)
mo = replace_output_var_table_in_mo(html)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<table summary=\"Supported output variables\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\" style=\"border-collapse:collapse;\">
<tr><th><code>OneZoneOneOutputVariable.name</code></th> <th>Unit as received in Modelica</th> <th>Unit used by EnergyPlus</th> </tr>
{% for v in vars %} <tr>
<td>{{ v }}</td>
<td>{{ vars[v]['modelicaUnit'] }}</td> <td>{{ vars[v]['energyplusUnit'] }}</td>
</tr>{% endfor %}
</table>
Loading

0 comments on commit 542f777

Please sign in to comment.