#!/bin/bash
set -euo pipefail

if [[ $# -eq 0 ]]; then
	echo Copy ranking output for publishing on archive.realrate.ai
	echo
	echo Run this script from the root of the archive.realrate.ai repository.
	echo
	echo 'Usage:   scripts/update-industry.sh INDUSTRY RR_DIR'
	echo 'Example: scripts/update-industry.sh us_life ../RealRate-Private'
	exit 1
fi

INDUSTRY="$1"
RR_DIR=${2:-../realrate-private}
ARCHIVE_DIR=$(pwd)

pushd "$RR_DIR"/output > /dev/null
    cp --parent "$INDUSTRY"/20??/website-ranking.json "$ARCHIVE_DIR"
    cp --parent "$INDUSTRY"/20??/website-ranking.csv "$ARCHIVE_DIR"
    cp --parent "$INDUSTRY"/20??/report/*.pdf "$ARCHIVE_DIR"
    cp --parent "$INDUSTRY"/20??/graphs/*.svg "$ARCHIVE_DIR"
    cp --parent "$INDUSTRY"/20??/feature_distribution/*.svg "$ARCHIVE_DIR"
    cp --parent "$INDUSTRY"/20??/plot_over_time/*.svg "$ARCHIVE_DIR"
    cp --parent "$INDUSTRY"/20??/backtesting_correlation/*.svg "$ARCHIVE_DIR"
popd > /dev/null
pushd "$RR_DIR"/input > /dev/null
    cp --parent -r "$INDUSTRY/logos" "$ARCHIVE_DIR"
    rm -f "$ARCHIVE_DIR"/*/logos/*_original*
popd > /dev/null
make logos -l 4
./scripts/update-website-overview.py
echo Successfully copied "$INDUSTRY" and updated website-overview.json.
