|
- """FileInterval
-
- An Interval that is backed with file data storage"""
-
- from nilmdb.interval import Interval, IntervalSet, IntervalError
- from datetime import datetime
- import bisect
-
- class FileInterval(Interval):
- """Represents an interval of time and its corresponding data"""
-
- def __init__(self, start, end,
- filename,
- start_offset = None, end_offset = None):
- self.start = start
- self.end = end
- self.filename = filename
- if start_offset is None:
- start_offset = 0
- self.start_offset = start_offset
- if end_offset is None:
- f = open(filename, 'rb')
- f.seek(0, os.SEEK_END)
- end_offset = f.tell()
- self.end_offset = end_offset
-
- def __setattr__(self, name, value):
- pass
-
- def subset(self, start, end):
- """Return a new Interval that is a subset of this one"""
- # TODO: Any magic regarding file/offset/length mapping for subsets
- if (start < self.start or end > self.end):
- raise IntervalError("not a subset")
- return FileInterval(start, end)
-
-
|