#!/bin/bash
flag=$TMP_PATH/full_treemap_bot.flag
date=`date +%Y%m%d0000`

if [ -f $flag ];
then
  echo "treemap_bot is already running !"
  exit 0
fi
touch $flag

cd $APPS_PATH/methode/full_treemap
for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt`
do
  
  if [ ! -f $DATA_PATH/full_treemap/$BLOCK-$MODE.png ]
  then
    php robot.php $BLOCK $((RANDOM % 6))
  fi

  BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'`
  if [ "$BNAME" == "LAST" ]
  then
    touch $DATA_PATH/full_treemap/$BLOCK.png
  else
    touch -t $date $DATA_PATH/full_treemap/$BLOCK.png
  fi

  rm -f $DATA_PATH/hasard/$BLOCK.png
  ln $DATA_PATH/full_treemap/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png
done

rm -f $flag
