You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

38 lines
1.1 KiB

  1. """FileInterval
  2. An Interval that is backed with file data storage"""
  3. from nilmdb.interval import Interval, IntervalSet, IntervalError
  4. from datetime import datetime
  5. import bisect
  6. class FileInterval(Interval):
  7. """Represents an interval of time and its corresponding data"""
  8. def __init__(self, start, end,
  9. filename,
  10. start_offset = None, end_offset = None):
  11. self.start = start
  12. self.end = end
  13. self.filename = filename
  14. if start_offset is None:
  15. start_offset = 0
  16. self.start_offset = start_offset
  17. if end_offset is None:
  18. f = open(filename, 'rb')
  19. f.seek(0, os.SEEK_END)
  20. end_offset = f.tell()
  21. self.end_offset = end_offset
  22. def __setattr__(self, name, value):
  23. pass
  24. def subset(self, start, end):
  25. """Return a new Interval that is a subset of this one"""
  26. # TODO: Any magic regarding file/offset/length mapping for subsets
  27. if (start < self.start or end > self.end):
  28. raise IntervalError("not a subset")
  29. return FileInterval(start, end)