#!/bin/sh
set -ex

start_date=$1
end_date=$2
model_name=$3
MODEL_PATH="./model/"
SAMPLE_PATH=$4
bias=$5
HADOOP="/opt/apps/HADOOP-COMMON/hadoop-common-current/bin/hadoop"
FM_TRAIN="/root/sunmingze/alphaFM/bin/fm_train"

current_date="$start_date"

while [[ "$current_date" != "$end_date" ]]; do
    echo -------"$current_date"----------

    yesterday=$(date -d "$current_date - 1 day" +%Y%m%d)
    echo model-day-$yesterday
    echo data-day-$current_date
    $HADOOP fs -text ${SAMPLE_PATH}/$current_date/* | ${FM_TRAIN} -m $MODEL_PATH/${model_name}_$current_date.txt -dim ${bias} -core 8 -im $MODEL_PATH/${model_name}_$yesterday.txt
    current_date=$(date -d "$current_date + 1 day" +%Y%m%d)
done

# nohup sh 02_train_go.sh 20240709 20240710 model_nba8 /dw/recommend/model/43_recsys_train_data/ 1,1,8 >p2_model_nba8.log 2>&1 &


# nohup sh 02_train_go.sh 20240623 20240624 model_bkb8 /dw/recommend/model/33_ad_train_data/ 1,1,8 >p2_model_bkb8.log 2>&1 &

# nohup sh 02_train_go.sh 20240703 20240704 model_bkb8_v3 /dw/recommend/model/33_ad_train_data_v3/ 1,1,8 >p2_model_bkb8.log 2>&1 &
