示例#1
0
 def make(self, date, data, raw = False):
     if date is None:
         self._date = None
         self._data = None
     else:
         self._date = asarray(date)
         data = asarray(data, np.double)
         if len(data.shape) == 1:
             data = data.reshape(len(data),1)
         self._data = data
示例#2
0
 def make(self, date, data, raw=False):
     if date is None:
         self._date = None
         self._data = None
     else:
         self._date = asarray(date)
         data = asarray(data, np.double)
         if len(data.shape) == 1:
             data = data.reshape(len(data), 1)
         self._data = data
示例#3
0
 def _rollingTest(self, func):
     # A rolling function calculation
     ts = self.getts(cols=2)
     rollfun = 'roll%s' % func
     # Calculate the rolling function for two different windows
     mts30 = getattr(ts, rollfun)(window=30, fallback=self.fallback)
     mts60 = getattr(ts, rollfun)(window=60, fallback=self.fallback)
     # Check that dimensions are OK
     self.assertEqual(len(mts30), len(ts) - 29)
     self.assertEqual(len(mts60), len(ts) - 59)
     self.assertEqual(mts30.count(), 2)
     self.assertEqual(mts60.count(), 2)
     values = ts.values()
     v30 = mts30.values()
     date = asarray(ts.dates())
     c = 0
     # Loop over the items of the shorter windows rolling function
     for dt, v in mts30.items():
         # Clone the timeseries for this particular window
         tst = ts.clone(date[c:c+30], values[c:c+30])
         self.assertEqual(dt, tst.end())
         # Get the rolling function applied to the whole timeseries clone
         tv = getattr(tst, func)()
         c += 1
         for a, b in zip(v, tv):
             self.assertAlmostEqual(a, b)
示例#4
0
 def _rollingTest(self, func):
     # A rolling function calculation
     ts = self.getts(cols=2)
     rollfun = 'roll%s' % func
     # Calculate the rolling function for two different windows
     mts30 = getattr(ts, rollfun)(window=30, fallback=self.fallback)
     mts60 = getattr(ts, rollfun)(window=60, fallback=self.fallback)
     # Check that dimensions are OK
     self.assertEqual(len(mts30), len(ts) - 29)
     self.assertEqual(len(mts60), len(ts) - 59)
     self.assertEqual(mts30.count(), 2)
     self.assertEqual(mts60.count(), 2)
     values = ts.values()
     v30 = mts30.values()
     date = asarray(ts.dates())
     c = 0
     # Loop over the items of the shorter windows rolling function
     for dt, v in mts30.items():
         # Clone the timeseries for this particular window
         tst = ts.clone(date[c:c + 30], values[c:c + 30])
         self.assertEqual(dt, tst.end())
         # Get the rolling function applied to the whole timeseries clone
         tv = getattr(tst, func)()
         c += 1
         for a, b in zip(v, tv):
             self.assertAlmostEqual(a, b)
示例#5
0
文件: tsnumpy.py 项目: arjunpmm/dynts
 def make(self, date, data, raw=False, **params):
     if date is not None:
         if not raw:
             c = self.dateinverse
             date = (c(d) for d in date)
         date = asarray(date)
     self.__skl = skiplist(date)
     if date is None or not len(date):
         self._date = None
         self._data = None
     else:
         self._date = date
         data = asarray(data, self._dtype)
         if len(data.shape) == 1:
             data = data.reshape(len(data),1)
         self._data = data
示例#6
0
def rollsingle(self,
               func,
               window=20,
               name=None,
               fallback=False,
               align='right',
               **kwargs):
    '''Efficient rolling window calculation for min, max type functions'''
    rname = 'roll_{0}'.format(func)
    if fallback:
        rfunc = getattr(lib.fallback, rname)
    else:
        rfunc = getattr(lib, rname, None)
        if not rfunc:
            rfunc = getattr(lib.fallback, rname)
    rolling = lambda serie: list(rfunc(serie, window))
    data = np.array([rolling(serie) for serie in self.series()])
    name = name or self.makename(func, window=window)
    dates = asarray(self.dates())
    desc = settings.desc
    if (align == 'right' and not desc) or desc:
        dates = dates[window - 1:]
    else:
        dates = dates[:-window + 1]
    return self.clone(dates, data.transpose(), name=name)
示例#7
0
    def median(self, fallback=False):
        '''Median values by series. A median value of a serie
is defined as the the numeric value separating the higher half,
from the lower half. It is therefore differnt from the :meth:`TimeSeries.mean` value.

The median of a finite list of numbers can be found by arranging all the
observations from lowest value to highest value and picking the middle one.

If there is an even number of observations, then there is no single middle value;
the median is then usually defined to be the mean of the two middle values'''
        return asarray(self.apply('median', fallback=fallback)[0])
