Commit 2fd6a02b authored by Benjamin Schwenker's avatar Benjamin Schwenker
Browse files

updated code to make listing of input pvs

parent f91bfc04
......@@ -135,39 +135,6 @@
\end{figure}
\end{frame}
\begin{frame}{List of input PVs 1}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_0_VAR
\end{tabular}
\caption{List of input PVs, part 1}
\end{table}
\end{tiny}
\end{frame}
\begin{frame}{List of input PVs 2}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_1_VAR
\end{tabular}
\caption{List of input PVs, part 2}
\end{table}
\end{tiny}
\end{frame}
\begin{frame}{List of input PVs 3}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_2_VAR
\end{tabular}
\caption{List of input PVs, part 3}
\end{table}
\end{tiny}
\end{frame}
INPUTS_VAR
\end{document}
......@@ -135,41 +135,7 @@
\end{figure}
\end{frame}
\begin{frame}{List of input PVs 1}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_0_VAR
\end{tabular}
\caption{List of input PVs, part 1}
\end{table}
\end{tiny}
\end{frame}
\begin{frame}{List of input PVs 2}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_1_VAR
\end{tabular}
\caption{List of input PVs, part 2}
\end{table}
\end{tiny}
\end{frame}
\begin{frame}{List of input PVs 3}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_2_VAR
\end{tabular}
\caption{List of input PVs, part 3}
\end{table}
\end{tiny}
\end{frame}
INPUTS_VAR
\end{document}
......@@ -135,39 +135,7 @@
\end{figure}
\end{frame}
\begin{frame}{List of input PVs 1}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_0_VAR
\end{tabular}
\caption{List of input PVs, part 1}
\end{table}
\end{tiny}
\end{frame}
\begin{frame}{List of input PVs 2}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_1_VAR
\end{tabular}
\caption{List of input PVs, part 2}
\end{table}
\end{tiny}
\end{frame}
\begin{frame}{List of input PVs 3}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_2_VAR
\end{tabular}
\caption{List of input PVs, part 3}
\end{table}
\end{tiny}
\end{frame}
INPUTS_VAR
\end{document}
......@@ -135,39 +135,6 @@
\end{figure}
\end{frame}
\begin{frame}{List of input PVs 1}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_0_VAR
\end{tabular}
\caption{List of input PVs, part 1}
\end{table}
\end{tiny}
\end{frame}
\begin{frame}{List of input PVs 2}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_1_VAR
\end{tabular}
\caption{List of input PVs, part 2}
\end{table}
\end{tiny}
\end{frame}
\begin{frame}{List of input PVs 3}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_2_VAR
\end{tabular}
\caption{List of input PVs, part 3}
\end{table}
\end{tiny}
\end{frame}
INPUTS_VAR
\end{document}
......@@ -206,39 +206,6 @@
\end{figure}
\end{frame}
\begin{frame}{List of input PVs 1}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_0_VAR
\end{tabular}
\caption{List of input PVs, part 1}
\end{table}
\end{tiny}
\end{frame}
\begin{frame}{List of input PVs 2}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_1_VAR
\end{tabular}
\caption{List of input PVs, part 2}
\end{table}
\end{tiny}
\end{frame}
\begin{frame}{List of input PVs 3}
\begin{tiny}
\begin{table}[]
\centering
\begin{tabular}{|c|c|c|}
FEATURE_TABLE_2_VAR
\end{tabular}
\caption{List of input PVs, part 3}
\end{table}
\end{tiny}
\end{frame}
INPUTS_VAR
\end{document}
......@@ -44,7 +44,7 @@ for feature attribution for special reports.
"""
__version__ = "0.3.0"
__version__ = "0.4.0"
from bg_net.archiver.indexer_utils import str_to_jst_datetime
import bg_net.bgnet as bgnet
......@@ -162,6 +162,59 @@ def get_latexed_feature(feature_name):
return feature_name.replace("_", "\\_")
def add_table_header(part):
ret = "\\begin{{frame}}{{List of input PVs {}}}\n".format(part)
ret += " \\begin{tiny}\n"
ret += " \\begin{table}[]\n"
ret += " \\centering\n"
ret += " \\begin{tabular}{|c|c|c|}\n"
return ret
def add_table_footer(part):
ret = " \\end{tabular}\n"
ret +=" \\caption{{List of input PVs, part {}}}\n".format(part)
ret +=" \\end{table}\n"
ret +=" \\end{tiny}\n"
ret +="\\end{frame}\n\n"
return ret
def add_table_content(feature_names, ncols=3):
latexed_features = [name.replace("_", "\\_") for name in feature_names]
list_of_rows = ["&".join(latexed_features[i:i+ncols])+r"\\" for i in range(0, len(latexed_features), ncols)]
table_text = "\n".join(list_of_rows)
return table_text + "\n"
def add_table(feature_names, part):
return add_table_header(part) + add_table_content(feature_names) + add_table_footer(part)
def compile_latex_inputs(feature_names):
import math
# Fill tables with input features
# There are three tables for feature names, each can have max of 90 feature names.
ncols = 3
nsplit = 90
# Split features in groups for table
feature_names_split = [feature_names[i:i+nsplit] for i in range(0, len(feature_names), nsplit)]
ntables = math.ceil(len(feature_names)/nsplit)
# Fill the tables
latex_code = ""
for itable in range(ntables):
latexed_features = [name.replace("_", "\\_") for name in feature_names_split[itable]]
list_of_rows = ["&".join(latexed_features[i:i+ncols])+r"\\" for i in range(0, len(latexed_features), ncols)]
table_text = "\n".join(list_of_rows)
latex_code += add_table(feature_names_split[itable], part=itable)
return latex_code
def compile_latex_report(
channel,
obs,
......@@ -177,6 +230,10 @@ def compile_latex_report(
report_path='./'):
"""Compile report as pdf and copy report pdf into report_path"""
year = report_day.year
month = report_day.month
day = report_day.day
with tempfile.TemporaryDirectory() as tmpdirname:
jobname = get_jobname(tag, channel, report_day, shift)
......@@ -186,10 +243,6 @@ def compile_latex_report(
with open(template_path, 'r') as file:
filedata = file.read()
year = report_day.year
month = report_day.month
day = report_day.day
# Replace placeholders in template latex file
filedata = filedata.replace('REPORT_DAY_VAR', '{}-{}-{}'.format(year, month, day))
filedata = filedata.replace('OBS_VAR', '{}'.format(get_latexed_feature(obs)))
......@@ -205,30 +258,12 @@ def compile_latex_report(
filedata = filedata.replace('VERSION_VAR', '{}'.format(__version__))
filedata = filedata.replace('NOW_VAR', '{}'.format(datetime.now().strftime('%Y-%m-%d %X')))
filedata = filedata.replace('NINPUTS_VAR', '{}'.format(len(feature_names)))
filedata = filedata.replace('INPUTS_VAR', compile_latex_inputs(feature_names))
template_base_path = os.path.split(template_path)[0]
filedata = filedata.replace('GOE_LOGO_VAR', '{}'.format(os.path.join(template_base_path,"goe-logo.png")))
filedata = filedata.replace('GOE_LOGO_VAR', '{}'.format(os.path.join(template_base_path,"goe_Logo_2.jpg")))
filedata = filedata.replace('BELLE2_LOGO_VAR', '{}'.format(os.path.join(template_base_path,"belle2-logo.png")))
# Fill tables with input features
# There are three tables for feature names, each can have max of 90 feature names.
ntables = 3
ncols = 3
nsplit = 90
# Split features in groups for table, max 3 tables
feature_names_split = [feature_names[i:i+nsplit] for i in range(0, min(len(feature_names), ntables*nsplit), nsplit)]
# Fill the tables
for itable in range(ntables):
if itable < len(feature_names_split):
latexed_features = [name.replace("_", "\\_") for name in feature_names_split[itable]]
list_of_rows = ["&".join(latexed_features[i:i+ncols])+r"\\" for i in range(0, len(latexed_features), ncols)]
table_text = "\n".join(list_of_rows)
filedata = filedata.replace('FEATURE_TABLE_{}_VAR'.format(itable), table_text)
else:
filedata = filedata.replace('FEATURE_TABLE_{}_VAR'.format(itable), '')
# Write the file out again
texfile = os.path.join(tmpdirname, os.path.basename(template_path))
with open(texfile, 'w') as file:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment