<commit_before><?php
/*=========================================================================

  Program:   CDash - Cross-Platform Dashboard System
  Module:    $RCSfile: ctestparser.php,v $
  Language:  PHP
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Kitware, Inc.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

/** Main function to parse the incoming xml from ctest */
function ctest_parse($parser,$projectid)
{ 
  if(@$parser->index["BUILD"] != "")
    {
    parse_build($parser,$projectid);
    }
  else if(@$parser->index["CONFIGURE"] != "")
    {
    parse_configure($parser,$projectid);
    }
  else if(@$parser->index["TESTING"] != "")
    {
    parse_testing($parser,$projectid);
    }
  else if(@$parser->index["UPDATE"] != "")
    {
    parse_update($parser,$projectid);
    }  
  else if(@$parser->index["COVERAGE"] != "")
    {
    parse_coverage($parser,$projectid);
    } 
  else if(@$parser->index["COVERAGELOG"] != "")
    {
    parse_coveragelog($parser,$projectid);
    }
  else if(@$parser->index["NOTES"] != "")
    {
    parse_note($parser,$projectid);
    }
  else if(@$parser->index["DYNAMICANALYSIS"] != "")
    {
    parse_dynamicanalysis($parser,$projectid);
    }
}

/** Return the value given a tag or the parent tag */
function getXMLValue($xmlarray,$tag,$parenttag)
{
  if($parenttag=="")
    {
    $parentlevel = 0;
    }
  else
    {
    $parentlevel = -1;
    }
    
  foreach($xmlarray as $tagarray)
   {
   if($tagarray["tag"] == $parenttag)
     {
     $parentlevel = $tagarray["level"];
     }
   else if($tagarray["tag"] == $tag)
     {
     if($parentlevel==0 || $tagarray["level"] == $parentlevel+1)
       {
       return $tagarray["value"];
       }
     }
   }
  return "NA";
}

/** Return timestamp from string
 *  \WARNING this function needs improvement */
function str_to_time($str,$stamp)
{
  $str = str_replace("Eastern Standard Time","EST",$str);
  $str = str_replace("Eastern Daylight Time","EDT",$str);
  
  // For some reasons the Australian time is not recognized by php
  // Actually an open bug in PHP 5.
  $offset = 0; // no offset by default
  if(strpos($str,"AEDT") !== FALSE)
    {
    $str = str_replace("AEDT","UTC",$str);
    $offset = 3600*11;
    }
 // We had more custom dates
 else if(strpos($str,"Paris, Madrid") !== FALSE)
    {
    $str = str_replace("Paris, Madrid","UTC",$str);
    $offset = 3600*1;
    }
 else if(strpos($str,"W. Europe Standard Time") !== FALSE)
    {
    $str = str_replace("W. Europe Standard Time","UTC",$str);
    $offset = 3600*1;
    }
  
  // The year is always at the end of the string if it exists (from CTest)
  $stampyear = substr($stamp,0,4);
  $year = substr($str,strlen($str)-4,2);
  
  if($year!="19" && $year!="20")
    {
    // No year is defined we add it
    // find the hours
    $pos = strpos($str,":");
    if($pos !== FALSE)
      {
      $tempstr = $str;
      $str = substr($tempstr,0,$pos-2);
      $str .= $stampyear." ".substr($tempstr,$pos-2);
      }
    }
  
  $strtotimefailed = 0;
  if(PHP_VERSION>=5.1)
    {  
    if(strtotime($str) === FALSE)
      {
      $strtotimefailed = 1;
      }
    }
  else
    {
    if(strtotime($str) == -1)
      {
      $strtotimefailed = 1;
      }
    }
    
  // If it's still failing we assume GMT and put the year at the end
  if($strtotimefailed)
    {
    // find the hours
    $pos = strpos($str,":");
    if($pos !== FALSE)
      {
      $tempstr = $str;
      $str = substr($tempstr,0,$pos-2);
      $str .= substr($tempstr,$pos-2,5);   
      }
    } 
  
  return strtotime($str)-$offset;
}


