PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/details/data_metric.php

http://showslow.googlecode.com/
PHP | 67 lines | 53 code | 14 blank | 0 comment | 9 complexity | 82c6a258028c5575bc804a7d2e8e8173 MD5 | raw file
 1<?php 
 2require_once(dirname(dirname(__FILE__)).'/global.php');
 3
 4if (!array_key_exists('url', $_GET) || filter_var($_GET['url'], FILTER_VALIDATE_URL) === false
 5	|| !array_key_exists('metric', $_GET) || !array_key_exists($_GET['metric'], $metrics)) {
 6	header('HTTP/1.0 400 Bad Request');
 7
 8	?><html>
 9<head>
10<title>Bad Request: no valid url specified</title>
11</head>
12<body>
13<h1>Bad Request: no valid url specified</h1>
14<p>You must pass valid URL as 'url' parameter</p>
15</body></html>
16<?php 
17	exit;
18}
19
20$query = sprintf("SELECT id FROM urls WHERE urls.url = '%s'", mysql_real_escape_string($_GET['url']));
21$result = mysql_query($query);
22
23if (!$result) {
24	error_log(mysql_error());
25}
26
27$row = mysql_fetch_assoc($result);
28$urlid = $row['id'];
29mysql_free_result($result);
30
31$query = sprintf("SELECT UNIX_TIMESTAMP(timestamp) AS t, value
32	FROM metric WHERE url_id = %d AND metric_id = %d AND timestamp > DATE_SUB(now(), INTERVAL 3 MONTH)
33	ORDER BY timestamp DESC",
34	mysql_real_escape_string($urlid),
35	mysql_real_escape_string($metrics[$_GET['metric']]['id'])
36);
37
38$result = mysql_query($query);
39
40if (!$result) {
41        error_log(mysql_error());
42}
43
44$data = array();
45
46header('Content-type: text/plain');
47if (array_key_exists('ver', $_GET)) {
48	header('Expires: '.date('r', time() + 315569260));
49	header('Cache-control: max-age=315569260');
50}
51echo '# Timestamp, '.$metrics[$_GET['metric']]['title'].' for '.$_GET['url']."\n";
52
53$rows = array();
54while ($row = mysql_fetch_assoc($result)) {
55	$rows[] = $row;
56}
57mysql_free_result($result);
58
59if (array_key_exists('smooth', $_REQUEST)) {
60	require_once(dirname(__FILE__).'/smooth.php');
61	smooth($rows, array('value'));
62}
63
64foreach ($rows as $row) {
65        echo date('c', $row['t']).','.$row['value']."\n";
66}
67