Browse Source

Change table.get_timestamp to table.__getitem__

This lets us use simple indexing to get timestamps from the table,
which allows us to use 'bisect' directly without needing a proxy class.
tags/nilmdb-1.4.0
Jim Paris 11 years ago
parent
commit
a547ddbbba
2 changed files with 4 additions and 12 deletions
  1. +1
    -9
      nilmdb/server/bulkdata.py
  2. +3
    -3
      nilmdb/server/nilmdb.py

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

@@ -478,7 +478,7 @@ class Table(object):
row += count
return "".join(ret)

def get_timestamp(self, row):
def __getitem__(self, row):
"""Extract timestamps from a row, with table[n] notation."""
if (row is None or row < 0 or row >= self.nrows):
raise IndexError("Index out of range")
@@ -575,11 +575,3 @@ class Table(object):
self._remove_rows(subdir, filename, row_offset, row_offset + count)
remaining -= count
row += count

class TimestampOnlyTable(object):
"""Helper that lets us pass a Tables object into bisect, by
returning only the timestamp when a particular row is requested."""
def __init__(self, table):
self.table = table
def __getitem__(self, index):
return self.table.get_timestamp(index)

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

@@ -472,7 +472,7 @@ class NilmDB(object):
# Optimization for the common case where an interval wasn't truncated
if dbinterval.start == dbinterval.db_start:
return dbinterval.db_startpos
return bisect.bisect_left(bulkdata.TimestampOnlyTable(table),
return bisect.bisect_left(table,
dbinterval.start,
dbinterval.db_startpos,
dbinterval.db_endpos)
@@ -491,7 +491,7 @@ class NilmDB(object):
# 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
# non-overlapping data.
return bisect.bisect_left(bulkdata.TimestampOnlyTable(table),
return bisect.bisect_left(table,
dbinterval.end,
dbinterval.db_startpos,
dbinterval.db_endpos)
@@ -539,7 +539,7 @@ class NilmDB(object):
row_max = row_start + remaining
if row_max < row_end:
row_end = row_max
restart = table.get_timestamp(row_max)
restart = table[row_max]

# Gather these results up
result.append(table.get_data(row_start, row_end))


Loading…
Cancel
Save