$consolidatedEndTime = date('Y-m-d H:i:s', time() - 59); while ($hostData = $res->fetch_array()) { // Need to find last minute entered, and that's time after which we want to start working on consolidation $lastEntry = $db->fetchOne("SELECT DATE_FORMAT(time, '%Y-%m-%d %H:%i') as `last_time` FROM `ping-summary` WHERE host_id = {$hostData['id']} ORDER BY id DESC LIMIT 1"); $consolidateStartTime = '2000-01-01 00:00'; if (!empty($lastEntry)) { $consolidateStartTime = $lastEntry['last_time']; } $q = "SELECT DATE_FORMAT(time, '%Y-%m-%d %H:%i') `minute` FROM `ping-result` WHERE host_id = {$hostData['id']} AND time > '{$consolidateStartTime}:59' AND time < '{$consolidatedEndTime}' GROUP BY DATE_FORMAT(time, '%Y-%m-%d %H:%i') ORDER BY id ASC"; $minutes = $db->query($q); while ($minute = $minutes->fetch_array()) { // echo "\rWorking on {$hostData['description']} ({$hostData['id']}) at {$minute[0]}..."; $q = "SELECT IFNULL(ping_ms, 1000) FROM `ping-result` WHERE host_id = {$hostData['id']} AND time BETWEEN '{$minute[0]}:00' AND '{$minute[0]}:59'"; $ping = $db->fetchCol($q); sort($ping); $q = "INSERT INTO `ping-summary` (time, host_id, min, max, avg, perc50, perc80, perc90, perc95, perc98, percent_timeout) VALUES\n ('{$minute[0]}:00', {$hostData['id']}, " . min($ping) . ", " . max($ping) . ", " . round(array_sum($ping) / count($ping), 1) . ", " . perc($ping, 50) . ", " . perc($ping, 80) . ", " . perc($ping, 90) . ", " . perc($ping, 95) . ", " . perc($ping, 98) . ", " . getTimeoutPercentage($ping) . ")"; $db->query($q); $q = "DELETE FROM `ping-result` WHERE host_id = {$hostData['id']} AND time BETWEEN '{$minute[0]}:00' AND '{$minute[0]}:59'"; $db->query($q); } // echo "\n"; } function perc($sortedArray, $percentile) { $idx = ceil($percentile * count($sortedArray) / 100) - 1; return $sortedArray[$idx]; } function getTimeoutPercentage($ping) { $values = array_count_values($ping); if (empty($values['1000.000'])) {
<td class="lower">' . perc($actual['1v1']['defend'] - $theor['1v1']['defend']) . '</td> <td class="lower">' . perc($actual['2v1']['defend'] - $theor['2v1']['defend']) . '</td> <td class="lower">' . perc($actual['3v1']['defend'] - $theor['3v1']['defend']) . '</td> </tr> <tr> <th colspan="1" rowspan="3">2</th> <th>Attack</th> <td>' . perc($actual['1v2']['attack'] - $theor['1v2']['attack']) . '</td> <td>' . perc($actual['2v2']['attack'] - $theor['2v2']['attack']) . '</td> <td>' . perc($actual['3v2']['attack'] - $theor['3v2']['attack']) . '</td> </tr> <tr class="alt"> <th>Defend</th> <td>' . perc($actual['1v2']['defend'] - $theor['1v2']['defend']) . '</td> <td>' . perc($actual['2v2']['defend'] - $theor['2v2']['defend']) . '</td> <td>' . perc($actual['3v2']['defend'] - $theor['3v2']['defend']) . '</td> </tr> <tr> <th>Both</th> <td> -- </td> <td>' . perc($actual['2v2']['both'] - $theor['2v2']['both']) . '</td> <td>' . perc($actual['3v2']['both'] - $theor['3v2']['both']) . '</td> </tr> </tbody> </table> '; // TODO: possibly add game stats ??? echo get_header($meta); echo get_item($contents, $hints, $meta['title']); call($GLOBALS); echo get_footer();