示例#1
0
 def test_dataset_iterator(self):
     """Dataset must correctly work as iterable object."""
     dts = Dataset()
     N = 10
     for i in range(N):
         dts.add_row([i])
     for i in range(2):
         self.assertEqual(N, len([i for i in dts]))
示例#2
0
 def test_load_invalid_date_type(self):
     """Test invalid data for dataset fails with verbose message."""
     dts = Dataset([Dataset.DATE])
     try:
         dts.load([['aa-bb-cc']])
         self.fail('dataset has loaded invalid data')
     except dts.ParseError as exc:
         self.assertEqual(
             'Invalid value "aa-bb-cc" in line 1 '
             'for "d" column type (index: 0)', str(exc))
示例#3
0
    def test_get_dataset_columns(self):
        """Test column splitting correctness.

        | 0 | 1 | 2 |
        | 3 | 4 | 5 |
        """
        dts = Dataset()
        [dts.add_row(i) for i in chunk(range(6), 3)]
        for i in range(3):
            self.assertEqual([i, i + 3], list(dts.column(i)))
        # test multiple
        self.assertEqual([(0, 1), (3, 4)], list(dts.column(0, 1)))
        self.assertEqual([(1, 2), (4, 5)], list(dts.column(1, 2)))
示例#4
0
文件: app.py 项目: amadev/metr
def show_metric(metric):
    conn = sqlite3.connect(DB)
    points = get_points(conn, metric)
    conn.close()
    if not os.path.exists(IMAGE_DIR):
        os.makedirs(IMAGE_DIR)
    fname = IMAGE_DIR + '/%s.png' % metric
    d = Dataset([Dataset.DATE, Dataset.FLOAT])
    d.load(points)
    plot_date(d, output=fname, figsize=(14, 7), linestyle='-')

    data = open(fname, 'rb').read()
    r = Response()
    r.body = data
    r.code = '200 OK'
    r.headers = [('content-type', 'image/png'),
                 ('content-length', str(len(r.body)))]
    return r