query('SELECT seq, qp FROM `2b2q_log` ORDER BY id DESC LIMIT 1')->fetchArray(); $seq = $ret[0]; $last_qp = $ret[1]; if ($last_qp < $qp) { $seq++; } $stmt = $db->prepare('INSERT INTO `2b2q_log` (seq, ts, qp) VALUES (:seq, :ts, :qp)'); $stmt->bindValue(':seq', $seq); $stmt->bindValue(':ts', $ts); $stmt->bindValue(':qp', $qp); $stmt->execute(); header('HTTP/1.0 204 No Content'); } else { // stats mode $now = time(); $last_seq = $db->query('SELECT seq FROM `2b2q_log` ORDER BY id DESC LIMIT 1')->fetchArray()[0]; $ret = $db->query("SELECT MIN(id), MAX(id) FROM `2b2q_log` WHERE seq = $last_seq")->fetchArray(); $first_id = $ret[0]; $last_id = $ret[1]; if ($first_id == $last_id) { die('Insufficient data'); } $ret = $db->query("SELECT ts, qp FROM `2b2q_log` WHERE id = $first_id")->fetchArray(); $initial_ts = $ret[0]; $initial_qp = $ret[1]; $ret = $db->query("SELECT ts, qp FROM `2b2q_log` WHERE id = $last_id")->fetchArray(); $current_ts = $ret[0]; $current_qp = $ret[1]; // don't divide by zero dummy if ($initial_ts == $current_ts || $initial_qp == $current_qp) { die('Insufficient data'); } // linear regression using only two points isn't that great, the head of the queue moves slower $est_total_wait = $current_qp * ($current_ts - $initial_ts) / ($initial_qp - $current_qp); $est_remaining_wait = $initial_ts + $est_total_wait - $now; if ($est_remaining_wait < 0) { $est_remaining_wait = 0; } ?>
Last update: = date(DATE_RFC1123, $current_ts); ?>
Queue position: = $current_qp ?>
Estimated wait time: = round($est_remaining_wait / 60) ?> minutes
close();