Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions script/statistics/annual-statistics.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
4 changes: 3 additions & 1 deletion script/statistics/annual.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

21 changes: 21 additions & 0 deletions tools/db/build/annual-statistics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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