Пример #1
0
  def get_tick_prior(self, val):
  # {{{
    ''' get_tick_prior(val) - returns the date of the first tick prior to the
    date represented by val. If a tick lies on val, it returns the date of the
    previous tick.'''

    def unpack(dt): return dt.get('year', 1), dt.get('month', 1), dt.get('day', 1), dt.get('hour', 0), dt.get('minute', 0), dt.get('second', 0)
    def pack(yr, mn, dy, hr, mi, sc): return {'year':yr, 'month':mn, 'day':dy, 'hour':hr, 'minute':mi, 'second':sc}

    dt = self._taxis.val_as_date(val, allfields=True)
    yr, mn, dy, hr, mi, sc = unpack(dt)

    if val > self._taxis.date_as_val(pack(yr, mn, dy, hr, mi, sc)): 
      yr, mn, dy, hr, mi, sc = unpack(tu.wrapdate(self._taxis, pack(yr, mn, dy, hr, mi, sc+1), allfields=True))

    # Find first hour on given multiple prior to the given hour
    from numpy import floor_divide
    sc = floor_divide(sc - 1, self.mult) * self.mult

    # If we've wrapped, decrement the year
    d = tu.wrapdate(self._taxis, pack(yr, mn, dy, hr, mi, sc), allfields=True)
    d1 = tu.wrapdate(self._taxis, pack(yr, mn, dy, hr, mi+1, 0), allfields=True)

    if tu.date_diff(self._taxis, d, d1, 'seconds') < self.mult / 2:
      return d1
    else:
      return d
Пример #2
0
    def get_tick_prior(self, val):
        # {{{
        ''' get_tick_prior(val) - returns the date of the first tick prior to the
    date represented by val. If a tick lies on val, it returns the date of the
    previous tick.'''
        def unpack(dt):
            return dt.get('year', 1), dt.get('month',
                                             1), dt.get('day',
                                                        1), dt.get('hour', 0)

        def pack(yr, mn, dy, hr):
            return {'year': yr, 'month': mn, 'day': dy, 'hour': hr}

        dt = self._taxis.val_as_date(val, allfields=True)
        yr, mn, dy, hr = unpack(dt)

        if val > self._taxis.date_as_val(pack(yr, mn, dy, hr)):
            yr, mn, dy, hr = unpack(
                tu.wrapdate(self._taxis,
                            pack(yr, mn, dy, hr + 1),
                            allfields=True))

        # Find first hour on given multiple prior to the given hour
        from numpy import floor_divide
        hr = floor_divide(hr - 1, self.mult) * self.mult

        # If we've wrapped, decrement the year
        d = tu.wrapdate(self._taxis, pack(yr, mn, dy, hr), allfields=True)
        d1 = tu.wrapdate(self._taxis, pack(yr, mn, dy + 1, 0), allfields=True)

        if tu.date_diff(self._taxis, d, d1, 'hours') < self.mult / 2:
            return d1
        else:
            return d
Пример #3
0
  def get_tick_prior(self, val):
  # {{{
    ''' get_tick_prior(val) - returns the date of the first tick prior to the
    date represented by val. If a tick lies on val, it returns the date of the
    previous tick.'''

    def unpack(dt): return dt.get('year', 1), dt.get('month', 1), dt.get('day', 1)

    dt = self._taxis.val_as_date(val, allfields=True)
    yr, mn, dy = unpack(dt)

    if val > self._taxis.date_as_val({'year':yr, 'month':mn, 'day':dy}): 
      yr, mn, dy = unpack(tu.wrapdate(self._taxis, {'year':yr, 'month':mn, 'day':dy+1}, allfields=True))

    # Find first day on given multiple prior to the given day
    from numpy import floor_divide
    dy = floor_divide(dy - 2, self.mult) * self.mult + 1

    # If we've wrapped, decrement the year
    d = tu.wrapdate(self._taxis, {'year':yr, 'month':mn, 'day':dy}, allfields=True)
    d1 = tu.wrapdate(self._taxis, {'year':yr, 'month':mn + 1, 'day':1}, allfields=True)

    if tu.date_diff(self._taxis, d, d1, 'days') < self.mult / 2:
      return d1
    else:
      return d
