<commit_before><?php
/*
Copyright 2011 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

See the source code here:
     http://code.google.com/p/loadtimer/
*/

require_once("db.inc");

$gData = "blog";
$gRange = "createdate >= 1322599749 and createdate <= 1322606100";
if ( array_key_exists("data", $_GET) && "all" === $_GET["data"] ) {
	$gData = "all";
	$gRange = "createdate > 0";
}


$ghUrls = array(
				// no load "http://www.google.com/search?q=flowers",
				// no load "http://www.facebook.com/",
				"http://www.yahoo.com/" => "Yahoo",
				// no load "http://www.youtube.com/",
				"http://www.amazon.com/" => "Amazon",
				"http://en.wikipedia.org/wiki/Flowers" => "Wikipedia",
				// no load "http://www.twitter.com/",
				"http://www.craigslist.com/" => "Craigslist",
				"http://www.ebay.com/" => "eBay",
				"http://www.linkedin.com/" => "LinkedIn",
				"http://www.bing.com/search?q=flowers" => "Bing",
				"http://www.msn.com/" => "MSN",
				// framebuster "http://www.nytimes.com/",
				"http://www.engadget.com/" => "Engadget",
				"http://www.cnn.com/" => "CNN",
				"http://www.reddit.com/" => "Reddit"
				);

$ghExceptions = array();
$ghExceptions["Galaxy 7.0 SGH-T849"] = array();
$ghExceptions["Galaxy 7.0 SGH-T849"]["http://www.amazon.com/"] = 19;
$ghExceptions["Galaxy 7.0 SGH-T849"]["http://en.wikipedia.org/wiki/Flowers"] = 32;
$ghExceptions["Galaxy 7.0 SGH-T849"]["http://www.ebay.com/"] = 22;
$ghExceptions["Galaxy 7.0 SGH-T849"]["http://www.linkedin.com/"] = 2;
$ghExceptions["Galaxy 7.0 SGH-T849"]["http://www.bing.com/search?q=flowers"] = 7;
$ghExceptions["Galaxy 7.0 SGH-T849"]["http://www.cnn.com/"] = 20;
$ghExceptions["Galaxy 10.1 GT-P7510"] = array();
$ghExceptions["Galaxy 10.1 GT-P7510"]["http://www.linkedin.com/"] = 2;
$ghExceptions["Galaxy 10.1 GT-P7510"]["http://www.yahoo.com/"] = 46;
$ghExceptions["Silk (accel off) 1.1.0"] = array();
$ghExceptions["Silk (accel off) 1.1.0"]["http://www.yahoo.com/"] = 58;
$ghExceptions["Silk (accel off) 1.1.0"]["http://www.ebay.com/"] = 18;
$ghExceptions["Silk (accel on) 1.1.0"] = array();
$ghExceptions["Silk (accel on) 1.1.0"]["http://www.yahoo.com/"] = 58;
$ghExceptions["Silk (accel on) 1.1.0"]["http://www.ebay.com/"] = 18;
$ghExceptions["iPad 2 5.0"] = array();
$ghExceptions["iPad 2 5.0"]["http://www.yahoo.com/"] = 23;
$ghExceptions["iPad 1 5.0.1"] = array();
$ghExceptions["iPad 1 5.0.1"]["http://www.yahoo.com/"] = 60;

$ghResources = array();
$ghResources["http://www.yahoo.com/"] = 67;
$ghResources["http://www.amazon.com/"] = 43;
$ghResources["http://en.wikipedia.org/wiki/Flowers"] = 50;
$ghResources["http://www.craigslist.com/"] = 4;
$ghResources["http://www.ebay.com/"] = 64;
$ghResources["http://www.linkedin.com/"] = 11;
$ghResources["http://www.bing.com/search?q=flowers"] = 13;
$ghResources["http://www.msn.com/"] = 47;
$ghResources["http://www.engadget.com/"] = 215;
$ghResources["http://www.cnn.com/"] = 124;
$ghResources["http://www.reddit.com/"] = 21;



// list of browsers
$gaBrowsers = array();

if ( array_key_exists("comparesel", $_GET) ) {
	$aKeys = array_keys($_GET);
	foreach($aKeys as $key) {
		if ( 0 === strpos($key, "b_") ) {
			$gaBrowsers[] = $_GET[$key];
		}
	}
}

if ( 0 === count($gaBrowsers) ) {
	$query = "select browser from $gBeaconsTable where $gRange group by browser order by browser;";
	$result = doQuery($query);
	while ($row = mysql_fetch_assoc($result)) {
		$browser = $row['browser'];
		$gaBrowsers[] = $browser;
	}
	mysql_free_result($result);
}


