#!/usr/bin/env bash

# aws.sh should already exist on the instance and contain the relevant AWS env vars
source ~/aws.sh
# env.sh should have been generated by the deploy script (deploy.py)
source env.sh

virtualenv -p python3.6 venv
source venv/bin/activate
pip install -r kite_ml/requirements.txt

./graph_data_server > /data/logs/graph-server.log 2>&1 &

# wait for graph server to spin up
echo "waiting for graph server to spin up..."
while true; do
    if curl http://localhost:3039/some_bogus_page 2>&1 | grep -q '404 page not found'
    then
        break
    fi
    sleep 10
done

PYTHONPATH=./kite_ml python get_data.py \
    --endpoint=http://localhost:3039 \
    --random_seed=$RANDOM_SEED \
    --batch=$BATCH \
    --samples=$SAMPLES \
    --attr_proportion=$ATTR_PROPORTION \
    --attr_base_proportion=$ATTR_BASE_PROPORTION \
    --call_proportion=$CALL_PROPORTION \
    --arg_type_proportion=$ARG_TYPE_PROPORTION \
    --kwarg_name_proportion=$KWARG_NAME_PROPORTION \
    --arg_placeholder_proportion=$ARG_PLACEHOLDER_PROPORTION \
    --meta_info=./metainfo.json \
    --out_dir=$OUT_DIR \
    --samples_per_file=$SAMPLES_PER_FILE \
    --max_samples=$MAX_SAMPLES
