#!/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 20240614 20240615 model_aka8 /dw/recommend/model/16_train_data/ 1,1,8 >p2_model_aka8.log 2>&1 &
