Browse Source

Add nilm-decimate test, and fix support for int64 types

tags/nilmtools-2.0.0
Jim Paris 1 year ago
parent
commit
d8df408ce1
2 changed files with 71 additions and 1 deletions
  1. +3
    -1
      nilmtools/decimate.py
  2. +68
    -0
      tests/test.py

+ 3
- 1
nilmtools/decimate.py View File

@@ -24,7 +24,9 @@ def main(argv = None):
print("Destination %s doesn't exist" % (dest.path))
if "decimate_source" in f.client_src.stream_get_metadata(src.path):
rec = src.layout
elif 'int32' in src.layout_type or 'float64' in src.layout_type:
elif ('int32' in src.layout_type or
'int64' in src.layout_type or
'float64' in src.layout_type):
rec = 'float64_' + str(src.layout_count * 3)
else:
rec = 'float32_' + str(src.layout_count * 3)


+ 68
- 0
tests/test.py View File

@@ -268,6 +268,74 @@ class TestAllCommands(CommandTester):
def test_03_decimate(self):
self.main = nilmtools.decimate.main

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

# basic arguments
self.fail(f"")

# no dest
self.fail(f"/newton/prep /newton/prep-decimated-1")
self.contain("doesn't exist")

# wrong dest shape
client.stream_create("/newton/prep-decimated-bad", "float32_8")
self.fail(f"/newton/prep /newton/prep-decimated-bad")
self.contain("wrong number of fields")

# bad factor
self.fail(f"/newton/prep -f 1 /newton/prep-decimated-bad")
self.contain("needs to be 2 or more")

# ok, default factor 4
client.stream_create("/newton/prep-decimated-4", "float32_24")
self.ok(f"/newton/prep /newton/prep-decimated-4")
a = client.stream_count("/newton/prep")
b = client.stream_count("/newton/prep-decimated-4")
eq_(a // 4, b)

# factor 10
client.stream_create("/newton/prep-decimated-10", "float32_24")
self.ok(f"/newton/prep -f 10 /newton/prep-decimated-10")
self.contain("Processing")
a = client.stream_count("/newton/prep")
b = client.stream_count("/newton/prep-decimated-10")
eq_(a // 10, b)

# different factor, same target
self.fail(f"/newton/prep -f 16 /newton/prep-decimated-10")
self.contain("Metadata in destination stream")
self.contain("decimate_factor = 10")
self.contain("doesn't match desired data")
self.contain("decimate_factor = 16")

# unless we force it
self.ok(f"/newton/prep -f 16 -F /newton/prep-decimated-10")
a = client.stream_count("/newton/prep")
b = client.stream_count("/newton/prep-decimated-10")
# but all data was already converted, so no more
eq_(a // 10, b)

# if we try to decimate an already-decimated stream, the suggested
# shape is different
self.fail(f"/newton/prep-decimated-4 -f 4 /newton/prep-decimated-16")
self.contain("create /newton/prep-decimated-16 float32_24")

# decimate again
client.stream_create("/newton/prep-decimated-16", "float32_24")
self.ok(f"/newton/prep-decimated-4 -f 4 /newton/prep-decimated-16")
self.contain("Processing")

# check shape suggestion for different input types
for (shape, expected) in (("int32_1", "float64_3"),
("uint32_1", "float64_3"),
("int64_1", "float64_3"),
("uint64_1", "float64_3"),
("float32_1", "float32_3"),
("float64_1", "float64_3")):
client.stream_create(f"/test/{shape}", shape)
self.fail(f"/test/{shape} /test/{shape}-decim")
self.contain(f"create /test/{shape}-decim {expected}")

def test_04_decimate_auto(self):
self.main = nilmtools.decimate_auto.main



Loading…
Cancel
Save