// table column headers
$sTH = "<tr> <th>browser</th> ";
$aUrls = array_keys($ghUrls);
foreach($aUrls as $url) {
	$sTH .= "<th class=sortnum><a href='$url' target='_blank'>" . $ghUrls[$url] . "</a></th> ";
}
$sTH .= "<th class=sortnum>&#35; data</th>" . "</tr>\n";


// track min & max (initialize values for each URL)
$ghMin = array();
$ghMax = array();
foreach($aUrls as $url) {
	$ghMin[$url] = 9999999;
	$ghMax[$url] = 0;
}

$ghMedians = array();
foreach($gaBrowsers as $browser) {
	$ghMedians[$browser] = array();
	foreach($aUrls as $url) {
		$num = doSimpleQuery("select count(loadtime) as num from $gBeaconsTable where browser='$browser' and url='$url' and $gRange;");
		if ( $num > 0 ) {
			$median = doSimpleQuery("select loadtime as median from $gBeaconsTable where browser='$browser' and url='$url' and $gRange order by loadtime asc limit " .
									floor(($num-1)/2) . ",1;");
			$ghMedians[$browser][$url] = $median;
			if ( array_key_exists($browser, $ghExceptions) && array_key_exists($url, $ghExceptions[$browser]) ) {
				// don't let exceptions take the min
			}
			else if ( $median < $ghMin[$url] ) {
				$ghMin[$url] = $median;
			}
			if ( $median > $ghMax[$url] ) {
				$ghMax[$url] = $median;
			}
		}
	}
	$ghMedians[$browser]['num'] = $num;   // bogus if URLs have different # of beacons
}


$sRows = "";
$iBrowser = 0;
foreach($gaBrowsers as $browser) {
	$iBrowser++;
	$sRow = "<tr> <td class=browser><input type=checkbox name='b_$iBrowser' value='$browser' checked> $browser</td> ";
	foreach($aUrls as $url) {
		$median = $ghMedians[$browser][$url];
		$class = "sortnum";
		if ( intval($median) < intval($ghMin[$url]) ) {
			$class .= " minexc";
		}
		else if ( intval($median) == intval($ghMin[$url]) ) {
			$class .= " min";
		}
		else if ( intval($median) == intval($ghMax[$url]) ) {
			$class .= " max";
		}
		else {
			$class .= " num";
		}
		$data = "";
		if ( $median ) {
			$data = commaize($median) . "<br>(" .
				( array_key_exists($browser, $ghExceptions) && array_key_exists($url, $ghExceptions[$browser]) ? 
				  $ghExceptions[$browser][$url] : $ghResources[$url] ) . ")";
		}
		$sRow .= "<td class='$class" . ( array_key_exists($browser, $ghExceptions) && array_key_exists($url, $ghExceptions[$browser]) ? " exc" : "" ) . "'>" . 
			$data . "</td> ";
	}
	$num = $ghMedians[$browser]['num'];
	$sRow .= "<td class='sortnum'>$num</td> " . "</tr>\n";
	if ( $num ) {
		$sRows .= $sRow;
	}
}

// add commas to a big number
function commaize($num) {
	$sNum = "$num";
	$len = strlen($sNum);

	if ( $len <= 3 ) {
		return $sNum;
	}

	return commaize(substr($sNum, 0, $len-3)) . "," . substr($sNum, $len-3);
}
?>
<!doctype html>
<html>
<head>
<title>Loadtimer Results</title><commit_msg>looks like I broke the gray bg styling when I abbreviated the UA names. fix it.<commit_after><?php
/*
Copyright 2011 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

See the source code here:
     http://code.google.com/p/loadtimer/
*/

require_once("db.inc");

$gData = "blog";
$gRange = "createdate >= 1322599749 and createdate <= 1322606100";
if ( array_key_exists("data", $_GET) && "all" === $_GET["data"] ) {
	$gData = "all";
	$gRange = "createdate > 0";
}


$ghUrls = array(
				// no load "http://www.google.com/search?q=flowers",
				// no load "http://www.facebook.com/",
				"http://www.yahoo.com/" => "Yahoo",
				// no load "http://www.youtube.com/",
				"http://www.amazon.com/" => "Amazon",
				"http://en.wikipedia.org/wiki/Flowers" => "Wikipedia",
				// no load "http://www.twitter.com/",
				"http://www.craigslist.com/" => "Craigslist",
				"http://www.ebay.com/" => "eBay",
				"http://www.linkedin.com/" => "LinkedIn",
				"http://www.bing.com/search?q=flowers" => "Bing",
				"http://www.msn.com/" => "MSN",
				// framebuster "http://www.nytimes.com/",
				"http://www.engadget.com/" => "Engadget",
				"http://www.cnn.com/" => "CNN",
				"http://www.reddit.com/" => "Reddit"
				);

