{# ##### MACROS #### #} {# # #} {% macro MakePlotTable(plots, run) %} {# Convert 'plots' to dictionary with filenames. #} {# plotdict = {'plotType': {'plotFile':[], 'thumbFile':[]}} #} {% set plotdict = run.plotDict(plots) %} {% if plotdict|length > 0 %} {% for plottype in plotdict %} {% for plotfile, thumbfile in zip(plotdict[plottype]['plotFile'], plotdict[plottype]['thumbFile']) %} {% 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 %} {{ '%d'|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 metadata 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.allStatNames(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.metricInfo(withDataLink=False, withSlicerName=False) %} {% set lenMinfo = metricInfo|length %} {% set slicers = run.uniqueSlicerNames(metrics) %} {% for slicer in slicers %} {# Set up and make table, one per slicer. #} {% set slicermetrics = run.metricsWithSlicer(slicer, metrics) %} {% set slicermetrics = run.metricsWithStats(slicermetrics) %} {% if slicermetrics|length > 0 %} {# Count number of metric names. #} {% set metricNames = run.uniqueMetricNames(slicermetrics, baseonly=False) %} {# Count the number of metric + metadata combinations #} {% set metricNameMeta = run.uniqueMetricNameAndMetadata(slicermetrics) %} {# Count number of different summary metric names. #} {% set statNames = run.allStatNames(slicermetrics) %} {% if statNames|length == 1 %} {# Only one stat reported per metric/metadata combo #} {# so we make a metadata rows x metric cols table. #} {% set statName = statNames[0] %} {% set metadata = run.uniqueMetricMetadata(slicermetrics) %} {% set ncols = metricNames|length + 1 %} {# Table header. #} {% for mName in metricNames %} {% endfor %} {% for meta in metadata %} {# Find metric that matches the metric name for this column and this metadata. #} {% for mName in metricNames %} {% set mset = run.metricsWithMetricName(mName, slicermetrics, baseonly=False) %} {% set m = run.metricsWithMetadata(meta, mset) %} {% if m|length > 0 %} {% set stats = run.statsForMetric(m) %} {% set statDict = run.statDict(stats) %} {% else %} {% endif %} {% endfor %} {% endfor %}
Group: {{group }}; Subgroup: {{ subgroup }}; Slicer: {{ slicer }}
{{ mName }}
{{meta}} {{ FormatSummaryStat(mName, statDict[statName])}} --
{% elif statNames|length <= (metricNameMeta|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.metricInfo(metric, withDataLink=False, withSlicerName=False) %} {% set stats = run.statsForMetric(metric) %} {% set statDict = run.statDict(stats) %} {% if statDict|length > 0 %} {# print the metric info - metricname/slicer/metadata #} {% 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 > (metricNameMeta|length + lenMinfo + 3) %} {# make a table with rows = each summary stats, columns = metrics #} {% set ncols = metricNameMeta|length + 1 %} {# Table header. #} {% for m in slicermetrics %} {% set mInfo = run.metricInfo(m, withDataLink=False, withSlicerName=False) %} {% endfor %} {% for m in slicermetrics %} {% set mInfo = run.metricInfo(m, withDataLink=False, withSlicerName=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.statsForMetric(m, statName=statName) %} {# there should only ever be either 1 or 0 statName/metricName/metricMetadata combo #} {% if stats|length == 0 %} {% else %} {% set statDict = run.statDict(stats) %} {% endif %} {% endfor %} {% endfor %}
Group: {{group }}; Subgroup: {{ subgroup }}; Slicer: {{slicer}}
{{mInfo['MetricName']}}
{{mInfo['Metadata']}}
{{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 %}