Esempio n. 1
0
    def read(self,
             start,
             end,
             interval="",
             function="",
             ids=[],
             keys=[],
             tags=[],
             attributes={},
             tz=""):
        params = {'start': start.isoformat(), 'end': end.isoformat()}

        if ids:
            params['id'] = ids
        if keys:
            params['key'] = keys
        if interval:
            params['interval'] = interval
        if function:
            params['function'] = function
        if tags:
            params['tag'] = tags
        if attributes:
            params['attr'] = attributes
        if tz:
            params['tz'] = tz

        url = '/data/'
        json = self.request(url, method='GET', params=params)
        return [DataSet.from_json(j) for j in json]
Esempio n. 2
0
    def _read(self,
              series_type,
              series_val,
              start,
              end,
              interval="",
              function="",
              tz=""):
        params = {
            'start': start.isoformat(),
            'end': end.isoformat(),
        }

        # add rollup interval and function if supplied
        if interval:
            params['interval'] = interval
        if function:
            params['function'] = function
        if tz:
            params['tz'] = tz

        url = '/series/%s/%s/data/' % (series_type,
                                       urllib2.quote(series_val, ""))
        json = self.request(url, method='GET', params=params)

        #we got an error
        if 'error' in json:
            return json
        return DataSet.from_json(json)
Esempio n. 3
0
    def test_read(self):
        self.client.session.get.return_value = MockResponse(200, """[{
            "series": {
                "id": "id",
                "key": "key1",
                "name": "",
                "tags": [],
                "attributes": {}
            },
            "start": "2012-03-27T00:00:00.000Z",
            "end": "2012-03-28T00:00:00.000Z",
            "data": [{"t": "2012-03-27T00:00:00.000Z", "v": 12.34}],
            "summary": {}
        }]""")

        start = datetime.datetime(2012, 3, 27)
        end = datetime.datetime(2012, 3, 28)
        datasets = self.client.read(start, end, keys=['key1'])

        expected = [
            DataSet(Series('id', 'key1'), start, end, [DataPoint(start, 12.34)], Summary())]
        self.client.session.get.assert_called_once_with(
            'https://example.com/v1/data/?start=2012-03-27T00%3A00%3A00&end=2012-03-28T00%3A00%3A00&key=key1',
            auth=('key', 'secret'),
            headers=self.get_headers
        )
        self.assertEqual(datasets, expected)
Esempio n. 4
0
    def test_read_key_escape(self):
        self.client.session.get.return_value = MockResponse(
            200, """{
            "series": {
                "id": "id",
                "key": "ke:y/1",
                "name": "",
                "tags": [],
                "attributes": {}
            },
            "start": "2012-03-27T00:00:00.000",
            "end": "2012-03-28T00:00:00.000",
            "data": [{"t": "2012-03-27T00:00:00.000", "v": 12.34}],
            "summary": {},
            "rollup": {}
        }""")

        start = datetime.datetime(2012, 3, 27)
        end = datetime.datetime(2012, 3, 28)
        dataset = self.client.read_key('ke:y/1', start, end)

        expected = DataSet(Series('id', 'ke:y/1'), start, end,
                           [DataPoint(start, 12.34)], Summary(), Rollup())
        self.client.session.get.assert_called_once_with(
            'https://example.com/v1/series/key/ke%3Ay%2F1/data/?start=2012-03-27T00%3A00%3A00&end=2012-03-28T00%3A00%3A00',
            auth=('key', 'secret'),
            headers=self.get_headers)
        print dataset
        print expected
        self.assertEqual(dataset, expected)
Esempio n. 5
0
 def test_init(self):
     start = datetime.datetime(2012, 1, 1)
     end = datetime.datetime(2012, 1, 2)
     series = Series("id", "key")
     data = [DataPoint(start, 12.34), DataPoint(end, 23.45)]
     summary = Summary()
     dataset = DataSet(series, start, end, data, summary)
     self.assertEqual(dataset.series, series)
     self.assertEqual(dataset.start, start)
     self.assertEqual(dataset.end, end)
     self.assertEqual(dataset.data, data)
     self.assertEqual(dataset.summary, summary)
Esempio n. 6
0
 def test_from_json(self):
     json = {
         'series': {
             'id': 'id',
             'key': 'key',
             'name': 'name',
             'tags': ['tag1', 'tag2'],
             'attributes': {'key1': 'value1'},
         },
         'start': '2012-03-27T00:00:00.000Z',
         'end': '2012-03-28T00:00:00.000Z',
         'data': [],
         'summary': {'min': 45.5}
     }
     dataset = DataSet.from_json(json)
     series = Series('id', 'key', 'name', {'key1': 'value1'}, ['tag1', 'tag2'])
     start = datetime.datetime(2012, 3, 27)
     end = datetime.datetime(2012, 3, 28)
     data = []
     summary = Summary(min=45.5)
     expected = DataSet(series, start, end, data, summary)
     self.assertEqual(dataset, expected)
Esempio n. 7
0
    def _read(self, series_type, series_val, start, end, interval="", function="", tz=""):
        params = {
            'start': start.isoformat(),
            'end': end.isoformat(),
        }

        # add rollup interval and function if supplied
        if interval:
            params['interval'] = interval
        if function:
            params['function'] = function
        if tz:
            params['tz'] = tz

        url = '/series/%s/%s/data/' % (series_type, urllib2.quote(series_val, ""))
        json = self.request(url, method='GET', params=params)

        #we got an error
        if 'error' in json:
            return json
        return DataSet.from_json(json)
Esempio n. 8
0
    def read(self, start, end, interval="", function="", ids=[], keys=[], tags=[], attributes={}, tz=""):
        params = {
            'start': start.isoformat(),
            'end': end.isoformat()
        }

        if ids:
            params['id'] = ids
        if keys:
            params['key'] = keys
        if interval:
            params['interval'] = interval
        if function:
            params['function'] = function
        if tags:
            params['tag'] = tags
        if attributes:
            params['attr'] = attributes
        if tz:
            params['tz'] = tz

        url = '/data/'
        json = self.request(url, method='GET', params=params)
        return [DataSet.from_json(j) for j in json]