$stmt =& $db->connection->prepare("SELECT SUM(count) AS total, device FROM Pageviews_by_Device WHERE day <= ? and day >= ? GROUP BY device ORDER BY total DESC", $types); $result = $stmt->execute(array($end_date_sql, $start_date_sql)); $all_data = $result->fetchAll(); foreach ($all_data as $data) { if (!($device = Device::$deviceEnglish[$data["device"]])) { $device = $data["device"]; } $traffic[$device] = $data["total"]; } $total = 0; foreach ($traffic as $count) { $total += $count; } $phone_traffic = array(); foreach ($traffic as $device => $count) { $phone_traffic[$device] = per_cent($count, $total); } // views by individual sections $popular_pages = array(); # grab all data by section between two dates $stmt =& $db->connection->prepare("SELECT SUM(count) AS total, section FROM Pageviews_by_Section WHERE day <= ? and day >= ? GROUP BY section ORDER BY total DESC", $types); $result = $stmt->execute(array($end_date_sql, $start_date_sql)); $all_data = $result->fetchAll(); foreach ($all_data as $data) { $section = $data["section"]; $config_file = $install_path . "web/" . $section . "/info.yml"; if (file_exists($config_file)) { $config = Spyc::YAMLLoad($config_file); $section = $config["name"]; } $popular_pages[$section] = $data["total"];
function bar_percentage($data, $title) { $new_data = array(); $total = array_sum(array_values($data)); foreach ($data as $key => $count) { $new_data[$key] = per_cent($count, $total); } return array("type" => "BAR-PERCENTAGE", "data" => $new_data, "title" => $title); }