Skip to content
Snippets Groups Projects
Commit 1290575a authored by Mikhail Karnevskiy's avatar Mikhail Karnevskiy
Browse files

Use templates for parameters table

parent f6fa53d5
No related branches found
No related tags found
1 merge request!72Feat: Change formatting of list of input parameters
......@@ -17,7 +17,8 @@ from uuid import uuid4
import warnings
from .settings import *
from .notebooks import notebooks
from jinja2 import Template
import textwrap
# Add a class combining raw description formatting with
# Metavariable default outputs
......@@ -443,59 +444,64 @@ def concurrent_run(temp_path, nb, nbname, args, cparm=None, cval=None,
def make_par_table(parms, temp_path, run_uuid):
'''
"""
Create a table with input parameters if the notebook
:param parms: parameters of the notebook
:param temp_path: path to temporary directory for job outputs
:param run_uuid: inset of folder name containing job output
'''
"""
# Add space in long strings to wrap them in latex
def split_len(seq, length):
l = [seq[i:i+length] for i in range(0, len(seq), length)]
l = [seq[i:i + length] for i in range(0, len(seq), length)]
return ' '.join(l)
# prepare strings and estimate their length
# Prepare strings and estimate their length
l_parms = []
len_parms = [0, 0]
max_len = [30, 30]
for p in parms:
name = p.name.replace('_', '-')
if len(name)>max_len[0]:
if len(name) > max_len[0]:
len_parms[0] = max_len[0]
name = split_len(name, max_len[0])
value = str(p.value)
if len(value)>max_len[1]:
if len(value) > max_len[1]:
len_parms[1] = max_len[1]
value = split_len(value, max_len[1])
if p.type is str:
value = "``{}''".format(value)
value = value.replace('_', '\\_')
comment = str(p.comment)[1:].replace('_', '\\_')
l_parms.append([name, value, comment ])
with open("{}/slurm_tmp_{}/InputParameters.rst".format(temp_path, run_uuid), "w") as finfile:
finfile.write("Input of the calibration pipeline \n")
finfile.write("================================= \n\n")
finfile.write(".. math::\n")
col_type = ['l', 'c', 'p{.3\\textwidth}']
# fix column width is needed
if len_parms[0]==max_len[0]:
col_type[0] = 'p{.3\\textwidth}'
if len_parms[1]==max_len[1]:
col_type[1] = 'p{.3\\textwidth}'
finfile.write(" \\begin{{tabular}}{{ {} {} {} }}\n".format(*col_type))
finfile.write(" \\hline\n")
for p in l_parms:
tmpl = " \\textbf{{-{{}}-{} }} & {} & {}\\\\\n"
finfile.write(tmpl.format(*p))
finfile.write(" \\hline\n")
finfile.write(" \\end{tabular}\n")
l_parms.append([name, value, comment])
# Fix column width is needed
col_type = ['l', 'c', 'p{.3\\textwidth}']
if len_parms[0] == max_len[0]:
col_type[0] = 'p{.3\\textwidth}'
if len_parms[1] == max_len[1]:
col_type[1] = 'p{.3\\textwidth}'
tmpl = Template('''
Input of the calibration pipeline
=================================
.. math::
\\begin{tabular}{ {% for k in p %}{{ k }}{%- endfor %} }
\hline
{% for k in lines %}
{{ k[0] }} & {{ k[1] }} & {{ k[2] }} \\\\
{%- endfor %}
\hline
\end{tabular}
''')
f_name = "{}/slurm_tmp_{}/InputParameters.rst".format(temp_path, run_uuid)
with open(f_name, "w") as finfile:
finfile.write(textwrap.dedent(tmpl.render(p=col_type, lines=l_parms)))
def run():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment