本文整理汇总了PHP中GetMedianRun函数的典型用法代码示例。如果您正苦于以下问题:PHP GetMedianRun函数的具体用法?PHP GetMedianRun怎么用?PHP GetMedianRun使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetMedianRun函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PruneDir
/**
* Remove all video directories except for the median run
*
* @param mixed $dir
*/
function PruneDir($dir)
{
global $count;
global $pruned;
$pruned++;
echo "\r{$count} ({$pruned}): Pruning {$dir} ";
$pageData = loadAllPageData($dir);
$fv = GetMedianRun($pageData, 0);
if ($fv) {
$keep = array();
$keep[0] = "video_{$fv}";
$rv = GetMedianRun($pageData, 1);
if ($rv) {
$keep[1] = "video_{$rv}_cached";
} else {
$keep[1] = '';
}
$f = scandir($dir);
foreach ($f as $file) {
if (!strncmp($file, 'video_', 6) && is_dir("{$dir}/{$file}")) {
$del = true;
if (!strcmp($file, $keep[0]) || !strcmp($file, $keep[1])) {
$del = false;
}
if ($del) {
RemoveDirectory("{$dir}/{$file}");
}
}
}
}
unset($pageData);
}
示例2: StatsdPostResult
function StatsdPostResult(&$test, $testPath)
{
require_once 'page_data.inc';
$runs = $test['runs'];
if (array_key_exists('discard', $test) && $test['discard'] > 0 && $test['discard'] <= $runs) {
$runs -= $test['discard'];
}
if ($runs) {
$pageData = loadAllPageData($testPath);
$medians = array(GetMedianRun($pageData, 0), GetMedianRun($pageData, 1));
if (isset($pageData) && is_array($pageData)) {
foreach ($pageData as $run => &$pageRun) {
foreach ($pageRun as $cached => &$testData) {
if (GetSetting('statsdPattern') && !preg_match('/' . GetSetting('statsdPattern') . '/', $test['label'])) {
continue;
}
if (GetSetting('statsdMedianOnly') && !($medians[$cached] == $run)) {
continue;
}
$graphData = array();
foreach ($testData as $metric => $value) {
if (is_float($value)) {
$value = intval($value);
}
if (is_int($value) && $metric != 'result') {
$graphData[$metric] = $value;
}
}
StatsdPost($test['location'], $test['browser'], $test['label'], $cached, $graphData);
}
}
}
}
}
示例3: GenerateHAR
/**
* Generate a HAR file for the given test
*
* @param mixed $testPath
*/
function GenerateHAR($id, $testPath, $options)
{
$json = '{}';
if (isset($testPath)) {
$pageData = null;
if (isset($options["run"]) && $options["run"]) {
if (!strcasecmp($options["run"], 'median')) {
$raw = loadAllPageData($testPath);
$run = GetMedianRun($raw, $options['cached'], $median_metric);
if (!$run) {
$run = 1;
}
unset($raw);
}
$pageData[$run] = array();
if (isset($options['cached'])) {
$pageData[$run][$options['cached']] = loadPageRunData($testPath, $run, $options['cached']);
if (!isset($pageData[$run][$options['cached']])) {
unset($pageData);
}
} else {
$pageData[$run][0] = loadPageRunData($testPath, $run, 0);
if (!isset($pageData[$run][0])) {
unset($pageData);
}
$pageData[$run][1] = loadPageRunData($testPath, $run, 1);
}
}
if (!isset($pageData)) {
$pageData = loadAllPageData($testPath);
}
// build up the array
$harData = BuildHAR($pageData, $id, $testPath, $options);
$json_encode_good = version_compare(phpversion(), '5.4.0') >= 0 ? true : false;
$pretty_print = false;
if (isset($options['pretty']) && $options['pretty']) {
$pretty_print = true;
}
if (isset($options['php']) && $options['php']) {
if ($pretty_print && $json_encode_good) {
$json = json_encode($harData, JSON_PRETTY_PRINT);
} else {
$json = json_encode($harData);
}
} elseif ($json_encode_good) {
if ($pretty_print) {
$json = json_encode($harData, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} else {
$json = json_encode($harData, JSON_UNESCAPED_UNICODE);
}
} else {
$jsonLib = new Services_JSON();
$json = $jsonLib->encode($harData);
}
}
return $json;
}
示例4: KeepMedianVideo
/**
* Delete all of the video files except for the median run
*
* @param mixed $id
*/
function KeepMedianVideo($testPath)
{
require_once 'page_data.inc';
$pageData = loadAllPageData($testPath);
$run = GetMedianRun($pageData, 0);
if ($run) {
$dir = opendir($testPath);
if ($dir) {
while ($file = readdir($dir)) {
$path = $testPath . "/{$file}/";
if (is_dir($path) && !strncmp($file, 'video_', 6) && $file != "video_{$run}") {
delTree("{$path}/");
}
}
closedir($dir);
}
}
}
示例5: xmlDomains
echo "<PageSpeedData>http://{$host}{$uri}/result/{$id}/{$fvMedian}_pagespeed.txt</PageSpeedData>\n";
} else {
echo "<PageSpeedData>http://{$host}{$uri}//getgzip.php?test={$id}&file={$fvMedian}_pagespeed.txt</PageSpeedData>\n";
}
}
xmlDomains($id, $testPath, $fvMedian, 0);
xmlBreakdown($id, $testPath, $fvMedian, 0);
xmlRequests($id, $testPath, $fvMedian, 0);
StatusMessages($id, $testPath, $fvMedian, 0);
ConsoleLog($id, $testPath, $fvMedian, 0);
echo "</firstView>\n";
if (isset($rv)) {
if (array_key_exists('rvmedian', $_REQUEST) && $_REQUEST['rvmedian'] == 'fv') {
$rvMedian = $fvMedian;
} else {
$rvMedian = GetMedianRun($pageData, 1, $median_metric);
}
if ($rvMedian) {
echo "<repeatView>\n";
echo "<run>{$rvMedian}</run>\n";
if (array_key_exists('testinfo', $test)) {
$tester = null;
if (array_key_exists('tester', $test['testinfo'])) {
$tester = $test['testinfo']['tester'];
}
if (array_key_exists('test_runs', $test['testinfo']) && array_key_exists($rvMedian, $test['testinfo']['test_runs']) && array_key_exists('tester', $test['testinfo']['test_runs'][$rvMedian])) {
$tester = $test['testinfo']['test_runs'][$rvMedian]['tester'] . '<br>';
}
if (isset($tester)) {
echo "<tester>" . xml_entities($tester) . "</tester>\n";
}
示例6: GetTestInfo
$info = GetTestInfo($test['id']);
if ($info) {
if (array_key_exists('discard', $info) && $info['discard'] >= 1 && array_key_exists('priority', $info) && $info['priority'] >= 1) {
$defaultInterval = 100;
}
$test['url'] = $info['url'];
}
$testInfo = parse_ini_file("./{$test['path']}/testinfo.ini", true);
if ($testInfo !== FALSE) {
if (array_key_exists('test', $testInfo) && array_key_exists('location', $testInfo['test'])) {
$test['location'] = $testInfo['test']['location'];
}
if (isset($testInfo['test']) && isset($testInfo['test']['completeTime'])) {
$test['done'] = true;
if (!array_key_exists('run', $test) || !$test['run']) {
$test['run'] = GetMedianRun($test['pageData'], $test['cached'], $median_metric);
}
$test['aft'] = array_key_exists('aft', $test['pageData'][$test['run']][$test['cached']]) ? $test['pageData'][$test['run']][$test['cached']]['aft'] : 0;
$loadTime = $test['pageData'][$test['run']][$test['cached']]['fullyLoaded'];
if (isset($loadTime) && (!isset($fastest) || $loadTime < $fastest)) {
$fastest = $loadTime;
}
// figure out the real end time (in ms)
if (isset($test['end'])) {
if (!strcmp($test['end'], 'visual') && array_key_exists('visualComplete', $test['pageData'][$test['run']][$test['cached']])) {
$test['end'] = $test['pageData'][$test['run']][$test['cached']]['visualComplete'];
} elseif (!strcmp($test['end'], 'doc')) {
$test['end'] = $test['pageData'][$test['run']][$test['cached']]['docTime'];
} elseif (!strncasecmp($test['end'], 'doc+', 4)) {
$test['end'] = $test['pageData'][$test['run']][$test['cached']]['docTime'] + (int) ((double) substr($test['end'], 4) * 1000.0);
} elseif (!strcmp($test['end'], 'full')) {
示例7: header
if (isset($_REQUEST['maxReqs']) && strlen($_REQUEST['maxReqs'])) {
$maxReqs = $_REQUEST['maxReqs'];
}
header("Content-disposition: attachment; filename={$id}_headersMatch.csv");
header("Content-type: text/csv");
// list of metrics that will be produced
// for each of these, the median, average and std dev. will be calculated
echo "\"Test ID\",\"Found\"\r\n";
// and now the actual data
foreach ($testIds as &$testId) {
$cached = 0;
RestoreTest($testId);
GetTestStatus($testId);
$testPath = './' . GetTestPath($testId);
$pageData = loadAllPageData($testPath);
$medianRun = GetMedianRun($pageData, $cached);
$secured = 0;
$haveLocations = 1;
$requests = getRequests($testId, $testPath, $medianRun, $cached, $secure, $haveLocations, false, true);
// Flag indicating if we matched
$matched = array();
$nSearches = count($searches);
$nRecords = count($requests);
if ($nRecords > $maxReqs && $maxReqs != 0) {
$nRecords = $maxReqs;
}
for ($rec = 0; $rec < $nRecords; $rec++) {
$r = $requests[$rec];
if (isset($r['headers']) && isset($r['headers']['response'])) {
foreach ($r['headers']['response'] as &$header) {
// Loop through the search conditions we received
示例8: foreach
}
}
foreach ($tests['variations'] as $variationIndex => &$variation) {
$urlVariation = CreateUrlVariation($url, $variation['q']);
echo "\"{$urlVariation}\",";
$id = $test['v'][$variationIndex];
RestoreTest($id);
GetTestStatus($id);
$testPath = './' . GetTestPath($id);
$pageData = loadAllPageData($testPath);
for ($cacheVal = 0; $cacheVal <= $cached; $cacheVal++) {
if (count($pageData)) {
$count = CountSuccessfulTests($pageData, $cacheVal);
echo "\"{$count}\",";
if ($use_median_run) {
$median_run = GetMedianRun($pageData, $cacheVal, $median_metric);
echo "\"{$median_run}\",";
}
foreach ($metrics as $metric => $metricLabel) {
if ($use_median_run) {
echo "\"{$pageData[$median_run][$cacheVal][$metric]}\",";
} else {
CalculateAggregateStats($pageData, $cacheVal, $metric, $median, $avg, $stdDev);
echo "\"{$median}\",\"{$avg}\",\"{$stdDev}\",";
}
}
} else {
echo '"",';
if ($use_median_run) {
echo '"",';
}
示例9: unlink
if (preg_match('/.*\\.test$/', $file)) {
unlink("{$testPath}/{$file}");
}
}
if (array_key_exists('job_file', $testInfo) && is_file($testInfo['job_file'])) {
unlink($testInfo['job_file']);
}
$perTestTime = 0;
$testCount = 0;
// do pre-complete post-processing
MoveVideoFiles($testPath);
WptHookPostProcessResults(__DIR__ . '/../' . $testPath);
if (!isset($pageData)) {
$pageData = loadAllPageData($testPath);
}
$medianRun = GetMedianRun($pageData, 0, $medianMetric);
$testInfo['medianRun'] = $medianRun;
$testInfo_dirty = true;
// delete all of the videos except for the median run?
if (array_key_exists('median_video', $ini) && $ini['median_video']) {
KeepVideoForRun($testPath, $medianRun);
}
$test = file_get_contents("{$testPath}/testinfo.ini");
$now = gmdate("m/d/y G:i:s", $time);
// update the completion time if it isn't already set
if (!strpos($test, 'completeTime')) {
$complete = "[test]\r\ncompleteTime={$now}";
if ($medianRun) {
$complete .= "\r\nmedianRun={$medianRun}";
}
$out = str_replace('[test]', $complete, $test);
示例10: RestoreTest
if ($p[0] == 's') {
$test['syncStartRender'] = (int) $p[1];
}
if ($p[0] == 'd') {
$test['syncDocTime'] = (int) $p[1];
}
if ($p[0] == 'f') {
$test['syncFullyLoaded'] = (int) $p[1];
}
}
}
RestoreTest($test['id']);
$test['path'] = GetTestPath($test['id']);
$test['pageData'] = loadAllPageData($test['path']);
if (!$test['run']) {
$test['run'] = GetMedianRun($test['pageData'], 0, $median_metric);
}
// figure out the real end time (in ms)
if (isset($test['end'])) {
if (!strcmp($test['end'], 'visual') && array_key_exists('visualComplete', $test['pageData'][$test['run']][$test['cached']])) {
$test['end'] = $test['pageData'][$test['run']][$test['cached']]['visualComplete'];
} elseif (!strcmp($test['end'], 'doc') || !strcmp($test['end'], 'docvisual')) {
if (!strcmp($test['end'], 'docvisual')) {
$test['extend'] = true;
$videoIdExtra .= 'e';
}
$test['end'] = $test['pageData'][$test['run']][$test['cached']]['docTime'];
} elseif (!strncasecmp($test['end'], 'doc+', 4)) {
$test['end'] = $test['pageData'][$test['run']][$test['cached']]['docTime'] + (int) ((double) substr($test['end'], 4) * 1000.0);
} elseif (!strcmp($test['end'], 'aft')) {
$test['end'] = $test['pageData'][$test['run']][$test['cached']]['aft'];
示例11: urldecode
if ($p[0] == 'r') {
$test['run'] = (int) $p[1];
}
if ($p[0] == 'l') {
$test['label'] = urldecode($p[1]);
}
if ($p[0] == 'c') {
$test['cached'] = (int) $p[1];
}
}
}
$test['path'] = GetTestPath($test['id']);
$test['pageData'] = loadAllPageData($test['path']);
BuildVideoScripts("./{$test['path']}");
if (!$test['run']) {
$test['run'] = GetMedianRun($test['pageData']);
}
$test['videoPath'] = "./{$test['path']}/video_{$test['run']}";
if ($test['cached']) {
$test['videoPath'] .= '_cached';
}
if (!strlen($test['label'])) {
$test['label'] = trim(file_get_contents("./{$test['path']}/label.txt"));
}
if (!strlen($test['label'])) {
$test['label'] = trim(file_get_contents("./{$test['path']}/url.txt"));
}
$labels[] = $test['label'];
if (is_dir($test['videoPath'])) {
$tests[] = $test;
}
示例12: foreach
foreach ($pageData as $run => $run_data) {
if ($run > $max_runs) {
$max_runs = $run;
}
if (isset($run_data[0]) && isset($run_data[0][$metric])) {
$fv[$run] = $run_data[0][$metric];
}
if (isset($run_data[1]) && isset($run_data[1][$metric])) {
$rv[$run] = $run_data[1][$metric];
}
}
$fvMedian = GetMedianRun($pageData, 0);
if ($fvMedian) {
$fvMedianValue = $pageData[$fvMedian][0][$metric];
}
$rvMedian = GetMedianRun($pageData, 1);
if ($rvMedian) {
$rvMedianValue = $pageData[$rvMedian][1][$metric];
}
}
function labelFormat($aLabel)
{
return number_format($aLabel);
}
if (count($fv)) {
include "lib/jpgraph/jpgraph.php";
include "lib/jpgraph/jpgraph_scatter.php";
include "lib/jpgraph/jpgraph_line.php";
JpGraphError::SetErrLocale('prod');
$graph = new Graph($width, $height);
$graph->SetScale("linlin", 0, 0, 1, $max_runs);
示例13: ParseTests
/**
* Parse the list of tests and identify the screen shots to compare
*
*/
function ParseTests()
{
$tests = array();
global $median_metric;
if (isset($_REQUEST['tests'])) {
$groups = explode(',', $_REQUEST['tests']);
foreach ($groups as $group) {
$parts = explode('-', $group);
if (count($parts) >= 1 && ValidateTestId($parts[0])) {
$test = array();
$test['id'] = $parts[0];
$test['cached'] = 0;
for ($i = 1; $i < count($parts); $i++) {
$p = explode(':', $parts[$i]);
if (count($p) >= 2) {
if ($p[0] == 'r') {
$test['run'] = (int) $p[1];
}
if ($p[0] == 'l') {
$test['label'] = $p[1];
}
if ($p[0] == 'c') {
$test['cached'] = (int) $p[1];
}
}
}
RestoreTest($test['id']);
$test['path'] = GetTestPath($test['id']);
if (!isset($test['run'])) {
$pageData = loadAllPageData($test['path']);
$test['run'] = GetMedianRun($pageData, $test['cached'], $median_metric);
}
if (!isset($test['label'])) {
$label = getLabel($test['id'], $user);
if (!empty($label)) {
$test['label'] = $new_label;
} else {
$info = GetTestInfo($test['id']);
if ($info && isset($info['label']) && strlen($info['label'])) {
$test['label'] = trim($info['label']);
}
}
}
if (!isset($test['label'])) {
$test['label'] = $test['id'];
}
$cachedText = '';
if ($test['cached']) {
$cachedText = '_Cached';
}
$fileBase = "{$test['path']}/{$test['run']}{$cachedText}_screen";
if (is_file("{$fileBase}.png")) {
$test['image'] = "{$fileBase}.png";
} elseif (is_file("{$fileBase}.jpg")) {
$test['image'] = "{$fileBase}.jpg";
}
if (isset($test['image'])) {
$size = getimagesize($test['image']);
if ($size && count($size) >= 2 && $size[0] > 0 && $size[1] > 0) {
$test['width'] = $size[0];
$test['height'] = $size[1];
$tests[] = $test;
}
}
}
}
}
if (!count($tests)) {
unset($tests);
}
return $tests;
}
示例14: foreach
foreach ($files as $file) {
if (preg_match('/.*\\.test$/', $file)) {
unlink("{$testPath}/{$file}");
}
}
if (array_key_exists('job_file', $testInfo) && is_file($testInfo['job_file'])) {
unlink($testInfo['job_file']);
}
$perTestTime = 0;
$testCount = 0;
// do pre-complete post-processing
MoveVideoFiles($testPath);
if (!isset($pageData)) {
$pageData = loadAllPageData($testPath);
}
$medianRun = GetMedianRun($pageData, 0);
$testInfo['medianRun'] = $medianRun;
$testInfo_dirty = true;
// delete all of the videos except for the median run?
if (array_key_exists('median_video', $ini) && $ini['median_video']) {
KeepVideoForRun($testPath, $medianRun);
}
$test = file_get_contents("{$testPath}/testinfo.ini");
$now = gmdate("m/d/y G:i:s", $time);
// update the completion time if it isn't already set
if (!strpos($test, 'completeTime')) {
$complete = "[test]\r\ncompleteTime={$now}";
if ($medianRun) {
$complete .= "\r\nmedianRun={$medianRun}";
}
$out = str_replace('[test]', $complete, $test);
示例15: notify
/**
* Send a mail notification to the user
*
* @param mixed $mailto
* @param mixed $id
* @param mixed $testPath
*/
function notify($mailto, $from, $id, $testPath, $host)
{
global $test;
// calculate the results
require_once 'page_data.inc';
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: {$from}\r\n";
$headers .= "Reply-To: {$from}";
$pageData = loadAllPageData($testPath);
$url = trim($pageData[1][0]['URL']);
$shorturl = substr($url, 0, 40);
if (strlen($url) > 40) {
$shorturl .= '...';
}
$subject = "Test results for {$shorturl}";
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($_SERVER['HTTP_SSL']) && $_SERVER['HTTP_SSL'] == 'On' ? 'https' : 'http';
if (!isset($host)) {
$host = $_SERVER['HTTP_HOST'];
}
$fv = GetMedianRun($pageData, 0);
if (isset($fv) && $fv) {
$load = number_format($pageData[$fv][0]['loadTime'] / 1000.0, 3);
$render = number_format($pageData[$fv][0]['render'] / 1000.0, 3);
$numRequests = number_format($pageData[$fv][0]['requests'], 0);
$bytes = number_format($pageData[$fv][0]['bytesIn'] / 1024, 0);
$result = "{$protocol}://{$host}/result/{$id}";
// capture the optimization report
require_once 'optimization.inc';
require_once 'object_detail.inc';
$secure = false;
$haveLocations = false;
$requests = getRequests($id, $testPath, 1, 0, $secure, $haveLocations, false);
ob_start();
dumpOptimizationReport($pageData[$fv][0], $requests, $id, 1, 0, $test);
$optimization = ob_get_contents();
ob_end_clean();
// build the message body
$body = "<html>\r\n <head>\r\n <title>{$subject}</title>\r\n <style type=\"text/css\">\r\n .indented1 {padding-left: 40pt;}\r\n .indented2 {padding-left: 80pt;}\r\n </style>\r\n </head>\r\n <body>\r\n <p>The full test results for <a href=\"{$url}\">{$url}</a> are now <a href=\"{$result}/\">available</a>.</p>\r\n <p>The page loaded in <b>{$load} seconds</b> with the user first seeing something on the page after <b>{$render} seconds</b>. To download \r\n the page required <b>{$numRequests} requests</b> and <b>{$bytes} KB</b>.</p>\r\n <p>Here is what the page looked like when it loaded (click the image for a larger view):<br><a href=\"{$result}/{$fv}/screen_shot/\"><img src=\"{$result}/{$fv}_screen_thumb.jpg\"></a></p>\r\n <h3>Here are the things on the page that could use improving:</h3>\r\n {$optimization}\r\n </body>\r\n </html>";
// send the actual mail
mail($mailto, $subject, $body, $headers);
}
}