{# ##### MACROS #### #} {# # #} {% macro MakePlotTable(plots, run) %} {# Convert 'plots' to dictionary with filenames. #} {# plotdict = {'plottype': {'plot_file':[], 'thumb_file':[]}} #} {% set plotdict = run.plot_dict(plots) %} {% if plotdict|length > 0 %} {% for plottype in plotdict %} {% for plotfile, thumbfile in zip(plotdict[plottype]['plot_file'], plotdict[plottype]['thumb_file']) %} {% endfor %} {% endfor %}
{% endif %} {%- endmacro %} {# # #} {% macro PrintMetricInfo(runId, metric, metricInfo) %} {# print metric info, adding link for metric data if available #} {% for key in metricInfo %} {% if key == 'Data' %} npz JSON {% else %} {{ metricInfo[key]|escape }} {% endif %} {% endfor %}
{%- endmacro %} {# # #} {% macro FormatSummaryStat(statname, statvalue) %} {% if False %} {{statvalue}} {% else %} {# convert statvalue from series to single value #} {% if 'Count' in statname or '-3Sigma' in statname or '+3Sigma' in statname or 'TableFraction' in statname %} {{ '%.0f'|format(statvalue) }} {% else %} {% if statvalue|abs < 0.03 %} {{ '%.4f'|format(statvalue) }} {% else %} {{ '%.2f'|format(statvalue) }} {% endif %} {% endif %} {% endif %} {%- endmacro %} {# # #} {% macro MakeStatTable(metrics, group, subgroup, run) %} {# big macro for stats tables #} {# Always split tables so that one table per slicer. #} {# Table can either be: metric rows x stat cols (if #metrics > #stats) #} {# OR stat rows x metric cols (if #stats > #metrics) #} {# OR info_label rows x metric cols (if only single summary stat) #} {# Check that there is *some* summary stat info from this group/subgroup to put into a table #} {% set statNames = run.all_stat_names(metrics) %} {% if statNames|length > 0 %} {# we have some good stats, let's show them. #} {# Put in a link to jump to this part of the page. #} {% set metricInfo = run.metric_info(with_data_link=False, with_slicer_name=False) %} {% set lenMinfo = metricInfo|length %} {% set slicers = run.unique_slicer_names(metrics) %} {% for slicer in slicers %} {# Set up and make table, one per slicer. #} {% set slicermetrics = run.metrics_with_slicer(slicer, metrics) %} {% set slicermetrics = run.metrics_with_stats(slicermetrics) %} {% if slicermetrics|length > 0 %} {# Count number of metric names. #} {% set metricNames = run.unique_metric_names(slicermetrics, baseonly=False) %} {# Count the number of metric + info_label combinations #} {% set metricNameInfo = run.unique_metric_name_and_info_label(slicermetrics) %} {# Count number of different summary metric names. #} {% set statNames = run.all_stat_names(slicermetrics) %} {% if statNames|length == 1 %} {# Only one stat reported per metric/info_label combo #} {# so we make a info_label rows x metric cols table. #} {% set statName = statNames[0] %} {% set InfoLabel = run.unique_metric_info_label(slicermetrics) %} {% set ncols = metricNames|length + 1 %} {# Table header. #} {% for mName in metricNames %} {% endfor %} {% for il in InfoLabel %} {# Find metric that matches the metric name for this column and this info_label. #} {% for mName in metricNames %} {% set mset = run.metrics_with_metric_name(mName, slicermetrics, baseonly=False) %} {% set m = run.metrics_with_info_label(il, mset) %} {% if m|length > 0 %} {% set stats = run.stats_for_metric(m) %} {% set statDict = run.stat_dict(stats) %} {% else %} {% endif %} {% endfor %} {% endfor %}
Group: {{group }}; Subgroup: {{ subgroup }}; Slicer: {{ slicer }}
{{ mName }}
{{il}} {{ FormatSummaryStat(mName, statDict[statName])}} --
{% elif statNames|length <= (metricNameInfo|length + lenMinfo + 3) %} {# make a table with rows = each metric, columns = summary stats #} {% set ncols = statNames|length + lenMinfo %} {# Table header. #} {% for key in metricInfo %} {% endfor %} {% for name in statNames %} {% endfor %} {# Add the summary stat info. #} {% for metric in slicermetrics %} {% set metricInfo = run.metric_info(metric, with_data_link=False, with_slicer_name=False) %} {% set stats = run.stats_for_metric(metric) %} {% set statDict = run.stat_dict(stats) %} {% if statDict|length > 0 %} {# print the metric info - metricname/slicer/info_label #} {% for key in metricInfo %} {% endfor %} {% for statName in statNames %} {% if statName in statDict.keys() %} {% else %} {% endif %} {% endfor %} {% endif %} {% endfor %}
Group: {{group }}; Subgroup: {{ subgroup }}; Slicer: {{slicer}}
{{ key }} {{name}}
{{ metricInfo[key]|escape }} {{ FormatSummaryStat(statName, statDict[statName]) }} --
{% elif statNames|length > (metricNameInfo|length + lenMinfo + 3) %} {# make a table with rows = each summary stats, columns = metrics #} {% set ncols = metricNameInfo|length + 1 %} {# Table header. #} {% for m in slicermetrics %} {% set mInfo = run.metric_info(m, with_data_link=False, with_slicer_name=False) %} {% endfor %} {% for m in slicermetrics %} {% set mInfo = run.metric_info(m, with_data_link=False, with_slicer_name=False) %} {% endfor %} {# Add the summary stat info. #} {% for statName in statNames %} {# Find metric that matches the metric name for this column and this statName. #} {% for m in slicermetrics %} {% set stats = run.stats_for_metric(m, stat_name=statName) %} {# there should only ever be either 1 or 0 statName/metricName/metricInfoLabel combo #} {% if stats|length == 0 %} {% else %} {% set statDict = run.stat_dict(stats) %} {% endif %} {% endfor %} {% endfor %}
Group: {{group }}; Subgroup: {{ subgroup }}; Slicer: {{slicer}}
{{mInfo['MetricName']}}
{{mInfo['InfoLabel']}}
{{statName}} -- {{ FormatSummaryStat(statName, statDict[statName]) }}
{% endif %} {# End of various table options. #} {% endif %} {# End of 'if' to skip table for slicer. #} {% endfor %} {# End of running through slicers. #} {% endif %} {# End of if to skip all table creation. #} {%- endmacro %}