SHARE
TWEET

Scoring template

snowpb May 21st, 2019 (edited) 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. TIMEOUT_VAL=60  #unit : seconds
  4.  
  5. ####### Auxiliary functions ######
  6. get_id() {
  7.     local id=$(echo "$1" | /bin/grep -oPi -m 1 "[A|B]\d{6}" | head -1)
  8.     echo ${id}
  9. }
  10.  
  11. get_float() {
  12.     echo "$@" | /bin/grep -oP "\d+\.\d+" #Try capturing floating number
  13.     if [ $? -ne 0 ]
  14.     then
  15.         echo "$@" | /bin/grep -oP "\d+" #Or, just capture an integer
  16.     fi
  17. }
  18.  
  19. bc_true() {
  20.     (( $(echo "$@" | bc -l) != 0))
  21. }
  22.  
  23. get_1st_loss() {
  24.     local ret=$(echo "$1" | /bin/grep -A 1 "^0 번째 트레이닝")
  25.     get_float "$ret"
  26. }
  27.  
  28. get_final_loss() {
  29.     local ret=$(echo "$1" | /bin/grep -A 1 "^30 번째 트레이닝" )
  30.     get_float "$ret"
  31. }
  32.  
  33. get_accuracy() {
  34.     local ret=$(echo "$1" | /bin/grep -A 3 "^30 번째 트레이닝" | tail -1 )
  35.     get_float "$ret"
  36. }
  37.  
  38.  
  39. ####### Score each student's assignment ######
  40. for path in $(find . -name *singlelayer.py)
  41. do
  42.     id=$(get_id "${path}")
  43.  
  44.     cp -f $path ../workspace/
  45.  
  46.     if [ $? -ne 0 ]
  47.     then
  48.         echo "Something is wrong."
  49.         exit 1
  50.     fi
  51.  
  52.     printf "Score %s's assignment.\n" "$id"
  53.  
  54.     val=$(timeout --foreground $TIMEOUT_VAL python3 ../workspace/main.py 2>&1)
  55.  
  56.     if [ $? -ne 0 ]
  57.     then
  58.         printf "%s got failed.\n" "$id"
  59.         continue
  60.     fi
  61.  
  62.     loss=$(get_1st_loss "$val")
  63.     finalLoss=$(get_final_loss "$val")
  64.     accu=$(get_accuracy "$val")
  65.  
  66.     if bc_true "${loss} < 5" && bc_true "${finalLoss} < 1" && bc_true "${accu} >= 60"
  67.     then
  68.         printf "%s got passed.\n" "$id"
  69.     else
  70.         printf "%s got failed.\n" "$id"
  71.     fi
  72.  
  73. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top