Browse Source

Consolidate timestamp constants into nilmdb.utils.time

tags/nilmdb-1.4.0
Jim Paris 11 years ago
parent
commit
e6a081d639
6 changed files with 16 additions and 9 deletions
  1. +1
    -4
      nilmdb/client/client.py
  2. +1
    -1
      nilmdb/server/bulkdata.py
  3. +4
    -1
      nilmdb/server/interval.pyx
  4. +4
    -1
      nilmdb/server/layout.pyx
  5. +2
    -2
      nilmdb/server/nilmdb.py
  6. +4
    -0
      nilmdb/utils/time.py

+ 1
- 4
nilmdb/client/client.py View File

@@ -238,9 +238,6 @@ class StreamInserter(object):
_max_data = 2 * 1024 * 1024 _max_data = 2 * 1024 * 1024
_max_data_after_send = 64 * 1024 _max_data_after_send = 64 * 1024


# Delta to add to the final timestamp, if "end" wasn't given
_end_epsilon = 1e-6

def __init__(self, http, path, start = None, end = None): def __init__(self, http, path, start = None, end = None):
"""'http' is the httpclient object. 'path' is the database """'http' is the httpclient object. 'path' is the database
path to insert to. 'start' and 'end' are used for the first path to insert to. 'start' and 'end' are used for the first
@@ -364,7 +361,7 @@ class StreamInserter(object):
if end_ts is None: if end_ts is None:
(spos, epos) = self._get_last_noncomment(block) (spos, epos) = self._get_last_noncomment(block)
end_ts = extract_timestamp(block[spos:epos]) end_ts = extract_timestamp(block[spos:epos])
end_ts += self._end_epsilon
end_ts += nilmdb.utils.time.epsilon
except (ValueError, IndexError): except (ValueError, IndexError):
pass # no timestamp is OK, if we have no data pass # no timestamp is OK, if we have no data
self._block_data = [] self._block_data = []


+ 1
- 1
nilmdb/server/bulkdata.py View File

@@ -421,7 +421,7 @@ class Table(object):
the table is reverted back to its original state by truncating the table is reverted back to its original state by truncating
or deleting files as necessary.""" or deleting files as necessary."""
data_offset = 0 data_offset = 0
last_timestamp = -1e12
last_timestamp = nilmdb.utils.time.min_timestamp
tot_rows = self.nrows tot_rows = self.nrows
count = 0 count = 0
linenum = 0 linenum = 0


+ 4
- 1
nilmdb/server/interval.pyx View File

@@ -19,6 +19,8 @@ Intervals are half-open, ie. they include data points with timestamps
# Fourth version is an optimized rb-tree that stores interval starts # Fourth version is an optimized rb-tree that stores interval starts
# and ends directly in the tree, like bxinterval did. # and ends directly in the tree, like bxinterval did.


from ..utils.time import min_timestamp as nilmdb_min_timestamp
from ..utils.time import max_timestamp as nilmdb_max_timestamp
from ..utils.time import float_time_to_string as ftts from ..utils.time import float_time_to_string as ftts
from ..utils.iterator import imerge from ..utils.iterator import imerge
import itertools import itertools
@@ -331,7 +333,8 @@ cdef class IntervalSet:
yield i.start, key_start, i yield i.start, key_start, i
yield i.end, key_end, i yield i.end, key_end, i
if bounds is None: if bounds is None:
bounds = Interval(-1e12, 1e12)
bounds = Interval(nilmdb_min_timestamp,
nilmdb_max_timestamp)
self_iter = decorate(self.intersection(bounds), 0, 2) self_iter = decorate(self.intersection(bounds), 0, 2)
other_iter = decorate(other.intersection(bounds), 1, 3) other_iter = decorate(other.intersection(bounds), 1, 3)




+ 4
- 1
nilmdb/server/layout.pyx View File

@@ -5,6 +5,8 @@ import sys
import inspect import inspect
import cStringIO import cStringIO


from ..utils.time import min_timestamp as nilmdb_min_timestamp

cdef enum: cdef enum:
max_value_count = 64 max_value_count = 64


@@ -146,7 +148,8 @@ class Parser(object):
layout, into an internal data structure suitable for a layout, into an internal data structure suitable for a
pytables 'table.append(parser.data)'. pytables 'table.append(parser.data)'.
""" """
cdef double last_ts = -1e12, ts
cdef double last_ts = nilmdb_min_timestamp
cdef double ts
cdef int n = 0, i cdef int n = 0, i
cdef char *line cdef char *line




+ 2
- 2
nilmdb/server/nilmdb.py View File

@@ -135,9 +135,9 @@ class NilmDB(object):


def _check_user_times(self, start, end): def _check_user_times(self, start, end):
if start is None: if start is None:
start = -1e12
start = nilmdb.utils.time.min_timestamp
if end is None: if end is None:
end = 1e12
end = nilmdb.utils.time.max_timestamp
if start >= end: if start >= end:
raise NilmDBError("start must precede end") raise NilmDBError("start must precede end")
return (start, end) return (start, end)


+ 4
- 0
nilmdb/utils/time.py View File

@@ -1,6 +1,10 @@
from nilmdb.utils import datetime_tz from nilmdb.utils import datetime_tz
import re import re


min_timestamp = -1e12
max_timestamp = 1e12
epsilon = 1e-6 # smallest representable timestamp

def parse_time(toparse): def parse_time(toparse):
""" """
Parse a free-form time string and return a datetime_tz object. Parse a free-form time string and return a datetime_tz object.


Loading…
Cancel
Save