Skip to content

Commit 9e255e6

Browse files
committed
add the pathname to the stats to differentiate tests. add grouping
1 parent e17e29b commit 9e255e6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

tests/speed/stats/index.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
<?php
22
$db = new PDO('sqlite:./stats.db');
3-
$db->query('CREATE TABLE IF NOT EXISTS stats (id INTEGER, agent TEXT, point TEXT, value REAL, time TIMESTAMP, PRIMARY KEY (id))');
3+
$db->query('CREATE TABLE IF NOT EXISTS stats (id INTEGER, agent TEXT, point TEXT, value REAL, time TIMESTAMP, pathname TEXT, PRIMARY KEY (id))');
44

55
// making a sad attempt here to provide a clean REST-respecting url scheme.
66
// stats with a GET returns - wait for it - the stats, and a post with the
77
// the right params will create a new entry
88
if ( $_SERVER['REQUEST_METHOD'] == "GET" ) {
99
$json = Array();
10-
$st = $db->prepare( 'SELECT agent, point, value, time FROM stats' );
10+
$st = $db->prepare( 'SELECT point, avg(value) as avg_value, pathname, strftime(\'%Y-%m-%d\', time) as day FROM stats GROUP BY pathname, point, strftime(\'%Y-%m-%d\', time);' );
1111
$st->execute();
1212
$result = $st->fetchAll(PDO::FETCH_ASSOC);
1313
header("Content-Type: application/json");
1414
echo json_encode($result);
15-
} elseif ( $_POST['datapoint'] && $_POST['value'] && $_POST['agent'] ) {
16-
$st = $db->prepare('INSERT INTO stats (agent, point, value, time) VALUES (:agent, :data_point, :value, DATETIME(\'now\'))');
15+
} elseif ( $_POST['datapoint'] && $_POST['value'] && $_POST['agent'] && $_POST['pathname']) {
16+
$st = $db->prepare('INSERT INTO stats (agent, point, value, pathname, time) VALUES (:agent, :data_point, :value, :pathname, DATETIME(\'now\'))');
1717
$st->execute(array(
1818
':agent' => $_POST['agent'],
1919
':data_point' => $_POST['datapoint'],
20-
':value' => $_POST['value']
20+
':value' => $_POST['value'],
21+
':pathname' => $_POST['pathname']
2122
));
2223

2324
echo "success";

tests/speed/stats/perf.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ window.Perf = (function($, Perf) {
99
report: function( data, after ) {
1010
var self = this;
1111

12+
data.pathname = location.pathname;
13+
1214
$.post( self.reportUrl, data, after );
1315
},
1416

0 commit comments

Comments
 (0)