Commit efe7c617 authored by Benjamin Schwenker's avatar Benjamin Schwenker
Browse files

Merge branch '41-better-listing-of-inputs-pvs' into 'master'

Resolve "better listing of inputs PVs"

Closes #41

See merge request !44
parents f91bfc04 5afb4e84
......@@ -46,7 +46,7 @@
\item Explain ref data: REF_START_VAR to REF_STOP_VAR
\item Explain test data: TEST_START_VAR to TEST_STOP_VAR
\item Lookback range for plotting is LOOK_BACK_VAR days
\item Input variables listed on last slides (TODO)
\item Input variables listed on last slides
\end{itemize}
\end{frame}
......@@ -279,4 +279,6 @@
\end{figure}
\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}
......@@ -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.1"
from bg_net.archiver.indexer_utils import str_to_jst_datetime
import bg_net.bgnet as bgnet
......@@ -60,6 +60,7 @@ import bg_net.archiver.indexer_utils as indexer_utils
from bg_net.archiver.skb_naming import get_unit
import bg_net.archiver.connect_vpn as connect_vpn
import math
import os
import yaml
import sys
......@@ -162,6 +163,65 @@ def get_latexed_feature(feature_name):
return feature_name.replace("_", "\\_")
def add_table_header(title):
"""Returns latex code string for header of table slide"""
ret = "\\begin{frame}{MyTitle}\n"
ret += " \\begin{tiny}\n"
ret += " \\begin{table}[]\n"
ret += " \\centering\n"
ret += " \\begin{tabular}{|c|c|c|}\n"
ret = ret.replace('MyTitle', get_latexed_feature(title))
return ret
def add_table_footer(title):
"""Returns latex code string for footer of table slide"""
ret = " \\end{tabular}\n"
ret +=" \\caption{MyTitle}\n"
ret +=" \\end{table}\n"
ret +=" \\end{tiny}\n"
ret +="\\end{frame}\n\n"
ret = ret.replace('MyTitle', get_latexed_feature(title))
return ret
def add_table_content(feature_names, ncols=3):
"""Returns latex code string for content of table slide"""
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, title):
"""Returns latex code string for table slide"""
return add_table_header(title) + add_table_content(feature_names) + add_table_footer(title)
def compile_latex_inputs(features_dict):
"""Returns latex code string for compiling tables with input variable names"""
# Each table has 3 columns and can have up to 90 feature names
ncols = 3
nsplit = 90
# Latex code for compiling tables
latex_code = ""
for model, feature_names in features_dict.items():
# 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)
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)
title = "List of input PVs for model {}, part {}".format(model, itable+1)
latex_code += add_table(feature_names_split[itable], title)
return latex_code
def compile_latex_report(
channel,
obs,
......@@ -173,10 +233,14 @@ def compile_latex_report(
train_times,
attr_ref_times,
attr_test_times,
feature_names=[],
report_path='./'):
features_dict,
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,9 +250,10 @@ 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
# Count number of inputs, over all submodels
ninputs = 0
for _, feature_names in features_dict.items():
ninputs += len(feature_names)
# Replace placeholders in template latex file
filedata = filedata.replace('REPORT_DAY_VAR', '{}-{}-{}'.format(year, month, day))
......@@ -204,31 +269,13 @@ def compile_latex_report(
filedata = filedata.replace('LOOK_BACK_VAR', '{}'.format(look_back))
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('NINPUTS_VAR', '{}'.format(ninputs))
filedata = filedata.replace('INPUTS_VAR', compile_latex_inputs(features_dict))
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:
......@@ -423,7 +470,7 @@ def report_on_channel(
train_times=train_times,
attr_ref_times=ref_times[0],
attr_test_times=test_times[0],
feature_names=feature_names,
features_dict={channel: feature_names},
report_path=report_path,
)
......@@ -715,7 +762,7 @@ def report_on_hitrate(
train_times=train_times,
attr_ref_times=ref_times[0],
attr_test_times=test_times[0],
feature_names=feature_names,
features_dict={sub_model: hitrate.get_interpretable_feature_names(config, name=sub_model) for sub_model in hitrate.sub_models},
report_path=report_path,
)
......
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