From 2f867f48225a61fa6c14777b8af89361b41b89ca Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Tue, 13 Jan 2026 15:19:07 +1100 Subject: [PATCH] feat: add app downloads by month stats report Test-bot: skip --- script/statistics/annual-statistics.inc.php | 4 ++++ script/statistics/annual.php | 4 +++- tools/db/build/annual-statistics.sql | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/script/statistics/annual-statistics.inc.php b/script/statistics/annual-statistics.inc.php index 98ca7c6..ce57995 100644 --- a/script/statistics/annual-statistics.inc.php +++ b/script/statistics/annual-statistics.inc.php @@ -21,6 +21,10 @@ function executeKeyboards($mssql, $startDate, $endDate) { return $this->_execute('sp_statistics_keyboard_downloads_by_id', $mssql, $startDate, $endDate); } + function executeAppDownloadsByMonth($mssql, $startDate, $endDate) { + return $this->_execute('sp_app_downloads_by_month_statistics', $mssql, $startDate, $endDate); + } + private function _execute($proc, $mssql, $startDate, $endDate) { $stmt = $mssql->prepare("EXEC $proc :prmStartDate, :prmEndDate"); diff --git a/script/statistics/annual.php b/script/statistics/annual.php index c9b2df0..6fdd38e 100644 --- a/script/statistics/annual.php +++ b/script/statistics/annual.php @@ -30,5 +30,7 @@ $stats = new \Keyman\Site\com\keyman\api\AnnualStatistics(); $summary = $stats->execute($mssql, $startDate, $endDate); $downloads = $stats->executeDownloadsByMonth($mssql, $startDate, $endDate); - $data = ["summary" => $summary, "keyboardDownloadsByMonth" => $downloads]; + $appDownloads = $stats->executeAppDownloadsByMonth($mssql, $startDate, $endDate); + $data = ["summary" => $summary, "keyboardDownloadsByMonth" => $downloads, "appDownloadsByMonth" => $appDownloads]; json_print($data); + diff --git a/tools/db/build/annual-statistics.sql b/tools/db/build/annual-statistics.sql index ec632ed..98e2247 100644 --- a/tools/db/build/annual-statistics.sql +++ b/tools/db/build/annual-statistics.sql @@ -91,3 +91,24 @@ CREATE PROCEDURE sp_statistics_keyboard_downloads_by_id ( ORDER BY k.keyboard_id GO + +/* ======================================================================== */ + +DROP PROCEDURE IF EXISTS sp_app_downloads_by_month_statistics; +GO + +CREATE PROCEDURE sp_app_downloads_by_month_statistics ( + @prmStartDate DATE, + @prmEndDate DATE +) AS + select + month(statdate) Month, + year(statdate) Year, + product Product, + sum(count) RawAppDownloadCount, + sum(count)/day(eomonth(datefromparts(year(statdate),month(statdate),1))) DownloadsPerDay + from kstats.t_app_downloads + WHERE statdate >= @prmStartDate AND statdate < @prmEndDate + group by month(statdate), year(statdate), product + order by 3, 2, 1 +GO