procedure define convertData - convert sql results into highcharts data format
global columnOne, columnTwo, results, resultsTwo
begin
   go $1
      foreach -row
      do
         ctf set date `print $columnOne`
         ctf set count `print $columnTwo`

         #Convert the date from "2013-09-16" to "2013, 08, 16"
         #Months in Date.UTC start from the index 0
         eval $env->{'date'} =~ s/.*?(\d{4}(?:-\d{2}){2})?.*/\1/;
         eval @{$env->{'tmp'}} = split('-', $env->date)
         eval @{$env->tmp}[1]--
         eval $env->{'date'} = join(', ', @{$env->tmp})

         #Enclosing the $date with quotes because the string contains
         #commas which will conflict with the syntax
         push -e data_array echo as "[Date.UTC(%s), %s]" "$date", $count
      done
      expr join(', ', $data_array)
   return
end

try
do

   set -e data1 procedure call convertData results
   set -e data2 procedure call convertData resultsTwo

   template load template.html
   template header
   template colors
   template footer
catch
   message info $ERROR
done

