SAMPLES = sample1 sample2 sample3 sample4 sample5 sample6 sample7 sample8 sample9 sample10 sample11 sample12 sample13 sample14 sample15 sample16 sample17 sample18 sample19 sample20
SAMPLING_INTERVALS = 100 200 300 400 500 600 700 800 900 1000
PRODUCT = $(foreach sample,$(SAMPLES),$(SAMPLING_INTERVALS:%=$(sample)_interval_%_ms_result.tsv))
RESULT = $(PRODUCT:%.tsv=%.log)

all: $(PRODUCT)

experiment: $(RESULT)

plot.tsv: $(SAMPLES:%=plot_%.tsv)
	paste $^ | cut -f 1,2,4,6 > $@

plot_sample%.tsv: $(SAMPLING_INTERVALS:%=plot_sample\%_%.tsv)
	cat $^ > $@

%.log: %.tsv
	../../build/hamoni --vector --c_polyhedron -f ./navigation_lha.dot -i $< > $@


%.cleaned.log: %.log
	awk '/time-point/' < $< | uniq > $@

define down-sample

plot_%_$1.tsv: %_interval_$1_ms_result.cleaned.log %_interval_$1_ms_result.tsv
	wc -l $$^ | xargs | awk -v name=$$@ '{printf "%d\t%f\n", $1, $$$$1/$$$$3}' > $$@

%_interval_$1_ms_result.tsv: ./%_raw_result.tsv
	head -n 15000 $$< | awk '!((NR-1)%$1)' > $$@

endef

$(foreach interval,$(SAMPLING_INTERVALS),$(eval $(call down-sample,$(interval))))


clean:
	$(RM) $(PRODUCT)

.PHONY: clean all
