#! /opt/bin/dash
#
# os/prog/segmentation/post.sh
export PATH="/opt/bin:/bin:/usr/bin"
#echo "Content-type: text/plain\n"; in=$(cat); echo "in = \"$in\""; exit
echo "Content-type: text/html\n\n
segmentation"
user=`echo "${REMOTE_USER}" | tr -dc '[:alnum:]' | tr '[:upper:]' '[:lower:]'`
if [ -z "$user" ]; then echo "Bad user: ${REMOTE_USER} -> $user"; exit 1; fi
if [ -n "$HTTP_HOST" ]; then cd /os/prog/segmentation || exit 1; fi
# tomato = #FF6347
# lightgreen = #90EE90
#
in=$(cat | egrep -v '#FF6347|#90EE90')
useed=$(echo "$in" | awk '{ if( $2 == "useed") { gsub(/[^0-9]/,"",$3); print $3; exit; }}')
n="8"; a="2048"; p="32768"; s="123456789"
if [ -n "$useed" ]; then
seed="$useed"
msg="- seed = $seed"
else
x=$(perl -e "print unpack(\"C*\",$user);"); seed="${s}${x}"
#echo "s = $s, x = $x, seed = $seed
"
msg=""
fi
echo "$user - segmentation results $msg
green = correct |
red = wrong |
"
#echo "
"
#python3 ./segmentation.py -s "$seed" -n "$n" -a "$a" -p "$p" -c | sed -e 's/) / /' -e 's/)$//'
#echo "
"
out=$(
(echo "$in"; python3 ./segmentation.py -s "$seed" -n "$n" -a "$a" -p "$p" -c |
sed -e 's/) / /' -e 's/)$//') |
awk -v "a=$a" 'BEGIN { v=0; print " # | ";
print "VA | PA |
"; } {
# each line of user input from segmentation-post looks like: U name value
if( $1 != "") { if( $1 == "U") u[$2]=$3;
else if( $1" "$2" "$3 == "Segment 0 limit") limit0 = $5;
else if( $1" "$2" "$3 == "Segment 1 limit") limit1 = $5;
else if( $1 == "VA") {
va=$5; pa=$12; if( pa == "") pa=0;
print ""v" | "va" | ";
x=u["v"v"v"]; if( x != "" && x == pa) color="#90EE90"; else color="#FF6347";
print " "x" |
"; ++v;
}}} END { highest0 = limit0-1; lowest1 = a-limit1;
print "highest VA seg0 | ";
x=u["v8v"]; if( x != "" && x == highest0) color="#90EE90"; else color="#FF6347";
print " "x" |
";
print "lowest VA seg1 | ";
x=u["v9v"]; if( x != "" && x == lowest1) color="#90EE90"; else color="#FF6347";
print " "x" |
";
}'
)
if [ -z "$useed" ]; then
bad=$(echo "$out" | grep "#FF6347" | wc -l)
good=$(echo "$out" | grep "#90EE90" | wc -l)
log=$(echo "$in" | tr -dc '[:alnum:]')
echo "$(date) $user good $good bad $bad in: $log" >> log
fi
echo "$out
"