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

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

Relative effect (s.d.)    {{'{0:.1%}'.format(summary.average.rel_effect)}} ({{'{0:.1%}'.format(SD(summary.average.rel_effect_lower, summary.average.rel_effect_upper, z_score, 4)|float)}}){{add_remaining_spaces(3 + '{0:.1%}'.format(summary.average.rel_effect) | length + '{0:.1%}'.format(SD(summary.average.rel_effect_lower, summary.average.rel_effect_upper, z_score, 4)|float)| string | length)}}{{'{0:.1%}'.format(summary.cumulative.rel_effect)}} ({{'{0:.1%}'.format(SD(summary.cumulative.rel_effect_lower, summary.cumulative.rel_effect_upper, z_score, 4)|float)}})
{{CI(alpha)}}                    [{{'{0:.1%}'.format([summary.average.rel_effect_lower, summary.average.rel_effect_upper]|min)}}, {{'{0:.1%}'.format([summary.average.rel_effect_upper, summary.average.rel_effect_lower]|max)}}]{{add_remaining_spaces(4 + '{0:.1%}'.format([summary.average.rel_effect_lower, summary.average.rel_effect_upper]|min)|length + '{0:.1%}'.format([summary.average.rel_effect_upper, summary.average.rel_effect_lower]|max)|length)}}[{{'{0:.1%}'.format([summary.cumulative.rel_effect_lower, summary.cumulative.rel_effect_upper]|min)}}, {{'{0:.1%}'.format([summary.cumulative.rel_effect_upper, summary.cumulative.rel_effect_lower]|max)}}]

Posterior tail-area probability p: {{p_value|round(3)}}
Posterior prob. of a causal effect: {{'{0:.2%}'.format(1 - p_value)}}

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