|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #!/usr/bin/python
-
- import nilmdb.client
- from nilmdb.utils.printf import *
- from nilmdb.utils.time import parse_time, format_time
-
- import time
- import sys
- import re
- import argparse
-
- class Filter(object):
-
- def __init__(self, description = "Filter data"):
- self.args = None
- self._client = None
- self.parse_args(description)
-
- def parse_args(self, description):
- parser = argparse.ArgumentParser(
- description = description,
- formatter_class = argparse.RawDescriptionHelpFormatter)
- parser.add_argument("-u", "--url", action="store",
- default="http://localhost:12380/",
- help="Server URL (default: %(default)s)")
- parser.add_argument("srcpath", action="store",
- help="Path of source stream, e.g. /foo/bar")
- parser.add_argument("destpath", action="store",
- help="Path of destination stream, e.g. /foo/bar")
- self.args = parser.parse_args()
-
- self._client = nilmdb.client.Client(args.url)
-
- if args.srcpath == args.destpath:
- raise Exception("source and destination path must be different")
-
- # Open and print info about the streams
- def stream_info_string(info):
- return sprintf("%s (%s), %.2fM rows, %.2f hours\n",
- info[0], info[1], info[4] / 1e6, info[5] / 3600)
-
- src = self._client.stream_list(args.srcpath, extended = True)
- if len(src) != 1:
- raise Exception("source path " + args.srcpath + " not found")
- print "Source:", stream_info_string(src[0])
-
- dest = self._client.stream_list(args.destpath, extended = True)
- if len(dest) != 1:
- raise Exception("destination path " + args.destpath + " not found")
- print " Dest:", stream_info_string(dest[0])
-
- def intervals(self):
- """Generate all the intervals that this filter should process"""
- for i in self._client.stream_intervals(
- args.srcpath, diffpath = args.destpath):
- yield i
-
- def main():
- # This is just a dummy function; actual filters can use the other
- # functions to prepare stuff, and then do something with the data.
- f = Filter()
- for interval in f.intervals():
- print "Generic filter: need to handle interval:", interval
-
- if __name__ == "__main__":
- main()
|