/** Parse the build xml */
function parse_build($parser,$projectid)
{   
  $xmlarray = $parser->vals;
 
  $site = $parser->index["SITE"];
  $sitename = $parser->vals[$site[0]]["attributes"]["NAME"]; 
  $name = $parser->vals[$site[0]]["attributes"]["BUILDNAME"];
  // Extract the type from the buildstamp
  $stamp = $parser->vals[$site[0]]["attributes"]["BUILDSTAMP"];
  $type = substr($stamp,strrpos($stamp,"-")+1);
  $generator = $parser->vals[$site[0]]["attributes"]["GENERATOR"];
  $starttime = getXMLValue($xmlarray,"STARTDATETIME","BUILD");
  
  // Convert the starttime to a timestamp
  $starttimestamp = str_to_time($starttime,$stamp);
  $elapsedminutes = getXMLValue($xmlarray,"ELAPSEDMINUTES","BUILD");
  $endtimestamp = $starttimestamp+$elapsedminutes*60;
  $command = getXMLValue($xmlarray,"BUILDCOMMAND","BUILD");
  $log = getXMLValue($xmlarray,"LOG","BUILD");
  
  include("config.php");
  include_once("common.php");
  $db = mysql_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS");
  mysql_select_db("$CDASH_DB_NAME",$db);

  // First we look at the site and add it if not in the list
  $siteid = add_site($sitename,$parser);
      
  $start_time = gmdate("Y-m-d H:i:s",$starttimestamp);
  $end_time = gmdate("Y-m-d H:i:s",$endtimestamp);
  $submit_time = gmdate("Y-m-d H:i:s");
  
  $buildid = add_build($projectid,$siteid,$name,$stamp,$type,$generator,
                       $start_time,$end_time,$submit_time,$command,$log,$parser);
  
  // Add the warnings
  $error_array = array();
  $index = 0;
  $inerror = false;
 
  foreach($xmlarray as $tagarray)
    {
    if(!$inerror && (($tagarray["tag"] == "WARNING") || ($tagarray["tag"] == "ERROR") ) 
     && ($tagarray["level"] == 3) && $tagarray["type"]=="open")
      {
      $inerror = true;
      $index++;
      if($tagarray["tag"] == "WARNING")
        {
        $error_array[$index]["type"]=1; // warning are type 1
        }
      else
        {
        $error_array[$index]["type"]=0;
        }
      }
    else if(($tagarray["tag"] == "BUILDLOGLINE") && ($tagarray["level"] == 4))
      {
      $error_array[$index]["logline"]=$tagarray["value"];
      }
    else if(($tagarray["tag"] == "TEXT") && ($tagarray["level"] == 4))
      {
      $error_array[$index]["text"]=$tagarray["value"];
      }
    else if(($tagarray["tag"] == "SOURCEFILE") && ($tagarray["level"] == 4))
      {
      $error_array[$index]["sourcefile"]=$tagarray["value"];
      }
    else if(($tagarray["tag"] == "SOURCELINENUMBER") && ($tagarray["level"] == 4))
      {
      $error_array[$index]["sourceline"]=$tagarray["value"];
      }
    else if(($tagarray["tag"] == "PRECONTEXT") && ($tagarray["level"] == 4) && array_key_exists("value",$tagarray))
      {
      $error_array[$index]["precontext"]=$tagarray["value"];
      }
    else if(($tagarray["tag"] == "POSTCONTEXT") && ($tagarray["level"] == 4) && array_key_exists("value",$tagarray))
      {
      $error_array[$index]["postcontext"]=$tagarray["value"];
      }
    else if(($tagarray["tag"] == "REPEATCOUNT") && ($tagarray["level"] == 4) && array_key_exists("value",$tagarray))
      {
      $error_array[$index]["repeatcount"]=$tagarray["value"];
      $inerror = false;
      }
    }
   

  foreach($error_array as $error)
    {
    if(array_key_exists("logline",$error))
      {
      add_error($buildid,$error["type"],$error["logline"],$error["text"],@$error["sourcefile"],@$error["sourceline"],
                @$error["precontext"],@$error["postcontext"],$error["repeatcount"]);
      }
    }
}

