#!/bin/sh

# 重新训练模型

set -x

begin_date=$1
end_date=$2
model_name=$3
train_dim=$4
hdfs_path=$5


PROJECT_HOME=/root/zhaohp/recommend-emr-dataprocess
HADOOP=/opt/apps/HADOOP-COMMON/hadoop-common-current/bin/hadoop
MODEL_PATH=${PROJECT_HOME}/model/recommend

FM_TRAIN=/root/sunmingze/alphaFM/bin/fm_train

train_date=$begin_date

main() {

    end_date=$(date -d "$end_date +1 day" +%Y%m%d)

    # 增量训练模型
    while [ "$train_date" != "$end_date" ]; do
        echo "==================== 开始训练 $train_date 模型 ===================="

        if [ "$train_date" == "$begin_date" ]; then
            $HADOOP fs -text ${hdfs_path}/${train_date}/* | ${FM_TRAIN} -m ${MODEL_PATH}/${model_name}_${train_date}.txt -dim ${train_dim} -core 8
        else
            yesterday=$(date -d "$train_date -1 day" +%Y%m%d)
            $HADOOP fs -text ${hdfs_path}/${train_date}/* | ${FM_TRAIN} -m ${MODEL_PATH}/${model_name}_${train_date}.txt -dim ${train_dim} -core 8 -im ${MODEL_PATH}/${model_name}_${yesterday}.txt
        fi

        echo -e "==================== 训练 $train_date 模型结束 ====================\n\n\n\n\n\n"

        train_date=$(date -d "$train_date +1 day" +%Y%m%d)
    done

}

main

# nohup ./recommend/01_recommend_model_new_train.sh 20240815 20240821 model_nba8_v3 1,1,8 /dw/recommend/model/43_recsys_train_data_new_table_274_sample_01/ > logs/25_recommend_model_new_train.log 2>&1 &
