#!/bin/bash
set -e 0
source $ZOOX_WORKSPACE_ROOT/scripts/shell/zooxrc.sh

function get_data {
  URIS=$(curl \
    'https://mined-metrics.zooxlabs.com/api/mined_metrics_backend/v1/get_all_meta_for_metric_experiment?id='$1 \
    --compressed |\
    jq '.data[] .chum_uri' -r)

  VIDEOS=$(curl \
    'https://mined-metrics.zooxlabs.com/api/mined_metrics_backend/v1/get_all_meta_for_metric_experiment?id='$1 \
    --compressed |\
    jq '.data[] .multimedia_uri[]' -r)

  for uri in $URIS;
  do
    FN=$(echo $uri | cut -d? -f1 | cut -d/ -f3 | sed -e 's/\.[0-9]*\+//g' )
    brun :extract_data -- --chum_uri $uri > data/$2_$FN.csv &
  done

  for v in $VIDEOS;
  do
    FN=$(echo $v | cut -d/ -f6)
    echo $v > data/$2_$FN.loc &
  done
}

mkdir -p data

# Initial mvp test
# 19.40
#get_data '67f1a495-7208-4b1b-9418-6f90e16b38e1' '19_40'

# 19.36
#get_data '0c9d9497-7cd6-4302-965b-76ac6123280e' '19_36'

# 19.34
#get_data '340d2dc0-1abf-4e82-9fe1-0a63adcb91a0' '19_34'

# baseline
#get_data '78adb9c9-27bc-4fe1-8d0c-c303c904b322' 'baseline'


#NTLJ
#get_data 'faa2146e-21a4-4339-b47a-ba5f714a3b13' '19_44'
#get_data '9ed4e0a2-3c90-48af-b5e5-cc611718f14e' '19_42'
#get_data 'c829cf42-dbf5-4d09-b02f-49f0c6ec2fe5' '19_40'
#get_data 'a4e6ed6a-a7d3-4397-80e2-c153a346a466' '19_36'
#get_data 'd620fe1b-cde3-4caf-8e8b-46317a762340' '19_34'
#get_data 'fa81181c-5df9-42cb-916e-34c7c61e53e6' 'baseline'

# 1944 regression
#get_data '7451b9be-59e6-4cc2-bdfb-6e1232cb63cf' '19_44'
#get_data '2c5d048e-7a16-4eb3-9648-b4758efe868e' '19_42'
#get_data '3d94e66b-f283-4143-9a08-749188224de3' 'baseline'

# logtests
get_data '9d915532-62f6-41d3-bdb5-e0588fc39658' '19_44'
get_data '8d29e334-8198-4efb-a979-cfb9d5be51e1' '19_42'

echo "Waiting for all forked processes..."
wait
echo "Done waiting. Data extracted to 'data' folder."


