| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #!/bin/bash
- abs_path=$(cd `dirname $0`; pwd)
- sample_path="${abs_path}/../data"
- model_path="${abs_path}/../model"
- predict_tools="/data2/jch/package/alphaFM/bin/fm_predict"
- predict_param="-core 16"
- update_py="${abs_path}/../src/tools/update2oss.py"
- monitor_py="${abs_path}/../src/tools/rec_monitor_push.py"
- auc_threshold=0.05
- online_model_file=""
- push_model_name="推荐模型str+"
- if(($#==2))
- then
- online_model_file=$1
- push_model_name=$2
- else
- exit -1
- fi
- # model size
- model_size=$(wc -l $online_model_file| awk '{print $1}')
- if [ $model_size -le 10000 ]
- then
- echo "$online_model_file lines <= 10000"
- exit -1
- fi
- # name & date
- model_name=$(echo $online_model_file | awk -F"/" '{print $NF}' | awk -F".txt" '{print $1}')
- new_model_date=$(echo $online_model_file | awk -F"/" '{print $(NF-1)}')
- old_model_date=$(date -d "$new_model_date -1 day" +"%Y%m%d")
- # offline model file
- new_off_model_file="${model_path}/${new_model_date}/${model_name}_offline.txt"
- old_off_model_file="${model_path}/${old_model_date}/${model_name}_offline.txt"
- # eval model
- check_file="${sample_path}/${new_model_date}_00063.csv"
- if [ -f $check_file ]
- then
- eval_file_list="${sample_path}/${new_model_date}_00*.csv"
- # eval new
- new_predict_file="${sample_path}/new_predict.txt"
- echo `date` "cat $eval_file_list | $predict_tools -m $new_off_model_file $predict_param -out $new_predict_file"
- echo
- cat $eval_file_list | $predict_tools -m $new_off_model_file $predict_param -out $new_predict_file &
- wait
- sleep 30s
- # eval old
- old_predict_file="${sample_path}/old_predict.txt"
- echo `date` "cat $eval_file_list | $predict_tools -m $old_off_model_file $predict_param -out $old_predict_file"
- echo
- cat $eval_file_list | $predict_tools -m $old_off_model_file $predict_param -out $old_predict_file &
- wait
- sleep 30s
- # compare auc
- auc_tools="${abs_path}/../src/tools/cal_auc.py"
- new_auc=$(python3 $auc_tools --input $new_predict_file)
- old_auc=$(python3 $auc_tools --input $old_predict_file)
- diff_auc=$(echo $new_auc $old_auc | awk '{print $1-$2}')
- flag=$(echo $diff_auc $auc_threshold | awk '{if($1>-$2&&$1<$2){print 1}else{print 0}}')
- if(($flag==1))
- then
- # 上传模型
- echo `date` "python3.6 $update_py --local $online_model_file"
- python3.6 $update_py --local $online_model_file &
- wait
- # 发送通知
- level=info
- msg=" ${push_model_name}更新完成"
- msg+="\n\t - 新模型AUC: ${new_auc}"
- msg+="\n\t - 老模型AUC: ${old_auc}"
- else
- echo "$diff_auc $auc_threshold"
- # 发送通知
- level=error
- msg=" ${push_model_name}更新失败, ${new_model_date}_auc差异为: ${diff_auc}, 大于$auc_threshold"
- msg+="\n\t - 新模型AUC: ${new_auc}"
- msg+="\n\t - 老模型AUC: ${old_auc}"
- fi
- echo `date` "python3 $monitor_py --level $level --model $push_model_name --msg $msg"
- python3 $monitor_py --level "$level" --model "$push_model_name" --msg "$msg"
- fi
|