Beispiel #1
0
    def get(self, channels, start, end, limit=100, interpolation='linear',
            scan_archives=True, archive_keys=None, tz=None):
        """
        channels : string or list of strings
            channel identifiers (not human-friendly names)
        start : string or datetime
            Strings are interpreted as ISO timestamps.
        end : string or datetime
            Strings are interpreted as ISO timestamps.
        interpolation : string
            Higher layers should be handling all the interpolation,
            so although this default value matches the ChannelArchiver
            default ('linear') that will raise an error here. All
            calls must specify interpolation='raw'.

        TODO: The other parameters are not yet implemented. They
        are merely ignored.
        """

        if interpolation != 'raw':
            raise NotImplementedError("We should not ask the Archiver "
                                      "to interpolate.")

        # If channels is not a list, make it a one-element list.
        received_str = isinstance(channels, six.string_types)
        if received_str:
            channels = [channels]

        if isinstance(start, six.string_types):
            start = utils.datetime_from_isoformat(start)
        if isinstance(end, six.string_types):
            end = utils.datetime_from_isoformat(end)

        if start.tzinfo is None:
            start = utils.localize_datetime(start, utils.local_tz)

        if end.tzinfo is None:
            end = utils.localize_datetime(end, utils.local_tz)

        result = []
        for channel in channels:
            times, values = _data[channel]
            result.append(ChannelData(values=values, times=times))

        if received_str:
            result = result[0]
        return result
def test_datetime_isoformat_with_dst():
    iso_str = "2013-02-07 10:21:55.012345"
    local_tz = utils.local_tz
    utils.local_tz = melbourne_tz
    dt = utils.datetime_from_isoformat(iso_str)
    utils.local_tz = local_tz
    assert dt.utcoffset() == timedelta(0, 39600)
    dt_correct = melbourne_tz.localize(datetime(2013, 2, 7, 10, 21, 55, 12345))
    assert dt == dt_correct
Beispiel #3
0
def test_datetime_isoformat_with_dst():
    iso_str = '2013-02-07 10:21:55.012345'
    local_tz = utils.local_tz
    utils.local_tz = melbourne_tz
    dt = utils.datetime_from_isoformat(iso_str)
    utils.local_tz = local_tz
    assert dt.utcoffset() == timedelta(0, 39600)
    dt_correct = melbourne_tz.localize(datetime(2013, 2, 7, 10, 21, 55, 12345))
    assert dt == dt_correct
Beispiel #4
0
    def test_datetime_isoformat_with_dst(self):
        iso_str = '2013-02-07 10:21:55.012345'

        local_tz = utils.local_tz
        utils.local_tz = melbourne_tz
        dt = utils.datetime_from_isoformat(iso_str)
        utils.local_tz = local_tz

        self.assertEqual(dt.utcoffset(), datetime.timedelta(0, 39600))
        dt_correct = melbourne_tz.localize(datetime.datetime(2013, 2, 7, 10, 21, 55, 12345))
        self.assertEqual(dt, dt_correct)
Beispiel #5
0
    def test_datetime_isoformat_with_dst(self):
        iso_str = '2013-02-07 10:21:55.012345'

        local_tz = utils.local_tz
        utils.local_tz = melbourne_tz
        dt = utils.datetime_from_isoformat(iso_str)
        utils.local_tz = local_tz

        self.assertEqual(dt.utcoffset(), datetime.timedelta(0, 39600))
        dt_correct = melbourne_tz.localize(
            datetime.datetime(2013, 2, 7, 10, 21, 55, 12345))
        self.assertEqual(dt, dt_correct)
def test_datetime_isoformat_bad_str():
    iso_str = "09:00 21/08/2103"
    with pytest.raises(ValueError):
        utils.datetime_from_isoformat(iso_str)
Beispiel #7
0
 def test_datetime_isoformat_no_secs_tz(self):
     iso_str = '2013-08-07 10:21-09:00'
     dt = utils.datetime_from_isoformat(iso_str)
     self.assertEqual(
         dt, datetime.datetime(2013, 8, 7, 10, 21, 0, 0, utils.UTC(-9)))
Beispiel #8
0
 def test_datetime_isoformat_no_hrs(self):
     iso_str = '2013-08-07'
     dt = utils.datetime_from_isoformat(iso_str)
     dt_correct = utils.local_tz.localize(
         datetime.datetime(2013, 8, 7, 0, 0, 0, 0))
     self.assertEqual(dt, dt_correct)
Beispiel #9
0
def test_datetime_isoformat_with_short_tz():
    iso_str = '2013-08-07 10:21:55.012345+08'
    dt = utils.datetime_from_isoformat(iso_str)
    assert dt == datetime(2013, 8, 7, 10, 21, 55, 12345, utils.UTC(8))
def test_datetime_isoformat_no_ms():
    iso_str = "2013-08-07 10:21:55Z"
    dt = utils.datetime_from_isoformat(iso_str)
    assert dt == datetime(2013, 8, 7, 10, 21, 55, 0, utils.utc)
Beispiel #11
0
 def test_datetime_isoformat_with_tz(self):
     iso_str = '2013-08-07 10:21:55.012345+08'
     dt = utils.datetime_from_isoformat(iso_str)
     self.assertEqual(dt, datetime.datetime(2013, 8, 7, 10, 21, 55, 12345, utils.UTC(8)))
Beispiel #12
0
def test_datetime_isoformat_with_T():
    iso_str = '2013-08-07T10:21:55.012345'
    dt = utils.datetime_from_isoformat(iso_str)
    dt_correct = utils.local_tz.localize(datetime(2013, 8, 7, 10, 21, 55, 12345))
    assert dt == dt_correct
