diff --git a/nilmdb/fileinterval.py b/nilmdb/fileinterval.py index af016a7..a3082a6 100644 --- a/nilmdb/fileinterval.py +++ b/nilmdb/fileinterval.py @@ -9,6 +9,24 @@ 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): + + 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 diff --git a/nilmdb/interval.py b/nilmdb/interval.py index 3262b90..ccfb26c 100644 --- a/nilmdb/interval.py +++ b/nilmdb/interval.py @@ -12,6 +12,9 @@ class IntervalError(Exception): class Interval(object): """Represents an interval of time""" + start = None + end = None + def __init__(self, start, end): self.start = start self.end = end @@ -22,9 +25,6 @@ class Interval(object): def __str__(self): return "[" + str(self.start) + " -> " + str(self.end) + "]" - def __getattr__(self, name): - return { } - def __setattr__(self, name, value): """Set attribute""" # TODO: If we need to manipulate file names, offsets, lengths, etc, diff --git a/nilmdb/test_fileinterval.py b/nilmdb/test_fileinterval.py index 3069f86..25ded45 100644 --- a/nilmdb/test_fileinterval.py +++ b/nilmdb/test_fileinterval.py @@ -12,10 +12,10 @@ def fiset(string): if (c == "["): start = day elif (c == "|"): - iset += FileInterval(start, day) + iset += FileInterval(start, day, "test.dat") start = day elif (c == "]"): - iset += FileInterval(start, day) + iset += FileInterval(start, day, "test.dat") del start return iset