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.2 KiB

  1. #!/usr/bin/python
  2. import nilmtools.filter
  3. import nilmdb.client
  4. import numpy as np
  5. import sys
  6. def main():
  7. f = nilmtools.filter.Filter()
  8. parser = f.setup_parser("Copy a stream")
  9. # Parse arguments
  10. try:
  11. args = f.parse_args()
  12. except nilmtools.filter.MissingDestination as e:
  13. print "Source is %s (%s)" % (e.src.path, e.src.layout)
  14. print "Destination %s doesn't exist" % (e.dest.path)
  15. print "You could make it with a command like:"
  16. print " nilmtool -u %s create %s %s" % (e.dest.url,
  17. e.dest.path, e.src.layout)
  18. raise SystemExit(1)
  19. # Copy metadata
  20. meta = f.client_src.stream_get_metadata(f.src.path)
  21. f.check_dest_metadata(meta)
  22. # Copy all rows of data as ASCII strings
  23. extractor = nilmdb.client.Client(f.src.url).stream_extract
  24. inserter = nilmdb.client.Client(f.dest.url).stream_insert_context
  25. for i in f.intervals():
  26. print "Processing", f.interval_string(i)
  27. with inserter(f.dest.path, i.start, i.end) as insert_ctx:
  28. for row in extractor(f.src.path, i.start, i.end):
  29. insert_ctx.insert(row + "\n")
  30. if __name__ == "__main__":
  31. main()