</table> <?php print "Opening Shifts: {$openings}<br/>\n"; print "Closing Shifts: {$closings}<br/>\n"; print "Midday Shifts: {$middays}<br/>\n"; print "Cash Shifts: {$cashshifts}<br/>\n"; print "Total Shifts: " . ($openings + $closings + $middays) . "<br/>\n"; print "Total Scouts: {$totalscouts}<br/>\n"; print "Total Adults: {$totaladults}<br/>\n"; print "Total People-Shifts: " . ($totalscouts + $totaladults) . "<br/>\n"; print "<pre>\n"; print_r($troopdata); print_r($sheetdata); print "</pre>\n"; foreach ($troops as $key => $value) { print_stats($key, $troopdata); } $mysqli = db_connect(); if ($mysqli === FALSE) { print "<b>Unable to load database</b><br/>\n"; } foreach ($sheetdata as $key => $value) { $query = "INSERT INTO shifts (id, start, end, description, scouts, adults, troop, type) VALUES ("; $query .= $value['shift'] . ", "; $query .= "'" . $value['date'] . " " . $value['start'] . "', "; $query .= "'" . $value['date'] . " " . $value['end'] . "', "; $query .= "'" . $value['desc'] . "', "; $query .= $value['scouts'] . ", "; $query .= $value['adults'] . ", "; $query .= $value['troop'] . ", "; $query .= $value['type'] . ");";
$con = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); if ($con->connect_errno > 0) { die("Failed to connect to MySQL: " . $con->connect_error); } function print_stats($con, $id, $table, $title) { if (!($res = $con->query("SELECT sd.name AS name, s.value AS value FROM {$table} AS s JOIN stats_definitions sd ON sd.id = s.stats_id WHERE player_id = {$id};"))) { die('There was an error running the query [' . $con->error . ']'); } echo "<table border=1 style=\"display: inline-block;\">"; echo "<tr><td colspan=2 align=\"center\">{$title}</td></tr>"; echo "<tr><td>Statistics</td><td>Value</td></tr>"; while ($row = $res->fetch_assoc()) { echo "<tr><td>" . $row['name'] . "</td><td>" . $row['value'] . "</td></tr>"; } echo "</table>"; } if (isset($_POST['submit'])) { $user = $_POST['user']; if (!($res = $con->query("SELECT id FROM users WHERE name = '{$user}'"))) { die('There was an error running the query [' . $con->error . ']'); } if ($res->num_rows != 0) { $row = $res->fetch_assoc(); $id = $row['id']; print_stats($con, $id, "stats_global", "Global statistics"); print_stats($con, $id, "stats_current", "Stats for last session"); } else { echo "No stats for user {$user}."; } }
/** * Creates an index and prints out seperate tables * for each index. * For example, to print all users individual resource usage, * this function takes all the resource ids and loops through them, * calculating the number of reservations per resource and printing * a table for each one * @param none */ function print_multiple_stats() { if (!$this->dynlabel) { // Only print all when we are not using dynamic labels $this->graph_title = $this->dyn_title . ' ' . translate('[All Reservations]'); print_stats($this, 'all'); // Print all first } foreach ($this->index as $k => $v) { if ($this->dynlabel) { // Call dynamic label handler eval('$this->' . $this->lbl_fnc . '($k);'); } $this->total = isset($this->dyntot[$k]) ? $this->dyntot[$k] : 0; // Set the total $this->graph_title = $this->dyn_title . ' ' . translate('for') . ' ' . $v; // Set the title print_stats($this, $k); // Print the graph } }
$stats = array('*sum' => $first); foreach (file($file) as $line) { //r5887 | buildmob | 2011-08-23 13:08:25 -0700 (Tue, 23 Aug 2011) | 4 lines if (count(list($r, $u, $d, $n) = explode(' | ', $line)) < 4) { continue; } if ($stats[$u]) { $stats[$u]['commits']++; $stats[$u]['lines'] += (int) $n; $stats['*sum']['commits']++; $stats['*sum']['lines'] += (int) $n; } else { $stats[$u] = $first; } } return $stats; } function print_stats(array $stats, $sortby) { print "users commits commit% lines line% (sorted by {$sortby})\n"; print "------- ------- ------- ----- -------\n"; uasort($stats, function ($a, $b) use($sortby) { return $b[$sortby] - $a[$sortby]; }); foreach ($stats as $user => $stat) { printf("% -10s% 6d% 8.1f%%% 7d% 8.1f%%\n", $user, $stat['commits'], $stat['commits'] / $stats['*sum']['commits'] * 100, $stat['lines'], $stat['lines'] / $stats['*sum']['lines'] * 100); } print "\n"; } print_stats(get_stats('php://stdin'), $argc > 1 ? 'lines' : 'commits');