Browse Source

Add nilm-decimate-auto test

tags/nilmtools-2.0.0
Jim Paris 1 year ago
parent
commit
0fa46c09a9
2 changed files with 34 additions and 3 deletions
  1. +9
    -3
      nilmtools/decimate_auto.py
  2. +25
    -0
      tests/test.py

+ 9
- 3
nilmtools/decimate_auto.py View File

@@ -27,7 +27,7 @@ def main(argv = None):
help='Maximum number of points in last level ' +
'(default: %(default)s)')
parser.add_argument("-F", "--force-metadata", action="store_true",
default = False,
default=False,
help="Force metadata changes if the dest "
"doesn't match")
parser.add_argument("-v", "--version", action="version",
@@ -36,6 +36,10 @@ def main(argv = None):
help='Path of base stream')
args = parser.parse_args(argv)

if args.max < 0:
print("error: bad max, must be nonnegative")
raise SystemExit(1)

# Pull out info about the base stream
client = nilmdb.client.Client(args.url)

@@ -56,7 +60,7 @@ def main(argv = None):
def do_decimation(client, args, path):
print("Decimating", path)
info = nilmtools.filter.get_stream_info(client, path)
if not info:
if not info: # pragma: no cover (only good paths passed above)
raise Exception("path " + path + " not found")

meta = client.stream_get_metadata(path)
@@ -66,7 +70,9 @@ def do_decimation(client, args, path):
raise SystemExit(1)

# Figure out the type we should use for decimated streams
if 'int32' in info.layout_type or 'float64' in info.layout_type:
if ('int32' in info.layout_type or
'int64' in info.layout_type or
'float64' in info.layout_type):
decimated_type = 'float64_' + str(info.layout_count * 3)
else:
decimated_type = 'float32_' + str(info.layout_count * 3)


+ 25
- 0
tests/test.py View File

@@ -339,6 +339,31 @@ class TestAllCommands(CommandTester):
def test_04_decimate_auto(self):
self.main = nilmtools.decimate_auto.main

client = nilmdb.client.Client(url=self.url)

self.fail(f"")

self.fail(f"--max -1 asdf")
self.contain("bad max")

self.fail(f"/no/such/stream")
self.contain("no stream matched path")

# normal run
self.ok(f"/newton/prep")

# can't auto decimate a decimated stream
self.fail(f"/newton/prep-decimated-16")
self.contain("need to pass the base stream instead")

# decimate prep again, this time much more; also use -F
self.ok(f"-m 10 --force-metadata /newton/pr??")
self.contain("Level 4096 decimation has 9 rows")

# decimate the different shapes
self.ok(f"/test/*")
self.contain("Level 1 decimation has 0 rows")

def test_05_insert(self):
self.main = nilmtools.insert.main



Loading…
Cancel
Save