def __init__(self, input_time, input_value, id=None): """ id is optional and could be None auto generate id is handled by FileStorageManager if id is None """ if id == None: id = StorageManager.generateId() StorageManager.store(str(id), ArrayTimeSeries(input_time, input_value)) self._id = str(id)
def test_valid_ts_range_time(): ts = SMTimeSeries(range(2, 7), range(0, 5)) arrayts = StorageManager.get(ts._id) assert np.array_equal(arrayts._value, np.array([0, 1, 2, 3, 4])) assert np.array_equal(arrayts._time, np.array([2, 3, 4, 5, 6])) assert np.array_equal(arrayts._timeseries, np.array([(2, 0), (3, 1), (4, 2), (5, 3), (6, 4)]))
def test_construct_with_id_num(): ts = SMTimeSeries([3, 5], [9, 3], 1990) arrayts = StorageManager.get(ts._id) assert ts._id == str(1990) assert np.array_equal(arrayts._value, np.array([9, 3])) assert np.array_equal(arrayts._time, np.array([3, 5])) assert np.array_equal(arrayts._timeseries, np.array([(3, 9), (5, 3)]))
def test_empty_ts(): ts = SMTimeSeries([], []) arrayts = StorageManager.get(ts._id) for t in arrayts._value == np.array([]): assert t for t in arrayts._time == np.array([]): assert t for t in arrayts._timeseries == np.array([]): assert t
def subConst(self, num): arrayts1 = StorageManager.get(self._id) arraydiff = arrayts1.subConst(num) return SMTimeSeries(arraydiff.times(), arraydiff.values())
def addConst(self, num): arrayts1 = StorageManager.get(self._id) arraysum = arrayts1.addConst(num) return SMTimeSeries(arraysum.times(), arraysum.values())
def __add__(self, otherTS): arrayts1 = StorageManager.get(self._id) arrayts2 = StorageManager.get(otherTS._id) arraysum = arrayts1 + arrayts2 return SMTimeSeries(arraysum.times(), arraysum.values())
def iteritems(self): # raise NotImplementedError('Concrete Implementation are missing for iteritems') arrayts = StorageManager.get(self._id) return arrayts.iteritems()
def values(self): arrayts = StorageManager.get(self._id) return arrayts.values()
def test_valid_ts_with_time(): ts = SMTimeSeries([3, 5], [9, 3]) arrayts = StorageManager.get(ts._id) assert np.array_equal(arrayts._value, np.array([9, 3])) assert np.array_equal(arrayts._time, np.array([3, 5])) assert np.array_equal(arrayts._timeseries, np.array([(3, 9), (5, 3)]))
def __mul__(self, otherTS): arrayts1 = StorageManager.get(self._id) arrayts2 = StorageManager.get(otherTS._id) arrayproduct = arrayts1 * arrayts2 return SMTimeSeries(arrayproduct.times(), arrayproduct.values())
def __len__(self): arrayts = StorageManager.get(self._id) return len(arrayts.values())
def items(self): arrayts = StorageManager.get(self._id) return arrayts.items()
def __str__(self): """ Returns a string represenation of the TimeSeries. If there are more than 10 elements, the rest are abbreviated. """ arrayts = StorageManager.get(self._id) return str(arrayts)
def __repr__(self): arrayts = StorageManager.get(self._id) return repr(arrayts)
def __bool__(self): arrayts = StorageManager.get(self._id) return bool(abs(arrayts))
def __abs__(self): arrayts = StorageManager.get(self._id) return abs(arrayts)
def __contains__(self, value): arrayts = StorageManager.get(self._id) return (value in arrayts)
def multConst(self, num): arrayts1 = StorageManager.get(self._id) arrayproduct = arrayts1.multConst(num) return SMTimeSeries(arrayproduct.times(), arrayproduct.values())
def __eq__(self, otherTS): arrayts1 = StorageManager.get(self._id) arrayts2 = StorageManager.get(otherTS._id) return arrayts1 == arrayts2
def interpolate(self, newTimes): arrayts = StorageManager.get(self._id) arrayinterpolate = arrayts.interpolate(newTimes) return SMTimeSeries(arrayinterpolate.times(), arrayinterpolate.values())
def __neg__(self): arrayts = StorageManager.get(self._id) return SMTimeSeries(arrayts.times(), -arrayts.values())
def __iter__(self): arrayts = StorageManager.get(self._id) return iter(arrayts)
def __getitem__(self, index): arrayts = StorageManager.get(self._id) return arrayts[index]
def times(self): arrayts = StorageManager.get(self._id) return arrayts.times()
def __setitem__(self, index, value): arrayts = StorageManager.get(self._id) arrayts[index] = value StorageManager.store(self._id, arrayts)
def __sub__(self, otherTS): arrayts1 = StorageManager.get(self._id) arrayts2 = StorageManager.get(otherTS._id) arraydiff = arrayts1 - arrayts2 return SMTimeSeries(arraydiff.times(), arraydiff.values())