$ghExceptions = array();
$ghExceptions["Galaxy 7.0 SGH-T849"] = array();
$ghExceptions["Galaxy 7.0 SGH-T849"]["http://www.amazon.com/"] = 19;
$ghExceptions["Galaxy 7.0 SGH-T849"]["http://en.wikipedia.org/wiki/Flowers"] = 32;
$ghExceptions["Galaxy 7.0 SGH-T849"]["http://www.ebay.com/"] = 22;
$ghExceptions["Galaxy 7.0 SGH-T849"]["http://www.linkedin.com/"] = 2;
$ghExceptions["Galaxy 7.0 SGH-T849"]["http://www.bing.com/search?q=flowers"] = 7;
$ghExceptions["Galaxy 7.0 SGH-T849"]["http://www.cnn.com/"] = 20;
$ghExceptions["Galaxy 7"] = array();
$ghExceptions["Galaxy 7"]["http://www.amazon.com/"] = 19;
$ghExceptions["Galaxy 7"]["http://en.wikipedia.org/wiki/Flowers"] = 32;
$ghExceptions["Galaxy 7"]["http://www.ebay.com/"] = 22;
$ghExceptions["Galaxy 7"]["http://www.linkedin.com/"] = 2;
$ghExceptions["Galaxy 7"]["http://www.bing.com/search?q=flowers"] = 7;
$ghExceptions["Galaxy 7"]["http://www.cnn.com/"] = 20;

$ghExceptions["Galaxy 10.1 GT-P7510"] = array();
$ghExceptions["Galaxy 10.1 GT-P7510"]["http://www.linkedin.com/"] = 2;
$ghExceptions["Galaxy 10.1 GT-P7510"]["http://www.yahoo.com/"] = 46;
$ghExceptions["Galaxy 10"] = array();
$ghExceptions["Galaxy 10"]["http://www.linkedin.com/"] = 2;
$ghExceptions["Galaxy 10"]["http://www.yahoo.com/"] = 46;

$ghExceptions["Silk (accel off) 1.1.0"] = array();
$ghExceptions["Silk (accel off) 1.1.0"]["http://www.yahoo.com/"] = 58;
$ghExceptions["Silk (accel off) 1.1.0"]["http://www.ebay.com/"] = 18;
$ghExceptions["Silk (accel on) 1.1.0"] = array();
$ghExceptions["Silk (accel on) 1.1.0"]["http://www.yahoo.com/"] = 58;
$ghExceptions["Silk (accel on) 1.1.0"]["http://www.ebay.com/"] = 18;
$ghExceptions["Silk (accel off) 1"] = array();
$ghExceptions["Silk (accel off) 1"]["http://www.yahoo.com/"] = 58;
$ghExceptions["Silk (accel off) 1"]["http://www.ebay.com/"] = 18;
$ghExceptions["Silk (accel on) 1"] = array();
$ghExceptions["Silk (accel on) 1"]["http://www.yahoo.com/"] = 58;
$ghExceptions["Silk (accel on) 1"]["http://www.ebay.com/"] = 18;

$ghExceptions["iPad 2 5.0"] = array();
$ghExceptions["iPad 2 5.0"]["http://www.yahoo.com/"] = 23;
$ghExceptions["iPad 2 5"] = array();
$ghExceptions["iPad 2 5"]["http://www.yahoo.com/"] = 23;

$ghExceptions["iPad 1 5.0.1"] = array();
$ghExceptions["iPad 1 5.0.1"]["http://www.yahoo.com/"] = 60;
$ghExceptions["iPad 1 5"] = array();
$ghExceptions["iPad 1 5"]["http://www.yahoo.com/"] = 60;

$ghResources = array();
$ghResources["http://www.yahoo.com/"] = 67;
$ghResources["http://www.amazon.com/"] = 43;
$ghResources["http://en.wikipedia.org/wiki/Flowers"] = 50;
$ghResources["http://www.craigslist.com/"] = 4;
$ghResources["http://www.ebay.com/"] = 64;
$ghResources["http://www.linkedin.com/"] = 11;
$ghResources["http://www.bing.com/search?q=flowers"] = 13;
$ghResources["http://www.msn.com/"] = 47;
$ghResources["http://www.engadget.com/"] = 215;
$ghResources["http://www.cnn.com/"] = 124;
$ghResources["http://www.reddit.com/"] = 21;



