
<?
   require 'at_dbconnect.php';
   //get today's date
   $today=getdate();
   //get unix stamp for beginning of today
   $today_start=mktime(0,0,0,$today['mon']*1.0,$today['mday']*1.0,$today['year']*1.0);
   //echo ($today_start);

       //get total number of moves today
       $move_count = mysql_query(
                "SELECT Count(*) As move_count ".
                " FROM tblMoves ".
                " WHERE UNIX_TIMESTAMP(tblMoves.MovedAt) >= $today_start");

    if (!$move_count) {
      echo("<P>Error performing query: " .
           mysql_error() . "</P>");
      exit();
    }
    //echo("<p><u>Latest</u></p>");
    while ( $row = mysql_fetch_array($move_count) ) {
      $total_moves = $row["move_count"];

      //echo("<P>$total_moves</P>");

    }
    //set up percentages array
    $percentages=array(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
      $symbol_count= mysql_query(
                     "SELECT Symbol,((Count(Symbol)/$total_moves)*100) As Percent ".
                     " FROM tblMoves ".
                     " WHERE UNIX_TIMESTAMP(MovedAt) >= $today_start ".
                     " GROUP BY Symbol");

    if (!$symbol_count) {
      echo("<P>Error performing query: " .
           mysql_error() . "</P>");
      exit();
    }
    //echo("<p><u>Percents</u></p>");
    while ( $row = mysql_fetch_array($symbol_count) ) {
      $symbol = $row["Symbol"];
      $percent = $row["Percent"];

      //echo("<P>$symbol - $percent%</P>");
      //set up loop to insert percents
      for($counter=0;$counter<9;$counter++){
         if($symbol==$counter){
            //echo(" inserted $percent ");
            $percentages[$counter]=$percent;
         }

        // echo("</p>");
      }
    }
   $datestr=$today['mday']." ".$today['month'].", ".$today['year'];
    //print_r($percentages);
   $strXML  = "";
   $strXML .= "<chart caption='ATMOSPHERE' subcaption='$datestr' xAxisName='Month' yAxisName='Units' showValues='0'    formatNumberScale='0' showBorder='1' baseFont='Trebuchet MS' baseFontSize ='12' baseFontColor ='000000'>";
   $strXML .= "<set label='Sun' value='$percentages[0]' color='F5E525'/>";
   $strXML .= "<set label='Cloud & Sun' value='$percentages[1]' color='65CBFE' />";
   $strXML .= "<set label='White Cloud' value='$percentages[2]'  color='E5D1D1' />";
   $strXML .= "<set label='Black Cloud' value='$percentages[3]' color='9B9898' />";
   $strXML .= "<set label='Rain Cloud' value='$percentages[4]' color='403E3E'/>";
   $strXML .= "<set label='Lightning' value='$percentages[5]' color='FF9933' />";
   $strXML .= "<set label='Fog' value='$percentages[6]' color='60865F'/>";
   $strXML .= "<set label='Ice' value='$percentages[7]' color='FFFFFF'/>";
   $strXML .= "<set label='Wind' value='$percentages[8]' color='856892'/>";
   $strXML .= "</chart>";

   echo $strXML;
?>

