#URL="http://bucket.mit.edu:8080/nilmdb"
URL="http://localhost/nilmdb"

all: test

test:
ifeq ($(INSIDE_EMACS), t)
	@make test_sinefit
else
	@echo 'No test suite for nilmtools.  Try "make install"'
endif

test_pipewatch:
	nilmtools/pipewatch.py -t 3 "seq 10 20" "seq 20 30"

test_trainola:
	-nilmtool -u http://bucket/nilmdb remove -s min -e max \
		/sharon/prep-a-matches
	nilmtools/trainola.py "$$(cat extras/trainola-test-param.js)"

test_trainola2:
	-nilmtool -u http://bucket/nilmdb remove -s min -e max \
		/sharon/prep-a-matches
	nilmtools/trainola.py "$$(cat extras/trainola-test-param-2.js)"

test_trainola3:
	-nilmtool -u "http://bucket/nilmdb" destroy -R /test/jim
	nilmtool -u "http://bucket/nilmdb" create /test/jim uint8_3
	nilmtools/trainola.py "$$(cat extras/trainola-test-param-3.js)"
	nilmtool -u "http://bucket/nilmdb" extract /test/jim -s min -e max

test_cleanup:
	nilmtools/cleanup.py -e extras/cleanup.cfg
	nilmtools/cleanup.py extras/cleanup.cfg

test_insert:
	nilmtools/insert.py --skip --file --dry-run /foo/bar ~/data/20130311T2100.prep1.gz ~/data/20130311T2100.prep1.gz ~/data/20130311T2200.prep1.gz

test_copy:
	nilmtools/copy_wildcard.py -U "http://nilmdb.com/bucket/" -D /lees*

/tmp/raw.dat:
	octave --eval 'fs = 8000;' \
	--eval 't = (0:fs*10)*2*pi*60/fs;' \
	--eval 'raw = transpose([sin(t); 0.3*sin(3*t)+sin(t)]);' \
	--eval 'save("-ascii","/tmp/raw.dat","raw");'

test_prep: /tmp/raw.dat
	-nilmtool destroy -R /test/raw
	-nilmtool destroy -R /test/sinefit
	-nilmtool destroy -R /test/prep
	nilmtool create /test/raw float32_2
	nilmtool create /test/sinefit float32_3
	nilmtool create /test/prep float32_8
	nilmtool insert -s '@0' -t -r 8000 /test/raw /tmp/raw.dat
	nilmtools/sinefit.py -a 0.5 -c 1 -s '@0' -e '@5000000' /test/raw /test/sinefit
	nilmtools/prep.py -c 2 /test/raw /test/sinefit /test/prep
	nilmtools/prep.py -c 2 /test/raw /test/sinefit /test/prep
	nilmtool extract -s min -e max /test/prep | head -20

test_sinefit:
	make install >/dev/null 2>&1
	-nilmtool destroy -R /test/sinefit
	nilmtool create /test/sinefit float32_3
	nilmtools/sinefit.py -c 5 -s '2013/03/25 09:11:00' \
	-e '2013/03/25 10:11:00' /sharon/raw /test/sinefit
	nilmtool extract -s min -e max /test/sinefit | head -20

test_decimate:
	-@nilmtool destroy /lees-compressor/no-leak/raw/4 || true
	-@nilmtool destroy /lees-compressor/no-leak/raw/16 || true
	-@nilmtool create /lees-compressor/no-leak/raw/4 float32_18 || true
	-@nilmtool create /lees-compressor/no-leak/raw/16 float32_18 || true
	time python nilmtools/decimate.py -s '2013-02-04 18:10:00' -e '2013-02-04 18:11:00' /lees-compressor/no-leak/raw/1 /lees-compressor/no-leak/raw/4
	python nilmtools/decimate.py -s '2013-02-04 18:10:00' -e '2013-02-04 18:11:00' /lees-compressor/no-leak/raw/4 /lees-compressor/no-leak/raw/16

version:
	python setup.py version

dist: sdist
sdist:
	python setup.py sdist

install:
	python setup.py install

develop:
	python setup.py develop

clean::
	find . -name '*pyc' | xargs rm -f
	rm -rf nilmtools.egg-info/ build/ MANIFEST.in

gitclean::
	git clean -dXf

.PHONY: all version dist sdist install clean gitclean test
