Ejemplo n.º 1
0
def plot_gaussian_dates():
    """
    Used to demonstrate that the Gaussian date generator is indeed a Gaussian.
    This function will display a histogram - it should look bell-shaped!
    """
    # generate test data
    mean = datetime.datetime(2010, 12, 1, 0, 0)
    sigma_in_days = 100
    dates = gaussian_date_generator(mean, sigma_in_days)
    dates_in_seconds = [(dates.next() - datetime.datetime.utcfromtimestamp(0)).total_seconds()
                        for _ in range(1000)]
    plot_points(dates_in_seconds, 100)
Ejemplo n.º 2
0
    def test_gaussian_date_generator(self):
        """ Confirm that the generated dates are distributed according
        to a Gaussian. We doe this assertion 10 times.
        """
        expected_mean = datetime(2014, 6, 1)
        expected_sigma_in_days = 100
        gg = gaussian_date_generator(expected_mean, expected_sigma_in_days)
        for _ in range(10):
            distribution = [next(gg) for _ in range(100000)]
            seconds = [convert_datetime_to_seconds(d) for d in distribution]
            actual_mean = self.mean(seconds)
            diff = actual_mean - convert_datetime_to_seconds(expected_mean)
            diff_in_days = seconds_to_days(diff)
            one_day = 1

            # assert stuff
            self.assertLessEqual(diff_in_days, one_day)

            actual_sigma = self.standard_deviation(seconds)
            diff = abs(actual_sigma - days_to_seconds(expected_sigma_in_days))
            self.assertLessEqual(diff, days_to_seconds(1))