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. group = parser.add_argument_group("Copy options")
  10. # Parse arguments
  11. try:
  12. args = f.parse_args()
  13. except nilmtools.filter.MissingDestination as e:
  14. print "Source is %s (%s)" % (e.src, e.layout)
  15. print "Destination %s doesn't exist" % (e.dest)
  16. print "You could make it with a command like:"
  17. print " nilmtool create", e.dest, e.layout
  18. raise SystemExit(1)
  19. # Copy metadata
  20. meta = f.client.stream_get_metadata(args.srcpath)
  21. f.check_dest_metadata(meta)
  22. # Copy all rows of data as ASCII strings
  23. extractor = nilmdb.client.Client(args.url).stream_extract
  24. inserter = nilmdb.client.Client(args.url).stream_insert_context
  25. for (start, end) in f.intervals():
  26. print "Processing", f.interval_string((start, end))
  27. with inserter(args.destpath, start, end) as insert_ctx:
  28. for row in extractor(args.srcpath, start, end):
  29. insert_ctx.insert(row + "\n")
  30. if __name__ == "__main__":
  31. main()