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.
 
 
 
 

67 lines
2.4 KiB

  1. #!/usr/bin/python
  2. import nilmdb.client
  3. from nilmdb.utils.printf import *
  4. from nilmdb.utils.time import parse_time, format_time
  5. import time
  6. import sys
  7. import re
  8. import argparse
  9. class Filter(object):
  10. def __init__(self, description = "Filter data"):
  11. self.args = None
  12. self._client = None
  13. self.parse_args(description)
  14. def parse_args(self, description):
  15. parser = argparse.ArgumentParser(
  16. description = description,
  17. formatter_class = argparse.RawDescriptionHelpFormatter)
  18. parser.add_argument("-u", "--url", action="store",
  19. default="http://localhost:12380/",
  20. help="Server URL (default: %(default)s)")
  21. parser.add_argument("srcpath", action="store",
  22. help="Path of source stream, e.g. /foo/bar")
  23. parser.add_argument("destpath", action="store",
  24. help="Path of destination stream, e.g. /foo/bar")
  25. self.args = parser.parse_args()
  26. self._client = nilmdb.client.Client(args.url)
  27. if args.srcpath == args.destpath:
  28. raise Exception("source and destination path must be different")
  29. # Open and print info about the streams
  30. def stream_info_string(info):
  31. return sprintf("%s (%s), %.2fM rows, %.2f hours\n",
  32. info[0], info[1], info[4] / 1e6, info[5] / 3600)
  33. src = self._client.stream_list(args.srcpath, extended = True)
  34. if len(src) != 1:
  35. raise Exception("source path " + args.srcpath + " not found")
  36. print "Source:", stream_info_string(src[0])
  37. dest = self._client.stream_list(args.destpath, extended = True)
  38. if len(dest) != 1:
  39. raise Exception("destination path " + args.destpath + " not found")
  40. print " Dest:", stream_info_string(dest[0])
  41. def intervals(self):
  42. """Generate all the intervals that this filter should process"""
  43. for i in self._client.stream_intervals(
  44. args.srcpath, diffpath = args.destpath):
  45. yield i
  46. def main():
  47. # This is just a dummy function; actual filters can use the other
  48. # functions to prepare stuff, and then do something with the data.
  49. f = Filter()
  50. for interval in f.intervals():
  51. print "Generic filter: need to handle interval:", interval
  52. if __name__ == "__main__":
  53. main()