Beispiel #13
0
 def test_datetime_isoformat_with_T(self):
     iso_str = '2013-08-07T10:21:55.012345'
     dt = utils.datetime_from_isoformat(iso_str)
     dt_correct = utils.local_tz.localize(
         datetime.datetime(2013, 8, 7, 10, 21, 55, 12345))
     self.assertEqual(dt, dt_correct)
Beispiel #14
0
 def test_datetime_isoformat_no_secs(self):
     iso_str = '2013-08-07 10:21Z'
     dt = utils.datetime_from_isoformat(iso_str)
     self.assertEqual(
         dt, datetime.datetime(2013, 8, 7, 10, 21, 0, 0, utils.utc))
def test_datetime_isoformat_no_hrs():
    iso_str = "2013-08-07"
    dt = utils.datetime_from_isoformat(iso_str)
    dt_correct = utils.local_tz.localize(datetime(2013, 8, 7, 0, 0, 0, 0))
    assert dt == dt_correct
def test_datetime_isoformat_no_secs_tz():
    iso_str = "2013-08-07 10:21-09:00"
    dt = utils.datetime_from_isoformat(iso_str)
    assert dt == datetime(2013, 8, 7, 10, 21, 0, 0, utils.UTC(-9))
Beispiel #17
0
 def test_datetime_isoformat_no_hrs(self):
     iso_str = '2013-08-07'
     dt = utils.datetime_from_isoformat(iso_str)
     dt_correct = utils.local_tz.localize(datetime.datetime(2013, 8, 7, 0, 0, 0, 0))
     self.assertEqual(dt, dt_correct)
Beispiel #18
0
 def test_datetime_isoformat_no_secs_tz(self):
     iso_str = '2013-08-07 10:21-09:00'
     dt = utils.datetime_from_isoformat(iso_str)
     self.assertEqual(dt, datetime.datetime(2013, 8, 7, 10, 21, 0, 0, utils.UTC(-9)))
Beispiel #19
0
 def test_datetime_isoformat_no_secs(self):
     iso_str = '2013-08-07 10:21Z'
     dt = utils.datetime_from_isoformat(iso_str)
     self.assertEqual(dt, datetime.datetime(2013, 8, 7, 10, 21, 0, 0, utils.utc))
Beispiel #20
0
 def test_datetime_isoformat_with_tz(self):
     iso_str = '2013-08-07 10:21:55.012345+08'
     dt = utils.datetime_from_isoformat(iso_str)
     self.assertEqual(
         dt, datetime.datetime(2013, 8, 7, 10, 21, 55, 12345, utils.UTC(8)))
Beispiel #21
0
def test_datetime_isoformat_no_secs_tz():
    iso_str = '2013-08-07 10:21-09:00'
    dt = utils.datetime_from_isoformat(iso_str)
    assert dt == datetime(2013, 8, 7, 10, 21, 0, 0, utils.UTC(-9))
Beispiel #22
0
def test_datetime_isoformat_bad_str():
    iso_str = '09:00 21/08/2103'
    with pytest.raises(ValueError):
        utils.datetime_from_isoformat(iso_str)
Beispiel #23
0
 def test_datetime_isoformat(self):
     iso_str = '2013-08-07 10:21:55.012345'
     dt = utils.datetime_from_isoformat(iso_str)
     dt_correct = utils.local_tz.localize(datetime.datetime(2013, 8, 7, 10, 21, 55, 12345))
     self.assertEqual(dt, dt_correct)
Beispiel #24
0
def test_datetime_isoformat_no_hrs():
    iso_str = '2013-08-07'
    dt = utils.datetime_from_isoformat(iso_str)
    dt_correct = utils.local_tz.localize(datetime(2013, 8, 7, 0, 0, 0, 0))
    assert dt == dt_correct
def test_datetime_isoformat_with_T():
    iso_str = "2013-08-07T10:21:55.012345"
    dt = utils.datetime_from_isoformat(iso_str)
    dt_correct = utils.local_tz.localize(
        datetime(2013, 8, 7, 10, 21, 55, 12345))
    assert dt == dt_correct
def test_datetime_isoformat_with_Z():
    iso_str = "2013-08-07 10:21:55.012345Z"
    dt = utils.datetime_from_isoformat(iso_str)
    assert dt == datetime(2013, 8, 7, 10, 21, 55, 12345, utils.utc)
def test_datetime_isoformat_with_short_tz():
    iso_str = "2013-08-07 10:21:55.012345+08"
    dt = utils.datetime_from_isoformat(iso_str)
    assert dt == datetime(2013, 8, 7, 10, 21, 55, 12345, utils.UTC(8))
Beispiel #28
0
def test_datetime_isoformat_with_Z():
    iso_str = '2013-08-07 10:21:55.012345Z'
    dt = utils.datetime_from_isoformat(iso_str)
    assert dt == datetime(2013, 8, 7, 10, 21, 55, 12345, utils.utc)
def test_datetime_isoformat_no_secs():
    iso_str = "2013-08-07 10:21Z"
    dt = utils.datetime_from_isoformat(iso_str)
    assert dt == datetime(2013, 8, 7, 10, 21, 0, 0, utils.utc)
Beispiel #30
0
def test_datetime_isoformat_no_secs():
    iso_str = '2013-08-07 10:21Z'
    dt = utils.datetime_from_isoformat(iso_str)
    assert dt == datetime(2013, 8, 7, 10, 21, 0, 0, utils.utc)
def test_datetime_isoformat_with_tz():
    iso_str = "2013-08-07 10:21:55.012345+10:00"
    dt = utils.datetime_from_isoformat(iso_str)
    assert dt == datetime(2013, 8, 7, 10, 21, 55, 12345, utils.UTC(10))