示例#8
0
文件: base.py 项目: GunioRobot/dynts
    def median(self, fallback = False):
        '''Median values by series. A median value of a serie
is defined as the the numeric value separating the higher half,
from the lower half. It is therefore differnt from the :meth:`TimeSeries.mean` value.

The median of a finite list of numbers can be found by arranging all the
observations from lowest value to highest value and picking the middle one.

If there is an even number of observations, then there is no single middle value;
the median is then usually defined to be the mean of the two middle values'''
        return asarray(self.apply('median', fallback = fallback)[0])
示例#9
0
    def __call__(self,
                 ts,
                 container=None,
                 desc=False,
                 series_info=None,
                 **kwargs):
        '''Dump timeseries as a JSON string compatible with ``flot``'''
        from dynts.web import flot
        from dynts.conf import settings

        pydate2flot = flot.pydate2flot
        result = container or flot.MultiPlot()
        df = {}
        series_info = series_info or df
        if istimeseries(ts):
            res = flot.Flot(ts.name, type='timeseries', **series_info)
            dates = asarray(ts.dates())
            missing = settings.ismissing
            for name, serie in zip(ts.names(), ts.series()):
                info = series_info.get(name, df)
                data = []
                append = data.append
                for dt, val in zip(dates, serie):
                    if not missing(val):
                        append([pydate2flot(dt), val])
                serie = flot.Serie(label=name, data=data, **info)
                res.add(serie)
        else:
            res = flot.Flot(ts.name)
            if ts.extratype:
                for name, serie in zip(ts.names(), ts.series()):
                    serie = flot.Serie(label=serie.name,
                                       data=serie.data,
                                       lines={'show': serie.lines},
                                       points={'show': True},
                                       scatter={
                                           'show': serie.points,
                                           'extratype': ts.extratype
                                       })
                    res.add(serie)
            else:
                for name, serie in zip(ts.names(), ts.series()):
                    serie = flot.Serie(label=serie.name,
                                       data=serie.data,
                                       lines={'show': serie.lines},
                                       points={'show': serie.points})
                    res.add(serie)
        result.add(res)
        return result
示例#10
0
 def __call__(self, ts, container = None, desc = False,
              series_info = None, **kwargs):
     '''Dump timeseries as a JSON string compatible with ``flot``'''
     from dynts.web import flot
     from dynts.conf import settings
     
     pydate2flot = flot.pydate2flot
     result = container or flot.MultiPlot()
     df = {}
     series_info = series_info or df
     if istimeseries(ts):
         res = flot.Flot(ts.name, type = 'timeseries', **series_info)
         dates  = asarray(ts.dates())
         missing = settings.ismissing
         for name,serie in zip(ts.names(),ts.series()):
             info = series_info.get(name,df) 
             data = []
             append = data.append
             for dt,val in zip(dates,serie):
                 if not missing(val):
                     append([pydate2flot(dt),val])
             serie = flot.Serie(label = name, data = data, **info)
             res.add(serie)
     else:
         res = flot.Flot(ts.name)
         if ts.extratype:
             for name,serie in zip(ts.names(),ts.series()):
                 serie = flot.Serie(label = serie.name,
                                    data = serie.data,
                                    lines = {'show':serie.lines},
                                    points = {'show':True},
                                    scatter = {'show':serie.points,
                                               'extratype':ts.extratype})
                 res.add(serie)
         else:
             for name,serie in zip(ts.names(),ts.series()):
                 serie = flot.Serie(label = serie.name,
                                    data = serie.data,
                                    lines = {'show':serie.lines},
                                    points = {'show':serie.points})
                 res.add(serie)
     result.add(res)
     return result
示例#11
0
文件: tsnumpy.py 项目: OspreyX/dynts
def rollsingle(self, func, window = 20, name = None,
               fallback = False, align = 'right',
               **kwargs):
    '''Efficient rolling window calculation for min, max type functions'''
    rname = 'roll_{0}'.format(func)
    if fallback:
        rfunc = getattr(lib.fallback,rname)
    else:
        rfunc = getattr(lib,rname,None)
        if not rfunc:
            rfunc = getattr(lib.fallback,rname)
    rolling = lambda serie : list(rfunc(serie,window))
    data = np.array([rolling(serie) for serie in self.series()])
    name = name or self.makename(func,window=window)
    dates = asarray(self.dates())
    desc = settings.desc
    if (align == 'right' and not desc) or desc:
        dates = dates[window-1:]
    else:
        dates = dates[:-window+1]
    return self.clone(dates, data.transpose(), name = name)
示例#12
0
 def mean(self, fallback=False):
     '''Mean values by series'''
     return asarray(self.apply('mean', fallback=fallback)[0])
示例#13
0
 def min(self, fallback=False):
     '''Max values by series'''
     return asarray(self.apply('min', fallback=fallback)[0])
示例#14
0
文件: base.py 项目: GunioRobot/dynts
 def mean(self, fallback = False):
     '''Mean values by series'''
     return asarray(self.apply('mean', fallback = fallback)[0])
示例#15
0
文件: base.py 项目: GunioRobot/dynts
 def min(self, fallback = False):
     '''Max values by series'''
     return asarray(self.apply('min', fallback = fallback)[0])