public static function getRideCountReportData($report, $userId, $bikeId, $rideId, $fromDate, $toDate) { $dateFormat = '%v'; $datasetName = 'Weekly Total'; $week = true; if ($report == 7) { //month query $dateFormat = '%M'; $datasetName = 'Monthly Total'; $week = false; } $weekAvg = array(); $avg = array(); $connection = Propel::getConnection(); $query = "select date_FORMAT(us.ride_date,'%x') as year, date_FORMAT(us.ride_date,'" . $dateFormat . "') as weekinyear, count(us.ride_key) as ridecount from user_stats us where us.user_id=? and date_FORMAT(us.RIDE_DATE,'%Y%m%d')>=? and date_FORMAT(us.RIDE_DATE,'%Y%m%d')<=? "; $bikeclause = " and us.bike_id=" . $bikeId; $rideclaue = " and us.ride_key=" . $rideId; $groupclause = " group by weekinyear order by 1,2 asc"; if ($bikeId && $bikeId >= 0) { $query = $query . $bikeclause; } if ($rideId && $rideId >= 0) { $query = $query . $rideclaue; } $query = $query . $groupclause; sfContext::getInstance()->getLogger()->info('@@@@@@@@@@@@@@@executing Time query ' . $query); $statement = $connection->prepare($query); $statement->bindValue(1, $userId); $statement->bindValue(2, date("Ymd", strtotime($fromDate))); $statement->bindValue(3, date("Ymd", strtotime($toDate))); $resultset = $statement->execute(); $count = 0; $total = 0; while ($row = $statement->fetch()) { $rideCount = $row['ridecount']; $weekInYear = $row['weekinyear']; $year = $row['year']; $display = $weekInYear; if ($week) { $display = reportQueries::getStartOfWeekFromWeekYear($weekInYear, $year); } $display = $display . "-" . $year; $weekAvg[$display] = $rideCount; $avg[$display] = 0; $total = $total + $rideCount; $count++; } //go through and set avg if ($count > 0) { $average = $total / $count; } else { $average = 0; } foreach (array_keys($weekAvg) as $a) { $avg[$a] = $average; } $return = array($datasetName => $weekAvg, 'Average' => $avg); return $return; }
private function createNumberRidesGraph($barChart, $threeD, $report, $userId, $bikeId, $rideId, $fromDate, $toDate) { if ($barChart) { $graph = new ezcGraphBarChart(); } else { $graph = new ezcGraphLineChart(); } if ($threeD) { $graph->renderer = new ezcGraphRenderer3d(); } $graph->title = 'Number of Rides'; $graphData = reportQueries::getRideCountReportData($report, $userId, $bikeId, $rideId, $fromDate, $toDate); // Add data foreach ($graphData as $cat => $data) { $graph->data[$cat] = new ezcGraphArrayDataSet($data); } $graph->data['Average']->displayType = ezcGraph::LINE; $graph->options->fillLines = 210; $title = 'images/charts/NumberRidesGraph_' . $userId . '.svg'; $graph->render(650, 350, $title); return $title; }
private function createElevationGraph($userId, $userRideId) { $graph = new ezcGraphLineChart(); $graph->title = 'Elevation Graph'; $graphData = reportQueries::getElevationReportDate($userRideId); //echo var_dump($graphData); // Add data foreach ($graphData as $cat => $data) { $graph->data[$cat] = new ezcGraphArrayDataSet($data); } $graph->data['Average Elevation']->displayType = ezcGraph::LINE; $graph->options->fillLines = 210; $title = 'images/charts/Elevation_' . $userId . '.svg'; $graph->render(700, 250, $title); return $title; }