masters-thesis/plots/Makefile

45 lines
1.8 KiB
Makefile
Raw Normal View History

# IPYNB to PY
IPYNBS = $(wildcard *.ipynb)
PYS = $(patsubst %.ipynb, %.py, $(IPYNBS))
# CSV to PDF
HIST_DIRS = $(wildcard *_hist/)
HIST_PDFS := $(foreach dir, $(HIST_DIRS), $(dir)legend.pdf)
MEDIAN_DIRS = $(wildcard *_median/)
MEDIAN_PDFS := $(foreach dir, $(MEDIAN_DIRS), $(dir)legend.pdf)
NODETYPE_DIRS = $(wildcard nodetype_*/)
NODETYPE_PDFS := $(foreach dir, $(NODETYPE_DIRS), $(dir)*legend.pdf)
all: $(PYS) $(HIST_PDFS) $(MEDIAN_PDFS) $(NODETYPE_PDFS)
%.py: %.ipynb
jupyter nbconvert --to script $<
chmod u+x $@
.SECONDEXPANSION:
$(HIST_PDFS): $$(wildcard $$(dir $$@)test*/*.csv) $$(wildcard $$(dir $$@)*.json) plot_histograms.py
./plot_histograms.py $(word 1,$(subst /, ,$@))
$(MEDIAN_PDFS): $$(wildcard $$(dir $$@)test*/shift_*/*.csv) $$(wildcard $$(dir $$@)*.json) plot_medians.py
./plot_medians.py $(word 1,$(subst /, ,$@))
$(NODETYPE_PDFS): $$(wildcard $$(dir $$@)*/*.csv) $$(wildcard $$(dir $$@)*.json) plot_nodetypes.py
# This rather lengthy expression is necessary to make sure we clean up our csv files, but do not break
# them in case they were already cleand up
#
# It is not possible to put everything in one line without bash complaining about the ARG limit. The ARG
# limit is also the reason the second line is very "compact". Do not remove the second awk statement that
# looks for #s. Since symbolic links are allowed, files will _always_ be touched.
#
$(foreach f, $(subst \ , ,$^), if [[ "$(f)" == *".csv" && "$$(head -1 $(f) | awk -F\, '{print NF-1}')" -gt "1" ]]; then cut -d, -f3,4 $(f) > temp && mv temp $(f); fi;)
$(foreach f, $(subst \ , ,$^), if [[ "$(f)" == *"sv" && "$$(head -1 $(f)|awk -F\# '{print NF-1}')" -eq "0" ]]; then sed '0,/offs/s/^offs/#offs/' $(f) > t && mv t $(f); fi;)
./plot_nodetypes.py $(word 1,$(subst /, ,$@))
clean:
rm -f *.py
rm -f */*.pdf
.PHONY: clean