/** * Gather all of the data for a given test and return it as an array * * @param mixed $id */ function GetTestResult($id) { global $url; global $median_metric; $testPath = './' . GetTestPath($id); $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($_SERVER['HTTP_SSL']) && $_SERVER['HTTP_SSL'] == 'On' ? 'https' : 'http'; $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $path = substr($testPath, 1); $pageData = loadAllPageData($testPath); $stats = array(0 => array(), 1 => array()); $pageStats = calculatePageStats($pageData, $stats[0], $stats[1]); if (!strlen($url)) { $url = $pageData[1][0]['URL']; } $testInfo = GetTestInfo($id); if (is_file("{$testPath}/testinfo.ini")) { $test = parse_ini_file("{$testPath}/testinfo.ini", true); } $fvOnly = false; if (!count($stats[1])) { $fvOnly = true; } $cacheLabels = array('firstView', 'repeatView'); // summary information $ret = array('id' => $id, 'url' => $url, 'summary' => "{$protocol}://{$host}{$uri}/results.php?test={$id}"); $runs = max(array_keys($pageData)); if (isset($testInfo)) { if (array_key_exists('url', $testInfo) && strlen($testInfo['url'])) { $ret['testUrl'] = $testInfo['url']; } if (array_key_exists('location', $testInfo) && strlen($testInfo['location'])) { $locstring = $testInfo['location']; if (array_key_exists('browser', $testInfo) && strlen($testInfo['browser'])) { $locstring .= ':' . $testInfo['browser']; } $ret['location'] = $locstring; } if (isset($test) && array_key_exists('test', $test) && is_array($test['test']) && array_key_exists('location', $test['test']) && strlen($test['test']['location'])) { $ret['from'] = $test['test']['location']; } if (array_key_exists('connectivity', $testInfo) && strlen($testInfo['connectivity'])) { $ret['connectivity'] = $testInfo['connectivity']; } if (array_key_exists('bwIn', $testInfo)) { $ret['bwDown'] = $testInfo['bwIn']; } if (array_key_exists('bwOut', $testInfo)) { $ret['bwUp'] = $testInfo['bwOut']; } if (array_key_exists('latency', $testInfo)) { $ret['latency'] = $testInfo['latency']; } if (array_key_exists('plr', $testInfo)) { $ret['plr'] = $testInfo['plr']; } if (array_key_exists('label', $testInfo) && strlen($testInfo['label'])) { $ret['label'] = $testInfo['label']; } if (array_key_exists('completed', $testInfo)) { $ret['completed'] = $testInfo['completed']; } if (array_key_exists('tester', $testInfo) && strlen($testInfo['tester'])) { $ret['tester'] = $testInfo['tester']; } if (array_key_exists('testerDNS', $testInfo) && strlen($testInfo['testerDNS'])) { $ret['testerDNS'] = $testInfo['testerDNS']; } if (array_key_exists('runs', $testInfo) && $testInfo['runs']) { $runs = $testInfo['runs']; } if (array_key_exists('fvonly', $testInfo)) { $fvOnly = $testInfo['fvonly'] ? true : false; } } $cachedMax = 0; if (!$fvOnly) { $cachedMax = 1; } $ret['runs'] = $runs; $ret['fvonly'] = $fvOnly; $ret['successfulFVRuns'] = CountSuccessfulTests($pageData, 0); if (!$fvOnly) { $ret['successfulRVRuns'] = CountSuccessfulTests($pageData, 1); } // average // check if removing average $addAverage = 1; if (isset($_GET['average'])) { if ($_GET['average'] == 0) { $addAverage = 0; } } // add average if ($addAverage == 1) { $ret['average'] = array(); for ($cached = 0; $cached <= $cachedMax; $cached++) { $label = $cacheLabels[$cached]; $ret['average'][$label] = $stats[$cached]; } } // standard deviation // check if removing standard deviation $addStandard = 1; if (isset($_GET['standard'])) { if ($_GET['standard'] == 0) { $addStandard = 0; } } // add standard deviation if ($addStandard == 1) { $ret['standardDeviation'] = array(); for ($cached = 0; $cached <= $cachedMax; $cached++) { $label = $cacheLabels[$cached]; $ret['standardDeviation'][$label] = array(); foreach ($stats[$cached] as $key => $val) { $ret['standardDeviation'][$label][$key] = PageDataStandardDeviation($pageData, $key, $cached); } } } // median // check if removing median $addMedian = 1; if (isset($_GET['median'])) { if ($_GET['median'] == 0) { $addMedian = 0; } } // add median if ($addMedian == 1) { $ret['median'] = array(); for ($cached = 0; $cached <= $cachedMax; $cached++) { $label = $cacheLabels[$cached]; $medianRun = GetMedianRun($pageData, $cached, $median_metric); if (array_key_exists($medianRun, $pageData)) { $ret['median'][$label] = GetSingleRunData($id, $testPath, $medianRun, $cached, $pageData, $testInfo); } } } // runs // check if removing runs $addRuns = 1; if (isset($_GET['runs'])) { if ($_GET['runs'] == 0) { $addRuns = 0; } } // add runs if ($addRuns == 1) { $ret['runs'] = array(); for ($run = 1; $run <= $runs; $run++) { $ret['runs'][$run] = array(); for ($cached = 0; $cached <= $cachedMax; $cached++) { $label = $cacheLabels[$cached]; $ret['runs'][$run][$label] = GetSingleRunData($id, $testPath, $run, $cached, $pageData, $testInfo); } } } ArchiveApi($id); return $ret; }
} echo "</repeatView>\n"; } echo "</average>\n"; echo "<standardDeviation>\n"; echo "<firstView>\n"; foreach ($fv as $key => $val) { $key = preg_replace('/[^a-zA-Z0-9\\.\\-_]/', '_', $key); echo "<{$key}>" . PageDataStandardDeviation($pageData, $key, 0) . "</{$key}>\n"; } echo "</firstView>\n"; if (isset($rv)) { echo "<repeatView>\n"; foreach ($rv as $key => $val) { $key = preg_replace('/[^a-zA-Z0-9\\.\\-_]/', '_', $key); echo "<{$key}>" . PageDataStandardDeviation($pageData, $key, 1) . "</{$key}>\n"; } echo "</repeatView>\n"; } echo "</standardDeviation>\n"; // output the median run data $fvMedian = GetMedianRun($pageData, 0, $median_metric); if ($fvMedian) { echo "<median>\n"; echo "<firstView>\n"; echo "<run>{$fvMedian}</run>\n"; if (array_key_exists('testinfo', $test)) { $tester = null; if (array_key_exists('tester', $test['testinfo'])) { $tester = $test['testinfo']['tester']; }