// list of browsers
$gaBrowsers = array();

if ( array_key_exists("comparesel", $_GET) ) {
	$aKeys = array_keys($_GET);
	foreach($aKeys as $key) {
		if ( 0 === strpos($key, "b_") ) {
			$gaBrowsers[] = $_GET[$key];
		}
	}
}

if ( 0 === count($gaBrowsers) ) {
	$query = "select browser from $gBeaconsTable where $gRange group by browser order by browser;";
	$result = doQuery($query);
	while ($row = mysql_fetch_assoc($result)) {
		$browser = $row['browser'];
		$gaBrowsers[] = $browser;
	}
	mysql_free_result($result);
}


// table column headers
$sTH = "<tr> <th>browser</th> ";
$aUrls = array_keys($ghUrls);
foreach($aUrls as $url) {
	$sTH .= "<th class=sortnum><a href='$url' target='_blank'>" . $ghUrls[$url] . "</a></th> ";
}
$sTH .= "<th class=sortnum>&#35; data</th>" . "</tr>\n";


// track min & max (initialize values for each URL)
$ghMin = array();
$ghMax = array();
foreach($aUrls as $url) {
	$ghMin[$url] = 9999999;
	$ghMax[$url] = 0;
}

$ghMedians = array();
foreach($gaBrowsers as $browser) {
	$ghMedians[$browser] = array();
	foreach($aUrls as $url) {
		$num = doSimpleQuery("select count(loadtime) as num from $gBeaconsTable where browser='$browser' and url='$url' and $gRange;");
		if ( $num > 0 ) {
			$median = doSimpleQuery("select loadtime as median from $gBeaconsTable where browser='$browser' and url='$url' and $gRange order by loadtime asc limit " .
									floor(($num-1)/2) . ",1;");
			$ghMedians[$browser][$url] = $median;
			if ( array_key_exists($browser, $ghExceptions) && array_key_exists($url, $ghExceptions[$browser]) ) {
				// don't let exceptions take the min
			}
			else if ( $median < $ghMin[$url] ) {
				$ghMin[$url] = $median;
			}
			if ( $median > $ghMax[$url] ) {
				$ghMax[$url] = $median;
			}
		}
	}
	$ghMedians[$browser]['num'] = $num;   // bogus if URLs have different # of beacons
}


$sRows = "";
$iBrowser = 0;
foreach($gaBrowsers as $browser) {
	$iBrowser++;
	$sRow = "<tr> <td class=browser><input type=checkbox name='b_$iBrowser' value='$browser' checked> $browser</td> ";
	foreach($aUrls as $url) {
		$median = $ghMedians[$browser][$url];
		$class = "sortnum";
		if ( intval($median) < intval($ghMin[$url]) ) {
			$class .= " minexc";
		}
		else if ( intval($median) == intval($ghMin[$url]) ) {
			$class .= " min";
		}
		else if ( intval($median) == intval($ghMax[$url]) ) {
			$class .= " max";
		}
		else {
			$class .= " num";
		}
		$data = "";
		if ( $median ) {
			$data = commaize($median) . "<br>(" .
				( array_key_exists($browser, $ghExceptions) && array_key_exists($url, $ghExceptions[$browser]) ? 
				  $ghExceptions[$browser][$url] : $ghResources[$url] ) . ")";
		}
		$sRow .= "<td class='$class" . ( array_key_exists($browser, $ghExceptions) && array_key_exists($url, $ghExceptions[$browser]) ? " exc" : "" ) . 
			"'>" . "$data</td> ";
	}
	$num = $ghMedians[$browser]['num'];
	$sRow .= "<td class='sortnum'>$num</td> " . "</tr>\n";
	if ( $num ) {
		$sRows .= $sRow;
	}
}

// add commas to a big number
function commaize($num) {
	$sNum = "$num";
	$len = strlen($sNum);

	if ( $len <= 3 ) {
		return $sNum;
	}

	return commaize(substr($sNum, 0, $len-3)) . "," . substr($sNum, $len-3);
}
?>
<!doctype html>
<html>
<head>
<title>Loadtimer Results</title>
{'fraction_non_alphanumeric': 0.23043120021971986, 'fraction_numerical': 0.029112881076627302, 'mean_word_length': 4.022413793103448, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 91, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5642366', 'n_tokens_mistral': 6283, 'n_tokens_neox': 5694, 'n_words': 1145}