Index: trunk/www/sites/www/community/donations/statistics/index.php =================================================================== --- trunk/www/sites/www/community/donations/statistics/index.php (revision 1567508) +++ trunk/www/sites/www/community/donations/statistics/index.php (revision 1567509) @@ -1,183 +1,227 @@ "Donations Statistics" ]); require('../../../aether/header.php'); $site_root = "../../"; echo '
'; function endsWith($haystack, $needle) { return substr($haystack, -strlen($needle)) === $needle; } echo "

Per Month

"; for ($year = date("Y", time()); $year > 2010; $year--) { echo ""; echo ""; echo ""; $stmtYear = $dbConnection->prepare('SELECT COUNT(*) as number, MIN(amount) as min_t, MAX(amount) as max_t, ROUND(AVG(amount), 2) as avg_t, ROUND(STDDEV(amount), 2) as stddev_t, SUM(amount) as sum_t FROM donations WHERE YEAR(date) = :year'); $stmtYear->execute([ 'year' => $year ]); $stmtMonth = $dbConnection->prepare('SELECT COUNT(*) as number, MIN(amount) as min_t, MAX(amount) as max_t, ROUND(AVG(amount), 2) as avg_t, ROUND(STDDEV(amount), 2) as stddev_t, SUM(amount) as sum_t FROM donations WHERE date >= :begin AND date <= :end'); $yearRow = $stmtYear->fetch(); for ($month = 1; $month <= 12 ; $month++) { $month < 10 ? $month_s = "0".$month : $month_s = $month; $stmtMonth->execute([ 'begin' => $year.'-'.$month_s.'-01', 'end' => $year.'-'.$month_s.'-31 23:59:59', ]); $row = $stmtMonth->fetch(); echo ""; } echo ""; echo "
".$year."
Month Number of Donations Total Amount Average Donation Donation StdDev Max Donation Min Donation
".date("F", mktime(0,0,0,$month,1,$year))." ".$row['number']." ".$row['sum_t']." ".$row['avg_t']." ".$row['stddev_t']." ".$row['max_t']." ".$row['min_t']."
Year Total ".$yearRow['number']." ".$yearRow['sum_t']." ".$yearRow['avg_t']." ".$yearRow['stddev_t']." ".$yearRow['max_t']." ".$yearRow['min_t']."

"; } + echo "

Per Week (promo data)

"; + + function rangeWeek ($datestr) { + date_default_timezone_set (date_default_timezone_get()); + $dt = strtotime ($datestr); + return array ( + "start" => date ('N', $dt) == 1 ? date ('Y-m-d', $dt) : date ('Y-m-d', strtotime ('last monday', $dt)), + "end" => date('N', $dt) == 7 ? date ('Y-m-d', $dt) : date ('Y-m-d', strtotime ('next sunday', $dt)) + ); + } + + for ($year = date("Y", time()); $year > 2010; $year--) { + echo ""; + echo ""; + echo " + + + "; + + $stmtMonth = $dbConnection->prepare('SELECT COUNT(*) as number, MIN(amount) as min_t, MAX(amount) as max_t, ROUND(AVG(amount), 2) as avg_t, ROUND(STDDEV(amount), 2) as stddev_t, SUM(amount) as sum_t FROM donations WHERE YEAR(date) = :year'); + $stmtMonth->execute([ + 'year' => $year + ]); + + $stmtWeek = $dbConnection->prepare('SELECT COUNT(*) as number, MIN(amount) as min_t, MAX(amount) as max_t, ROUND(AVG(amount), 2) as avg_t, ROUND(STDDEV(amount), 2) as stddev_t, SUM(amount) as sum_t FROM donations WHERE WEEK(date) == :week AND YEAR(date) == :year'); + $yearRow = $stmtYear->fetch(); + + for ($week = 1; $week <= 52 ; $week++) { + $stmtMonth->execute([ + 'week' => $week, + 'year' => $year, + ]); + $row = $stmtWeek->fetch(); + echo " + + + "; + } + echo " + + + "; + echo "
".$year."
WeekNumber of DonationsTotal Amount
".$week."".$row['number']."".$row['sum_t']."
Year Total".$yearRow['number']."".$yearRow['sum_t']."

"; + } ?>

Per Donation Url

Period:
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $query = "SELECT COUNT(id) as number, SUM(amount) as sum_t, MIN(amount) as min_t, MAX(amount) as max_t, ROUND(AVG(amount), 2) as avg_t, ROUND(STDDEV(amount), 2) as stddev_t, donate_url FROM donations"; $q = null; if ($period === "today") { $query .= ' WHERE DATE(date) = CURDATE() GROUP BY donate_url'; $q = $dbConnection->query($query); } else if ($period === "yesterday") { $query .= ' WHERE DATE(date) = SUBDATE(CURDATE(), 1) GROUP BY donate_url'; $q = $dbConnection->query($query); } else if ($period === "month") { $query .= ' WHERE YEAR(date) = YEAR(NOW()) AND MONTH(date) = MONTH(NOW()) GROUP BY donate_url'; $q = $dbConnection->query($query); } else if ($period === "custom") { $query .= ' WHERE date >= :fromTime AND date <= :toTime GROUP BY donate_url'; $q = $dbConnection->prepare($query); $q->execute([ 'fromTime' => $_POST['from'], 'toTime' => $_POST['to'] . ' 23:59:59', ]); } else if ($period === "all") { $q = $dbConnection->query($query . ' GROUP BY donate_url;'); } else { echo "bug: $period"; } echo ""; echo ""; $total = 0; while ($row = $q->fetch()) { echo ""; $total += $row['number']; } echo "
Url Number of Donations Total Amount Average Donation Donation StdDev Max Donation Min Donation
".cleanUrl($row['donate_url'])." ".$row['number']." ".$row['sum_t']." ".$row['avg_t']." ".$row['stddev_t']." ".$row['max_t']." ".$row['min_t']."

Total number of donations for this period is: $total

"; ?>