Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 60 lines (44 sloc) 1.877 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
from stdnet import odm
from stdnet.utils import encoders, todatetime, todate, missing_intervals
from stdnet.apps.columnts import ColumnTSField

        
class TimeSeries(odm.StdModel):
    ticker = odm.SymbolField(unique = True)
    data = odm.TimeSeriesField()
    
    def todate(self, v):
        return todatetime(v)
    
    def dates(self):
        return self.data
    
    def items(self):
        return self.data.items()
    
    def __get_start(self):
        r = self.data.front()
        if r:
            return r[0]
    data_start = property(__get_start)
    
    def __get_end(self):
        r = self.data.back()
        if r:
            return r[0]
    data_end = property(__get_end)
    
    def size(self):
        '''number of dates in timeseries'''
        return self.data.size()
        
    def intervals(self, startdate, enddate, parseinterval = None):
        '''Given a ``startdate`` and an ``enddate`` dates, evaluate the date intervals
from which data is not available. It return a list of two-dimensional tuples
containing start and end date for the interval. The list could countain 0,1 or 2
tuples.'''
        return missing_intervals(startdate, enddate, self.data_start,
                                 self.data_end, dateconverter = self.todate,
                                 parseinterval = parseinterval)
    

class DateTimeSeries(TimeSeries):
    data = odm.TimeSeriesField(pickler = encoders.DateConverter())
    
    def todate(self, v):
        return todate(v)
    
    
class BigTimeSeries(DateTimeSeries):
    data = odm.TimeSeriesField(
                    pickler = encoders.DateConverter(),
                    value_pickler = encoders.PythonPickle())


class ColumnTimeSeries(odm.StdModel):
    ticker = odm.SymbolField(unique = True)
    data = ColumnTSField()
Something went wrong with that request. Please try again.