Пример #4
0
    def get_tick_prior(self, val):
        # {{{
        ''' get_tick_prior(val) - returns the date of the first tick prior to the
    date represented by val. If a tick lies on val, it returns the date of the
    previous tick. The date is in the form of a dictionary with 'year' and
    'season' fields.'''

        dt = self._taxis.val_as_date(val, allfields=True)
        yr = dt.get('year', 1)
        sn = dt.get('season', 1)
        if val > self._taxis.date_as_val({'year': yr, 'season': sn}):
            dt = tu.wrapdate(self._taxis, {
                'year': yr,
                'month': sn + 1
            },
                             allfields=True)
            yr = dt.get('year', 1)
            sn = dt.get('season', 1)

        # Find first month on given multiple prior to the given month
        from numpy import floor_divide
        sn = floor_divide(sn - 2, self.mult) * self.mult + 1

        return tu.wrapdate(self._taxis, {
            'year': yr,
            'season': sn
        },
                           allfields=True)
Пример #5
0
    def get_tick_prior(self, val):
        # {{{
        ''' get_tick_prior(val) - returns the date of the first tick prior to the
    date represented by val. If a tick lies on val, it returns the date of the
    previous tick.'''
        def unpack(dt):
            return dt.get('year', 1), dt.get('month', 1), dt.get('day', 1)

        dt = self._taxis.val_as_date(val, allfields=True)
        yr, mn, dy = unpack(dt)

        if val > self._taxis.date_as_val({'year': yr, 'month': mn, 'day': dy}):
            yr, mn, dy = unpack(
                tu.wrapdate(self._taxis, {
                    'year': yr,
                    'month': mn,
                    'day': dy + 1
                },
                            allfields=True))

        # Find first day on given multiple prior to the given day
        from numpy import floor_divide
        dy = floor_divide(dy - 2, self.mult) * self.mult + 1

        # If we've wrapped, decrement the year
        d = tu.wrapdate(self._taxis, {
            'year': yr,
            'month': mn,
            'day': dy
        },
                        allfields=True)
        d1 = tu.wrapdate(self._taxis, {
            'year': yr,
            'month': mn + 1,
            'day': 1
        },
                         allfields=True)

        if tu.date_diff(self._taxis, d, d1, 'days') < self.mult / 2:
            return d1
        else:
            return d
Пример #6
0
  def get_tick_prior(self, val):
  # {{{
    ''' get_tick_prior(val) - returns the date of the first tick prior to the
    date represented by val. If a tick lies on val, it returns the date of the
    previous tick. The date is in the form of a dictionary with 'year' and
    'season' fields.'''

    dt = self._taxis.val_as_date(val, allfields=True)
    yr = dt.get('year', 1)
    sn = dt.get('season', 1)
    if val > self._taxis.date_as_val({'year':yr, 'season':sn}): 
      dt = tu.wrapdate(self._taxis, {'year':yr, 'month':sn+1}, allfields=True)
      yr = dt.get('year', 1)
      sn = dt.get('season', 1)

    # Find first month on given multiple prior to the given month
    from numpy import floor_divide
    sn = floor_divide(sn - 2, self.mult) * self.mult + 1

    return tu.wrapdate(self._taxis, {'year':yr, 'season':sn}, allfields=True)
Пример #7
0
 def wrapdate(self, dt, allfields=False):
   from pygeode import timeutils
   from warnings import warn
   warn ("Deprecated.  Use timeutils module.")
   return timeutils.wrapdate(self, dt, allfields)
Пример #8
0
 def wrapdate(self, dt, allfields=False):
   from pygeode import timeutils
   from warnings import warn
   warn ("Deprecated.  Use timeutils module.")
   return timeutils.wrapdate(self, dt, allfields)