update_model.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. abs_path=$(cd `dirname $0`; pwd)
  3. sample_path="${abs_path}/../data"
  4. model_path="${abs_path}/../model"
  5. predict_tools="/data2/jch/package/alphaFM/bin/fm_predict"
  6. predict_param="-core 16"
  7. update_py="${abs_path}/../src/tools/update2oss.py"
  8. monitor_py="${abs_path}/../src/tools/rec_monitor_push.py"
  9. auc_threshold=0.05
  10. online_model_file=""
  11. push_model_name="推荐模型str+"
  12. if(($#==2))
  13. then
  14. online_model_file=$1
  15. push_model_name=$2
  16. else
  17. exit -1
  18. fi
  19. # model size
  20. model_size=$(wc -l $online_model_file| awk '{print $1}')
  21. if [ $model_size -le 10000 ]
  22. then
  23. echo "$online_model_file lines <= 10000"
  24. exit -1
  25. fi
  26. # name & date
  27. model_name=$(echo $online_model_file | awk -F"/" '{print $NF}' | awk -F".txt" '{print $1}')
  28. new_model_date=$(echo $online_model_file | awk -F"/" '{print $(NF-1)}')
  29. old_model_date=$(date -d "$new_model_date -1 day" +"%Y%m%d")
  30. # offline model file
  31. new_off_model_file="${model_path}/${new_model_date}/${model_name}_offline.txt"
  32. old_off_model_file="${model_path}/${old_model_date}/${model_name}_offline.txt"
  33. # eval model
  34. check_file="${sample_path}/${new_model_date}_00063.csv"
  35. if [ -f $check_file ]
  36. then
  37. eval_file_list="${sample_path}/${new_model_date}_00*.csv"
  38. # eval new
  39. new_predict_file="${sample_path}/new_predict.txt"
  40. echo `date` "cat $eval_file_list | $predict_tools -m $new_off_model_file $predict_param -out $new_predict_file"
  41. echo
  42. cat $eval_file_list | $predict_tools -m $new_off_model_file $predict_param -out $new_predict_file &
  43. wait
  44. sleep 30s
  45. # eval old
  46. old_predict_file="${sample_path}/old_predict.txt"
  47. echo `date` "cat $eval_file_list | $predict_tools -m $old_off_model_file $predict_param -out $old_predict_file"
  48. echo
  49. cat $eval_file_list | $predict_tools -m $old_off_model_file $predict_param -out $old_predict_file &
  50. wait
  51. sleep 30s
  52. # compare auc
  53. auc_tools="${abs_path}/../src/tools/cal_auc.py"
  54. new_auc=$(python3 $auc_tools --input $new_predict_file)
  55. old_auc=$(python3 $auc_tools --input $old_predict_file)
  56. diff_auc=$(echo $new_auc $old_auc | awk '{print $1-$2}')
  57. flag=$(echo $diff_auc $auc_threshold | awk '{if($1>-$2&&$1<$2){print 1}else{print 0}}')
  58. if(($flag==1))
  59. then
  60. # 上传模型
  61. echo `date` "python3.6 $update_py --local $online_model_file"
  62. python3.6 $update_py --local $online_model_file &
  63. wait
  64. # 发送通知
  65. level=info
  66. msg=" ${push_model_name}更新完成"
  67. msg+="\n\t - 新模型AUC: ${new_auc}"
  68. msg+="\n\t - 老模型AUC: ${old_auc}"
  69. else
  70. echo "$diff_auc $auc_threshold"
  71. # 发送通知
  72. level=error
  73. msg=" ${push_model_name}更新失败, ${new_model_date}_auc差异为: ${diff_auc}, 大于$auc_threshold"
  74. msg+="\n\t - 新模型AUC: ${new_auc}"
  75. msg+="\n\t - 老模型AUC: ${old_auc}"
  76. fi
  77. echo `date` "python3 $monitor_py --level $level --model $push_model_name --msg $msg"
  78. python3 $monitor_py --level "$level" --model "$push_model_name" --msg "$msg"
  79. fi