filelist = $$(ls -tr NS2345K_datapeak_filelist_*.txt.gz|tail -n1)
nc4list = $(basename $(filelist))_nc4files.txt
pdffn = disk_NS2345K_$$(date +%Y%m%d).pdf
tablefn = sizeTable_$(basename $(filelist))_$$(date +%Y%m%d).txt
www=/datalake/NS9039K/www/pgchiu/disk_usage/
default:
	echo make sync

#monthly: analysis mkpdf sync isnc4 analysis mkpdf sync

#weeklyana: analysis mkpdf upload users
weeklyana: analysis mkpdf users

#weekly: mkdb isnc4 analysis mkpdf upload
#weekly: mkdb isnc4 analysis mkpdf upload users
weekly: mkdb isnc4 analysis mkpdf users
#post: isnc4 analysis mkpdf upload users
post: isnc4 analysis mkpdf users

upload:
	cp -f latex/$(pdffn) $(www)
	cp latex/latest.pdf $(www)
	cp filelist_classfy.err.txt $(www)
	cp sizeTable.txt $(www)
	cp sizeTable.txt $(www)/$(tablefn)
	cp $$(ls -tr NS9039K_datalake_analysis_*.json|tail -n1)  $(www)
	~/exec/notify 'NS9039K datalake disk usage updated.'

de:
	## make a quick plot without netcdf4
	./filelist_classfy.py $(filelist)
	cd latex && make && cp main.pdf latest.pdf && cp main.pdf $(pdffn) && cd -
	cd latex && ~/exec/public latest.pdf
	cd latex && ~/exec/public $(pdffn)
	~/exec/public filelist_classfy.err.txt ## this is a script for uploading file to my server
	
	## make plot for netcdf4
	./is_nc4.py $(filelist) && mv $(filelist) $(nc4list)
	./filelist_classfy.py $(filelist)
	cd latex && make && cp main.pdf latest.pdf && cp main.pdf $(pdffn) && cd -
	cd latex && ~/exec/public latest.pdf
	cd latex && ~/exec/public $(pdffn)
	~/exec/public filelist_classfy.err.txt ## this is a script for uploading file to my server
	
analysis:
	zcat $(filelist) | python3 filelist_classfy.py
	##./filelist_classfy.py $(filelist)
	#time zcat $$(ls -tr NS9039K_filelist_*.txt.gz|tail -n1) | python3 filelist_classfy.py
mkpdf:
	cd latex && make clean pdf&& cp main.pdf latest.pdf && cp main.pdf $(pdffn) && cd -

sync: 
	cd latex && ~/exec/public latest.pdf
	cd latex && ~/exec/public $(pdffn)
	~/exec/public filelist_classfy.err.txt ## this is a script for uploading file to my server

isnc4:
	#time ./is_nc4.py $(filelist) ##&& mv $(filelist) $(nc4list)
	zcat $(filelist) | ./is_nc4.py ##&& mv $(filelist) $(nc4list)
	#echo | mail -s subject nirdtrd.isnc4.done@blc.at.tw

mkdb:
	time sh disk_usage_check.sh >& disk_usage_check.log

users:
	## analysis the sizeTables in www dir
	echo skip ts_users.sh
	#sh ts_user.sh $(filelist)
