Ejemplo n.º 1
0
 def test_artificial_data(self):
     dt1 = datetime.datetime(2019, 8, 1)
     dt2 = datetime.datetime(2019, 9, 1)
     data = artificial_data(dt1, dt2, minutes=24 * 60)
     self.assertEqual(data.shape, (27, 2))
     data = artificial_data(dt1, dt2, minutes=60)
     self.assertEqual(data.shape, (297, 2))
     self.assertEqual(data.shape[0] * 1. / 27, data.shape[0] // 27)
Ejemplo n.º 2
0
 def test_clusters2(self):
     dt1 = datetime.datetime(2018, 8, 1)
     dt2 = datetime.datetime(2019, 8, 15)
     data = artificial_data(dt1, dt2, minutes=15)
     data['y2'] = data['y'] + 1.
     names = numpy.empty(data.shape[0], dtype=str)
     names[:] = 'A'
     for i in range(1, 20):
         names[i::20] = 'BCDEFGHIJKLMNOPQRSTUVWXYZ'[i]
     clusters, dists = find_ts_group_pattern(data['time'].values,
                                             data[['y',
                                                   'y2']].values, names)
     self.assertEqual(clusters.shape[0], dists.shape[0])
     self.assertEqual(8, dists.shape[1])
Ejemplo n.º 3
0
    def test_agg_data(self):
        dt1 = datetime.datetime(2019, 8, 1)
        dt2 = datetime.datetime(2019, 8, 8)
        data = artificial_data(dt1, dt2, minutes=15)
        data['y'] = 1
        agg = aggregate_timeseries(data, per='week')
        self.assertEqual(agg.shape, (132, 2))
        self.assertEqual(agg['y'].min(), 2)
        self.assertEqual(agg['y'].max(), 2)

        dt1 = datetime.datetime(2019, 8, 1)
        dt2 = datetime.datetime(2019, 8, 15)
        data = artificial_data(dt1, dt2, minutes=15)
        data['y'] = 1
        agg = aggregate_timeseries(data, per='week')
        self.assertEqual(agg.shape, (132, 2))
        self.assertEqual(agg['y'].min(), 4)
        self.assertEqual(agg['y'].max(), 4)

        agg = aggregate_timeseries(data, per='month')
        self.assertEqual(agg.shape, (264, 2))
        self.assertEqual(agg['y'].min(), 2)
        self.assertEqual(agg['y'].max(), 2)
Ejemplo n.º 4
0
 def test_plot_data(self):
     import matplotlib.pyplot as plt  # pylint: disable=C0415
     dt1 = datetime.datetime(2019, 8, 1)
     dt2 = datetime.datetime(2019, 8, 15)
     data = artificial_data(dt1, dt2, minutes=15)
     agg = aggregate_timeseries(data, per='week')
     ax = plot_week_timeseries(agg['weektime'],
                               agg['y'],
                               label="y",
                               value2=agg['y'] / 2,
                               label2="y/2",
                               normalise=False)
     self.assertNotEmpty(ax)
     if __name__ == "__main__":
         plt.show()
     plt.clf()
Ejemplo n.º 5
0
 def test_plot_data(self):
     try:
         import matplotlib.pyplot as plt  # pylint: disable=C0415
     except Exception as e:
         if 'generated new fontManager' in str(e):
             warnings.warn(e)
             return
         raise e
     dt1 = datetime.datetime(2019, 8, 1)
     dt2 = datetime.datetime(2019, 8, 15)
     data = artificial_data(dt1, dt2, minutes=15)
     agg = aggregate_timeseries(data, per='week')
     ax = plot_week_timeseries(agg['weektime'],
                               agg['y'],
                               label="y",
                               value2=agg['y'] / 2,
                               label2="y/2",
                               normalise=False)
     self.assertNotEmpty(ax)
     if __name__ == "__main__":
         plt.show()
     plt.clf()