function create_build($parser,$projectid)
{
  $xmlarray = $parser->vals;
  $site = $parser->index["SITE"];
  
  $sitename = $parser->vals[$site[0]]["attributes"]["NAME"]; 
  $buildname = $parser->vals[$site[0]]["attributes"]["BUILDNAME"];

  // Extract the type from the buildstamp
  $stamp = $parser->vals[$site[0]]["attributes"]["BUILDSTAMP"];
  $type = substr($stamp,strrpos($stamp,"-")+1);
  $generator = $parser->vals[$site[0]]["attributes"]["GENERATOR"];
 $starttime_index = $parser->index["STARTDATETIME"];
  $starttime = $parser->vals[$starttime_index[0]]["value"];
  
  // Convert the starttime to a timestamp
  $starttimestamp = str_to_time($starttime,$stamp);

  $elapsedminutes_index = $parser->index["ELAPSEDMINUTES"];
  $elapsedminutes = $parser->vals[$elapsedminutes_index[0]]["value"];
  $endtimestamp = $starttimestamp+$elapsedminutes*60;
    
  include("config.php");
  include_once("common.php");
  $db = mysql_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS");
  mysql_select_db("$CDASH_DB_NAME",$db);
  
  // First we look at the site and add it if not in the list
  $siteid = add_site($sitename,$parser);
       
  $start_time = gmdate("Y-m-d H:i:s",$starttimestamp);
  $end_time = gmdate("Y-m-d H:i:s",$endtimestamp);
  $submit_time = gmdate("Y-m-d H:i:s");
  
  $buildid = add_build($projectid,$siteid,$buildname,$stamp,$type,$generator,$start_time,$end_time,$submit_time,"","",$parser);
  
  return $buildid;
}

/** Parse the configure xml */
function parse_configure($parser,$projectid)
{
  include_once("common.php");
 
  $xmlarray = $parser->vals;
  $site = $parser->index["SITE"]; 
  $name = $parser->vals[$site[0]]["attributes"]["BUILDNAME"];
  $stamp = $parser->vals[$site[0]]["attributes"]["BUILDSTAMP"];
  
  // Find the build id
  $buildid = get_build_id($name,$stamp,$projectid);
  if($buildid<0)
    {
    $buildid = create_build($parser,$projectid);
    }
    
  $starttime = getXMLValue($xmlarray,"STARTDATETIME","CONFIGURE");
  $starttimestamp = str_to_time($starttime,$stamp);
  $elapsedminutes = getXMLValue($xmlarray,"ELAPSEDMINUTES","CONFIGURE");
  $endtimestamp = $starttimestamp+$elapsedminutes*60;
  $command = getXMLValue($xmlarray,"BUILDCOMMAND","CONFIGURE");
  $log = getXMLValue($xmlarray,"LOG","CONFIGURE");
  $command = getXMLValue($xmlarray,"CONFIGURECOMMAND","CONFIGURE");
  $status = getXMLValue($xmlarray,"CONFIGURESTATUS","CONFIGURE");
  

  $start_time = gmdate("Y-m-d H:i:s",$starttimestamp);
  $end_time = gmdate("Y-m-d H:i:s",$endtimestamp);
  
  add_configure($buildid,$start_time,$end_time,$command,$log,$status);
}

