{% macro CI(alpha) %}{{(((1 - alpha) * 100) | string).rstrip('0').rstrip('.')}}% CI{% endmacro -%}
{% macro SD(lower, upper, z_score, digits=2) %}{{((([upper, lower]|max) - ([upper, lower]|min)) / (2 * z_score)) | round(digits)}}{% endmacro -%}
{% macro add_remaining_spaces(n) %}{{' ' * (19 -n)}}{% endmacro -%}
Posterior Inference {Causal Impact}
                          Average            Cumulative
Actual                    {{summary.average.actual | round(digits)}}{{add_remaining_spaces(summary.average.actual | round(digits) | string | length)}}{{summary.cumulative.actual | round(digits)}}
Prediction (s.d.)         {{summary.average.predicted | round(digits)}} ({{SD(summary.average.predicted_lower, summary.average.predicted_upper, z_score, digits)}}){{add_remaining_spaces(summary.average.predicted | round(digits) | string | length + 3 + SD(summary.average.predicted_lower, summary.average.predicted_upper, z_score, digits) | string | length)}}{{summary.cumulative.predicted | round(digits)}} ({{SD(summary.cumulative.predicted_lower, summary.cumulative.predicted_upper, z_score, digits)}})
{{CI(alpha)}}                    [{{summary.average.predicted_lower | round(digits)}}, {{summary.average.predicted_upper | round(digits)}}]{{add_remaining_spaces(4 + summary.average.predicted_lower | round(digits) | string | length + summary.average.predicted_upper | round(digits) | string | length)}}[{{summary.cumulative.predicted_lower | round(digits)}}, {{summary.cumulative.predicted_upper | round(digits)}}]

Absolute effect (s.d.)    {{summary.average.abs_effect | round(digits)}} ({{SD(summary.average.abs_effect_lower, summary.average.abs_effect_upper, z_score, digits)}}){{add_remaining_spaces(3 + summary.average.abs_effect | round(digits) | string | length + SD(summary.average.abs_effect_lower, summary.average.abs_effect_upper, z_score, digits) | string | length)}}{{summary.cumulative.abs_effect | round(digits)}} ({{SD(summary.cumulative.abs_effect_lower, summary.cumulative.abs_effect_upper, z_score, digits)}})
{{CI(alpha)}}                    {{[summary.average.abs_effect_lower | round(digits), summary.average.abs_effect_upper | round(digits)] | sort}}{{add_remaining_spaces(4 + summary.average.abs_effect_lower | round(digits) | string | length + summary.average.abs_effect_upper | round(digits) | string | length)}}{{[summary.cumulative.abs_effect_lower | round(digits), summary.cumulative.abs_effect_upper | round(digits)] | sort}}

Relative effect (s.d.)    {{(summary.average.rel_effect * 100) | round(digits)}}% ({{(100 * SD(summary.average.rel_effect_lower, summary.average.rel_effect_upper, z_score, 4) | float) | round(digits)}}%){{add_remaining_spaces(5 + (summary.average.rel_effect * 100) | round(digits) | string | length + (100 * SD(summary.average.rel_effect_lower, summary.average.rel_effect_upper, z_score, 4) | float) | round(digits) | string | length)}}{{(100 * summary.cumulative.rel_effect) | round(digits)}}% ({{(100 * SD(summary.cumulative.rel_effect_lower, summary.cumulative.rel_effect_upper, z_score, 4)|float) | round(digits)}}%)
{{CI(alpha)}}                    [{{([(summary.average.rel_effect_lower * 100) | round(digits), (summary.average.rel_effect_upper * 100) | round(digits)] | min)}}%, {{([(100 * summary.average.rel_effect_upper) | round(digits), (100 * summary.average.rel_effect_lower) | round(digits)] | max)}}%]{{add_remaining_spaces(6 + ([(summary.average.rel_effect_lower * 100) | round(digits), (summary.average.rel_effect_upper * 100) | round(digits)] | min) | string | length +  ([(100 * summary.average.rel_effect_upper) | round(digits), (100 * summary.average.rel_effect_lower) | round(digits)] | max) | string | length)}}[{{([(100 * summary.cumulative.rel_effect_lower) | round(digits), (100 * summary.cumulative.rel_effect_upper) | round(digits)] | min)}}%, {{([(100 * summary.cumulative.rel_effect_upper) | round(digits), (100 * summary.cumulative.rel_effect_lower) | round(digits)] | max)}}%]

Posterior tail-area probability p: {{p_value|round(digits)}}
Posterior prob. of a causal effect: {{((1 - p_value) * 100) | round(digits)}}%

For more details run the command: print(impact.summary('report'))
