Esempio n. 1
0
    def summary(self, output: str = 'summary', digits: int = 2) -> str:
        """
        Builds and prints the summary report.

        Args
        ----
          output: str
              Can be either "summary" or "report". The first is a simpler output just
              informing general metrics such as expected absolute or relative effect.
          digits: int
              Defines the number of digits after the decimal point to round. For
              `digits=2`, value 1.566 becomes 1.57.

        Returns
        -------
          summary: str
              Contains results of the causal impact analysis.

        Raises
        ------
          ValueError: If input `output` is not either 'summary' or 'report'.
                      If input `digits` is not of type integer.
        """
        if not isinstance(digits, int):
            raise ValueError(
                f'Input value for digits must be integer. Received "{type(digits)}" '
                'instead.')
        result = summarizer.summary(self.summary_data, self.p_value,
                                    self.alpha, output, digits)
        return result
Esempio n. 2
0
def test_output_summary_1(summary_data, fix_path):
    alpha = 0.1
    p_value = 0.459329

    result = summarizer.summary(summary_data, p_value, alpha=alpha)
    expected = open(os.path.join(fix_path,
                                 'test_output_summary_1')).read().strip()
    assert result == expected
Esempio n. 3
0
def test_output_summary_single_digit(summary_data, fix_path):
    summarizer.summary_data = summary_data
    alpha = 0.1
    p_value = 0.459329

    result = summarizer.summary(summary_data, p_value, alpha, digits=1)
    expected = open(os.path.join(
        fix_path, 'test_output_summary_single_digit')).read().strip()
    assert result == expected
Esempio n. 4
0
def test_report_summary_1(summary_data, fix_path):
    # detected positive signal but with no significance.
    alpha = 0.1
    p_value = 0.5
    summary_data['average']['rel_effect'] = 0.41
    summary_data['average']['rel_effect_lower'] = -0.30
    summary_data['average']['rel_effect_upper'] = 0.30

    result = summarizer.summary(summary_data,
                                p_value,
                                alpha=alpha,
                                output='report')
    expected = open(os.path.join(fix_path,
                                 'test_report_summary_1')).read().strip()
    assert result == expected
Esempio n. 5
0
def test_report_summary_4(summary_data, fix_path):
    # detected negative signal with significance.
    summary_data['average']['rel_effect'] = -0.343
    summary_data['average']['rel_effect_lower'] = -0.434
    summary_data['average']['rel_effect_upper'] = -0.234
    alpha = 0.1
    p_value = 0.05

    result = summarizer.summary(summary_data,
                                p_value,
                                alpha=alpha,
                                output='report')
    expected = open(os.path.join(fix_path,
                                 'test_report_summary_4')).read().strip()
    assert result == expected
Esempio n. 6
0
def test_summary_raises(summary_data):
    with pytest.raises(ValueError):
        summarizer.summary(summary_data, 0.1, output='test')