/** Parse the testing xml */
function parse_testing($parser,$projectid)
{
  include_once("common.php");

  $xmlarray = $parser->vals;
  $site = $parser->index["SITE"]; 
  $name = $parser->vals[$site[0]]["attributes"]["BUILDNAME"];
  $stamp = $parser->vals[$site[0]]["attributes"]["BUILDSTAMP"];

  // Find the build id
  $buildid = get_build_id($name,$stamp,$projectid);
  if($buildid<0)
    {
    $buildid = create_build($parser,$projectid);
    }

  $test_array = array();
  $index = 0;
  $getTimeNext = FALSE;
  $getDetailsNext = FALSE;
  $getSummaryNext = FALSE;
  $getImageNext = FALSE;
  $imageType = "";
  $imageRole = "";
  foreach($xmlarray as $tagarray)
    {
    $key = $tagarray["tag"];
    @$val = $tagarray["value"];
    if(($tagarray["tag"] == "TEST") && ($tagarray["level"] == 3) && isset($tagarray["attributes"]["STATUS"]))
      {
      $index++;
      $test_array[$index]["status"]=$tagarray["attributes"]["STATUS"];
      $test_array[$index]["images"] = array();
      }
    else if( ($tagarray["level"] == 5) && array_key_exists("attributes",$tagarray) 
            && ($tagarray["attributes"]["NAME"] == "Execution Time") )
      {
      $getTimeNext = TRUE;
      }
    else if( ($tagarray["level"] == 5) && array_key_exists("attributes",$tagarray) 
            && ($tagarray["attributes"]["NAME"] == "Completion Status") )
      {
      $getDetailsNext = TRUE;
      }
    else if( ($tagarray["level"] == 5) && ($tagarray["tag"] == "MEASUREMENT") )
      {
      $getSummaryNext = TRUE;
      }
    else if( ($tagarray["level"] == 5) && array_key_exists("attributes",$tagarray)
            && (strpos($tagarray["attributes"]["TYPE"], "image") !== FALSE) )
      {
      $getImageNext = TRUE;
      $imageType = $tagarray["attributes"]["TYPE"];
      $imageRole = $tagarray["attributes"]["NAME"];
      }
    else if( ($tagarray["level"] == 6) && $getTimeNext)
      {
      $test_array[$index]["executiontime"]=$tagarray["value"];
      $getTimeNext = FALSE;
      }
    else if( ($tagarray["level"] == 6) && $getDetailsNext)
      {
      $test_array[$index]["details"]=$tagarray["value"];
      $getDetailsNext = FALSE;<commit_msg>BUG: Completion Status should be Exit Code for test details<commit_after><?php
/*=========================================================================

  Program:   CDash - Cross-Platform Dashboard System
  Module:    $RCSfile: ctestparser.php,v $
  Language:  PHP
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Kitware, Inc.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

/** Main function to parse the incoming xml from ctest */
function ctest_parse($parser,$projectid)
{ 
  if(@$parser->index["BUILD"] != "")
    {
    parse_build($parser,$projectid);
    }
  else if(@$parser->index["CONFIGURE"] != "")
    {
    parse_configure($parser,$projectid);
    }
  else if(@$parser->index["TESTING"] != "")
    {
    parse_testing($parser,$projectid);
    }
  else if(@$parser->index["UPDATE"] != "")
    {
    parse_update($parser,$projectid);
    }  
  else if(@$parser->index["COVERAGE"] != "")
    {
    parse_coverage($parser,$projectid);
    } 
  else if(@$parser->index["COVERAGELOG"] != "")
    {
    parse_coveragelog($parser,$projectid);
    }
  else if(@$parser->index["NOTES"] != "")
    {
    parse_note($parser,$projectid);
    }
  else if(@$parser->index["DYNAMICANALYSIS"] != "")
    {
    parse_dynamicanalysis($parser,$projectid);
    }
}

/** Return the value given a tag or the parent tag */
function getXMLValue($xmlarray,$tag,$parenttag)
{
  if($parenttag=="")
    {
    $parentlevel = 0;
    }
  else
    {
    $parentlevel = -1;
    }
    
  foreach($xmlarray as $tagarray)
   {
   if($tagarray["tag"] == $parenttag)
     {
     $parentlevel = $tagarray["level"];
     }
   else if($tagarray["tag"] == $tag)
     {
     if($parentlevel==0 || $tagarray["level"] == $parentlevel+1)
       {
       return $tagarray["value"];
       }
     }
   }
  return "NA";
}

/** Return timestamp from string
 *  \WARNING this function needs improvement */
function str_to_time($str,$stamp)
{
  $str = str_replace("Eastern Standard Time","EST",$str);
  $str = str_replace("Eastern Daylight Time","EDT",$str);
  
  // For some reasons the Australian time is not recognized by php
  // Actually an open bug in PHP 5.
  $offset = 0; // no offset by default
  if(strpos($str,"AEDT") !== FALSE)
    {
    $str = str_replace("AEDT","UTC",$str);
    $offset = 3600*11;
    }
 // We had more custom dates
 else if(strpos($str,"Paris, Madrid") !== FALSE)
    {
    $str = str_replace("Paris, Madrid","UTC",$str);
    $offset = 3600*1;
    }
 else if(strpos($str,"W. Europe Standard Time") !== FALSE)
    {
    $str = str_replace("W. Europe Standard Time","UTC",$str);
    $offset = 3600*1;
    }
  
  // The year is always at the end of the string if it exists (from CTest)
  $stampyear = substr($stamp,0,4);
  $year = substr($str,strlen($str)-4,2);
  
  if($year!="19" && $year!="20")
    {
    // No year is defined we add it
    // find the hours
    $pos = strpos($str,":");
    if($pos !== FALSE)
      {
      $tempstr = $str;
      $str = substr($tempstr,0,$pos-2);
      $str .= $stampyear." ".substr($tempstr,$pos-2);
      }
    }
  
  $strtotimefailed = 0;
  if(PHP_VERSION>=5.1)
    {  
    if(strtotime($str) === FALSE)
      {
      $strtotimefailed = 1;
      }
    }
  else
    {
    if(strtotime($str) == -1)
      {
      $strtotimefailed = 1;
      }
    }
    
  // If it's still failing we assume GMT and put the year at the end
  if($strtotimefailed)
    {
    // find the hours
    $pos = strpos($str,":");
    if($pos !== FALSE)
      {
      $tempstr = $str;
      $str = substr($tempstr,0,$pos-2);
      $str .= substr($tempstr,$pos-2,5);   
      }
    } 
  
  return strtotime($str)-$offset;
}


/** Parse the build xml */
function parse_build($parser,$projectid)
{   
  $xmlarray = $parser->vals;
 
  $site = $parser->index["SITE"];
  $sitename = $parser->vals[$site[0]]["attributes"]["NAME"]; 
  $name = $parser->vals[$site[0]]["attributes"]["BUILDNAME"];
  // Extract the type from the buildstamp
  $stamp = $parser->vals[$site[0]]["attributes"]["BUILDSTAMP"];
  $type = substr($stamp,strrpos($stamp,"-")+1);
  $generator = $parser->vals[$site[0]]["attributes"]["GENERATOR"];
  $starttime = getXMLValue($xmlarray,"STARTDATETIME","BUILD");
  
  // Convert the starttime to a timestamp
  $starttimestamp = str_to_time($starttime,$stamp);
  $elapsedminutes = getXMLValue($xmlarray,"ELAPSEDMINUTES","BUILD");
  $endtimestamp = $starttimestamp+$elapsedminutes*60;
  $command = getXMLValue($xmlarray,"BUILDCOMMAND","BUILD");
  $log = getXMLValue($xmlarray,"LOG","BUILD");
  
  include("config.php");
  include_once("common.php");
  $db = mysql_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS");
  mysql_select_db("$CDASH_DB_NAME",$db);

  // First we look at the site and add it if not in the list
  $siteid = add_site($sitename,$parser);
      
  $start_time = gmdate("Y-m-d H:i:s",$starttimestamp);
  $end_time = gmdate("Y-m-d H:i:s",$endtimestamp);
  $submit_time = gmdate("Y-m-d H:i:s");
  
  $buildid = add_build($projectid,$siteid,$name,$stamp,$type,$generator,
                       $start_time,$end_time,$submit_time,$command,$log,$parser);
  
  // Add the warnings
  $error_array = array();
  $index = 0;
  $inerror = false;
 
  foreach($xmlarray as $tagarray)
    {
    if(!$inerror && (($tagarray["tag"] == "WARNING") || ($tagarray["tag"] == "ERROR") ) 
     && ($tagarray["level"] == 3) && $tagarray["type"]=="open")
      {
      $inerror = true;
      $index++;
      if($tagarray["tag"] == "WARNING")
        {
        $error_array[$index]["type"]=1; // warning are type 1
        }
      else
        {
        $error_array[$index]["type"]=0;
        }
      }
    else if(($tagarray["tag"] == "BUILDLOGLINE") && ($tagarray["level"] == 4))
      {
      $error_array[$index]["logline"]=$tagarray["value"];
      }
    else if(($tagarray["tag"] == "TEXT") && ($tagarray["level"] == 4))
      {
      $error_array[$index]["text"]=$tagarray["value"];
      }
    else if(($tagarray["tag"] == "SOURCEFILE") && ($tagarray["level"] == 4))
      {
      $error_array[$index]["sourcefile"]=$tagarray["value"];
      }
    else if(($tagarray["tag"] == "SOURCELINENUMBER") && ($tagarray["level"] == 4))
      {
      $error_array[$index]["sourceline"]=$tagarray["value"];
      }
    else if(($tagarray["tag"] == "PRECONTEXT") && ($tagarray["level"] == 4) && array_key_exists("value",$tagarray))
      {
      $error_array[$index]["precontext"]=$tagarray["value"];
      }
    else if(($tagarray["tag"] == "POSTCONTEXT") && ($tagarray["level"] == 4) && array_key_exists("value",$tagarray))
      {
      $error_array[$index]["postcontext"]=$tagarray["value"];
      }
    else if(($tagarray["tag"] == "REPEATCOUNT") && ($tagarray["level"] == 4) && array_key_exists("value",$tagarray))
      {
      $error_array[$index]["repeatcount"]=$tagarray["value"];
      $inerror = false;
      }
    }
   

  foreach($error_array as $error)
    {
    if(array_key_exists("logline",$error))
      {
      add_error($buildid,$error["type"],$error["logline"],$error["text"],@$error["sourcefile"],@$error["sourceline"],
                @$error["precontext"],@$error["postcontext"],$error["repeatcount"]);
      }
    }
}

function create_build($parser,$projectid)
{
  $xmlarray = $parser->vals;
  $site = $parser->index["SITE"];
  
  $sitename = $parser->vals[$site[0]]["attributes"]["NAME"]; 
  $buildname = $parser->vals[$site[0]]["attributes"]["BUILDNAME"];

  // Extract the type from the buildstamp
  $stamp = $parser->vals[$site[0]]["attributes"]["BUILDSTAMP"];
  $type = substr($stamp,strrpos($stamp,"-")+1);
  $generator = $parser->vals[$site[0]]["attributes"]["GENERATOR"];
 $starttime_index = $parser->index["STARTDATETIME"];
  $starttime = $parser->vals[$starttime_index[0]]["value"];
  
  // Convert the starttime to a timestamp
  $starttimestamp = str_to_time($starttime,$stamp);

  $elapsedminutes_index = $parser->index["ELAPSEDMINUTES"];
  $elapsedminutes = $parser->vals[$elapsedminutes_index[0]]["value"];
  $endtimestamp = $starttimestamp+$elapsedminutes*60;
    
  include("config.php");
  include_once("common.php");
  $db = mysql_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS");
  mysql_select_db("$CDASH_DB_NAME",$db);
  
  // First we look at the site and add it if not in the list
  $siteid = add_site($sitename,$parser);
       
  $start_time = gmdate("Y-m-d H:i:s",$starttimestamp);
  $end_time = gmdate("Y-m-d H:i:s",$endtimestamp);
  $submit_time = gmdate("Y-m-d H:i:s");
  
  $buildid = add_build($projectid,$siteid,$buildname,$stamp,$type,$generator,$start_time,$end_time,$submit_time,"","",$parser);
  
  return $buildid;
}

/** Parse the configure xml */
function parse_configure($parser,$projectid)
{
  include_once("common.php");
 
  $xmlarray = $parser->vals;
  $site = $parser->index["SITE"]; 
  $name = $parser->vals[$site[0]]["attributes"]["BUILDNAME"];
  $stamp = $parser->vals[$site[0]]["attributes"]["BUILDSTAMP"];
  
  // Find the build id
  $buildid = get_build_id($name,$stamp,$projectid);
  if($buildid<0)
    {
    $buildid = create_build($parser,$projectid);
    }
    
  $starttime = getXMLValue($xmlarray,"STARTDATETIME","CONFIGURE");
  $starttimestamp = str_to_time($starttime,$stamp);
  $elapsedminutes = getXMLValue($xmlarray,"ELAPSEDMINUTES","CONFIGURE");
  $endtimestamp = $starttimestamp+$elapsedminutes*60;
  $command = getXMLValue($xmlarray,"BUILDCOMMAND","CONFIGURE");
  $log = getXMLValue($xmlarray,"LOG","CONFIGURE");
  $command = getXMLValue($xmlarray,"CONFIGURECOMMAND","CONFIGURE");
  $status = getXMLValue($xmlarray,"CONFIGURESTATUS","CONFIGURE");
  

  $start_time = gmdate("Y-m-d H:i:s",$starttimestamp);
  $end_time = gmdate("Y-m-d H:i:s",$endtimestamp);
  
  add_configure($buildid,$start_time,$end_time,$command,$log,$status);
}

/** Parse the testing xml */
function parse_testing($parser,$projectid)
{
  include_once("common.php");

  $xmlarray = $parser->vals;
  $site = $parser->index["SITE"]; 
  $name = $parser->vals[$site[0]]["attributes"]["BUILDNAME"];
  $stamp = $parser->vals[$site[0]]["attributes"]["BUILDSTAMP"];

  // Find the build id
  $buildid = get_build_id($name,$stamp,$projectid);
  if($buildid<0)
    {
    $buildid = create_build($parser,$projectid);
    }

  $test_array = array();
  $index = 0;
  $getTimeNext = FALSE;
  $getDetailsNext = FALSE;
  $getSummaryNext = FALSE;
  $getImageNext = FALSE;
  $imageType = "";
  $imageRole = "";
  foreach($xmlarray as $tagarray)
    {
    $key = $tagarray["tag"];
    @$val = $tagarray["value"];
    if(($tagarray["tag"] == "TEST") && ($tagarray["level"] == 3) && isset($tagarray["attributes"]["STATUS"]))
      {
      $index++;
      $test_array[$index]["status"]=$tagarray["attributes"]["STATUS"];
      $test_array[$index]["images"] = array();
      }
    else if( ($tagarray["level"] == 5) && array_key_exists("attributes",$tagarray) 
            && ($tagarray["attributes"]["NAME"] == "Execution Time") )
      {
      $getTimeNext = TRUE;
      }
    else if( ($tagarray["level"] == 5) && array_key_exists("attributes",$tagarray) 
            && ($tagarray["attributes"]["NAME"] == "Exit Code") )
      {
      $getDetailsNext = TRUE;
      }
    else if( ($tagarray["level"] == 5) && ($tagarray["tag"] == "MEASUREMENT") )
      {
      $getSummaryNext = TRUE;
      }
    else if( ($tagarray["level"] == 5) && array_key_exists("attributes",$tagarray)
            && (strpos($tagarray["attributes"]["TYPE"], "image") !== FALSE) )
      {
      $getImageNext = TRUE;
      $imageType = $tagarray["attributes"]["TYPE"];
      $imageRole = $tagarray["attributes"]["NAME"];
      }
    else if( ($tagarray["level"] == 6) && $getTimeNext)
      {
      $test_array[$index]["executiontime"]=$tagarray["value"];
      $getTimeNext = FALSE;
      }
    else if( ($tagarray["level"] == 6) && $getDetailsNext)
      {
      $test_array[$index]["details"]=$tagarray["value"];
      $getDetailsNext = FALSE;
{'fraction_non_alphanumeric': 0.2125040889761204, 'fraction_numerical': 0.007441936539090612, 'mean_word_length': 3.741566498642885, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 44}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2705558', 'n_tokens_mistral': 8483, 'n_tokens_neox': 8416, 'n_words': 1374}