Compare commits
2 Commits
nilmdb-1.1
...
nilmdb-1.1
Author | SHA1 | Date | |
---|---|---|---|
8125d9c840 | |||
ba55ad82f0 |
@@ -297,7 +297,7 @@ class Table(object):
|
|||||||
pickle.dump(fmt, f, 2)
|
pickle.dump(fmt, f, 2)
|
||||||
|
|
||||||
# Normal methods
|
# Normal methods
|
||||||
def __init__(self, root, initial_nrows):
|
def __init__(self, root, initial_nrows = 0):
|
||||||
"""'root' is the full OS path to the directory of this table"""
|
"""'root' is the full OS path to the directory of this table"""
|
||||||
self.root = root
|
self.root = root
|
||||||
self.initial_nrows = initial_nrows
|
self.initial_nrows = initial_nrows
|
||||||
|
@@ -23,7 +23,6 @@ from nilmdb.server.errors import NilmDBError, StreamError, OverlapError
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
import os
|
import os
|
||||||
import errno
|
import errno
|
||||||
import bisect
|
|
||||||
|
|
||||||
# Note about performance and transactions:
|
# Note about performance and transactions:
|
||||||
#
|
#
|
||||||
@@ -516,6 +515,17 @@ class NilmDB(object):
|
|||||||
# And that's all
|
# And that's all
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _bisect_left(self, a, x, lo, hi):
|
||||||
|
# Like bisect.bisect_left, but doesn't choke on large indices on
|
||||||
|
# 32-bit systems, like bisect's fast C implementation does.
|
||||||
|
while lo < hi:
|
||||||
|
mid = (lo + hi) / 2
|
||||||
|
if a[mid] < x:
|
||||||
|
lo = mid + 1
|
||||||
|
else:
|
||||||
|
hi = mid
|
||||||
|
return lo
|
||||||
|
|
||||||
def _find_start(self, table, dbinterval):
|
def _find_start(self, table, dbinterval):
|
||||||
"""
|
"""
|
||||||
Given a DBInterval, find the row in the database that
|
Given a DBInterval, find the row in the database that
|
||||||
@@ -526,10 +536,10 @@ class NilmDB(object):
|
|||||||
# Optimization for the common case where an interval wasn't truncated
|
# Optimization for the common case where an interval wasn't truncated
|
||||||
if dbinterval.start == dbinterval.db_start:
|
if dbinterval.start == dbinterval.db_start:
|
||||||
return dbinterval.db_startpos
|
return dbinterval.db_startpos
|
||||||
return bisect.bisect_left(table,
|
return self._bisect_left(table,
|
||||||
dbinterval.start,
|
dbinterval.start,
|
||||||
dbinterval.db_startpos,
|
dbinterval.db_startpos,
|
||||||
dbinterval.db_endpos)
|
dbinterval.db_endpos)
|
||||||
|
|
||||||
def _find_end(self, table, dbinterval):
|
def _find_end(self, table, dbinterval):
|
||||||
"""
|
"""
|
||||||
@@ -545,10 +555,10 @@ class NilmDB(object):
|
|||||||
# want to include the given timestamp in the results. This is
|
# want to include the given timestamp in the results. This is
|
||||||
# so a queries like 1:00 -> 2:00 and 2:00 -> 3:00 return
|
# so a queries like 1:00 -> 2:00 and 2:00 -> 3:00 return
|
||||||
# non-overlapping data.
|
# non-overlapping data.
|
||||||
return bisect.bisect_left(table,
|
return self._bisect_left(table,
|
||||||
dbinterval.end,
|
dbinterval.end,
|
||||||
dbinterval.db_startpos,
|
dbinterval.db_startpos,
|
||||||
dbinterval.db_endpos)
|
dbinterval.db_endpos)
|
||||||
|
|
||||||
def stream_extract(self, path, start = None, end = None,
|
def stream_extract(self, path, start = None, end = None,
|
||||||
count = False, markup = False, binary = False):
|
count = False, markup = False, binary = False):
|
||||||
|
Reference in New Issue
Block a user