Last active
May 1, 2024 07:34
-
-
Save jul/9c3fb387e06a832815cb5de8685217bc to your computer and use it in GitHub Desktop.
makefile for reciprocal.moving.poi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
declare -a action; | |
DEBUG=1 | |
RD='\e[31m' | |
GB='\e[33m' | |
BL='\e[34m' | |
GR='\e[0;90m\e[1;47m' | |
RZ='\e[0m' | |
TEMPLATE=${TEMPLATE:-template.dot} | |
DATE=${DATE:-2016-01-01} | |
ORIG=${ORIG:-out/rec.$DATE.dot} | |
MOVIE=${MOVIE:-output2.mp4} | |
BY_DAYS=${BY_DAYS:-40} | |
FORCE=${FORCE:-YES} | |
DOT=${DOT:-sfdp -x -Goverlap=scale} | |
MSPEED=${MSPEED:-1} | |
SHOW=${SHOW:-} | |
EDGE_SCALE=${EDGE_SCALE:-4} | |
MIN_MAIL=${MIN_MAIL:-5} | |
MAX_MAIL=${MAX_MAIL:-10000} | |
END_DATE=${END_DATE:-2017-04-01} | |
PERS_EDGE_SCALE=${PERS_EDGE_SCALE:-1} | |
THRESHOLD_ILOT=${THRESHOLD_ILOT:-2} | |
echo -e "${GB}REPRODUCIBLE BUILD WITH" | |
echo -e "-----------------------$RZ" | |
echo | |
for var in DEBUG PERS_EDGE_SCALE THRESHOLD_ILOT MOVIE \ | |
BY_DAYS FORCE DOT MSPEED \ | |
SHOW EDGE_SCALE MIN_MAIL MAX_MAIL DATE END_DATE ; | |
do | |
printf "%s='%s' " "$var" "$( eval eval echo \\$\$var)" | |
done | |
echo -n $@ | |
echo | |
echo | |
d() { | |
[ ! -z "$DEBUG" ] && echo -e "DEBUG:$(date +"%H:%M:%S"):$GR $* $RZ" | |
} | |
[ -d out ] || mkdir out | |
d "checking depency in python" | |
python3 -c 'import archery' || python3 -mpip install archery | |
NB_CORE=$(getconf _NPROCESSORS_ONLN) | |
function pwait() { | |
local nb_core=${1:-$NB_CORE} | |
while [ $(jobs -p | wc -l) -ge $nb_core ]; do | |
sleep 1 | |
done | |
} | |
push() { | |
local stack | |
declare -a stack | |
stack=( "$@" ) | |
for ((i=${#@}; i--; i)); do | |
action=( "${stack[$i]}" "${action[@]}" ); | |
done | |
} | |
e() { | |
local EX="$1" | |
shift | |
echo -e "${RD}${*}${RZ}" | |
exit $EX | |
} | |
w() { | |
echo LAST CHANCE TO MAKE CTRL+C | |
echo -e "$RD $* $RZ " | |
[ -z "$FORCE" ] && read -r a | |
echo $a | |
} | |
set +x | |
dispatch_action() { | |
while [[ ${#action} -gt 0 ]]; do | |
# pop in shell :D | |
act=${action[0]} | |
action=("${action[@]:1}") | |
# end of pop | |
d "DISPATCHING $act" | |
case $act in | |
all) | |
d all bells and whistles | |
push "very_clean" "movie"; dispatch_action | |
;; | |
backbone) | |
w "destroys $ORIG are you sure?" | |
d creating template by running reciprocal.moving.poi over a LOOONG TIME | |
EDGE_SCALE=$PERS_EDGE_SCALE TEMPLATE="" BY_DAYS=900 DATE=$DATE ./reciprocal.moving.poi.py # create $ORIG default | |
d "template is $( wc -l $TEMPLATE ) lines long" | |
d "TIP : above 1000l if still_images is too long try DOT='sfdp -x -Goverlap=scale' " | |
cp "$ORIG" "$TEMPLATE" | |
# TEMPLATE = "" => creating templates ;) | |
d "creating python templates with perl oneliners (lol)" | |
perl -i.back -pe "s/\{/{{/g" "$TEMPLATE" | |
perl -i -pe "s/\}/}}/g" "$TEMPLATE" | |
perl -i -pe ' s/("[^"]+") \-\- ("[^"]+") \[color=(\w+) penwidth=\S+/\1 -- \2 [color={wl((\1,\2)) or "lightblue" } penwidth={final.get((\1, \2),.5)*EDGE_SCALE}/' "$TEMPLATE" | |
d creating persitent views | |
$DOT -Tjpg "$ORIG" > out/persistent.jpg | |
$DOT -Tpng "$ORIG" > out/persistent.png | |
$DOT -Tsvg "$ORIG" > out/persistent.svg | |
$DOT -Tpdf "$ORIG" > out/persistent.pdf && ( [ -z $SHOW ] || firefox ./out/persistent.pdf &) | |
;; | |
muscle) | |
[ -f "$ORIG" ] || (push "backbone"; dispatch_action ) | |
d creating all the dot files | |
declare -a pids; | |
pids=() | |
echo $DATE | |
curd="$DATE" | |
enddate="$END_DATE" | |
interval=$( echo $(( $BY_DAYS / 2 )) ) | |
while [[ "$(date -d $curd +%Y%m%d)" < "$(date -d "$enddate" +%Y%m%d)" ]]; do | |
end=$( date -I -d "$curd + $interval day" ) | |
EDGE_SCALE=$EDGE_SCALE MIN_MAIL="$MIN_MAIL" MAX_MAIL="$MAX_MAIL" NB="$NB" DATE="$curd" END_DATE="$end" TEMPLATE="$TEMPLATE" BY_DAYS="$BY_DAYS" ./reciprocal.moving.poi.py & | |
echo -n . | |
ppids+=( "$!" ) | |
pwait ; | |
curd=$( date -I -d "$curd + $interval day" ); | |
done | |
echo | |
d "waiting process in background to finsh" | |
for pid in "${pids[@]}"; do | |
wait $pid; | |
done | |
sleep 10 | |
echo | |
;; | |
still_images) | |
[ $( ls out/rec*dot | wc -l ) -gt 1 ] || ( push "muscle"; dispatch_action) | |
#[ -f "out/rec.$DATE.jpg" ] && rm out/*jpg | |
pushd out | |
declare -a pids; | |
cp persistent.jpg persistent.jpg.orig | |
d jpg in // | |
for i in *dot; do | |
$DOT -Tjpg "$i" > $( basename "$i" .dot).jpg & | |
ppids+=( "$!" ) | |
echo -n . | |
pwait ; | |
done | |
echo | |
d "waiting process in background to finsh" | |
for pid in "${pids[@]}"; do | |
wait $pid; | |
done | |
sleep 10 | |
echo | |
popd | |
;; | |
movie) | |
[[ $( ls out/rec*jpg | wc -l ) > 1 ]] || ( push "still_images"; dispatch_action) | |
[ -f "out/$MOVIE" ] && rm "out/$MOVIE" | |
pushd out | |
ffmpeg -framerate 2 -pattern_type glob -i "rec.*.jpg" -c:v libx264 \ | |
-vf "scale=1980:1020,setpts=PTS/$MSPEED,format=yuv420p" \ | |
"$MOVIE" 1> /dev/null && echo -e "ffmpeg ${GB}OK${RZ}" \ | |
&& ( [ -z "$SHOW" ] || firefox "./$MOVIE" ) | |
popd | |
;; | |
very_clean) | |
w cleaning out directory | |
set +e | |
rm out/* | |
set -e | |
;; | |
clean) | |
set +e | |
rm out/*.jpg | |
set -e | |
;; | |
*) | |
echo unrecognized "$act"; | |
d "${action[@]}" | |
break | |
;; | |
esac | |
done | |
} | |
if [ ! -z $1 ]; then | |
action=( "$@" ); | |
else | |
push "all" | |
fi | |
dispatch_action | |
d fin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment