Skip to content

Commit ff914aa

Browse files
committed
feat: add extra download stats
Test-bot: skip
1 parent 0c8a526 commit ff914aa

3 files changed

Lines changed: 48 additions & 5 deletions

File tree

script/statistics/annual-statistics.inc.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,19 @@
77

88
namespace Keyman\Site\com\keyman\api;
99

10-
function filter_columns_by_name($key) {
11-
return !is_numeric($key);
10+
// strip out repeated columns with numeric keys
11+
function filter_columns_by_name($data) {
12+
$result = [];
13+
foreach($data as $row) {
14+
$r = [];
15+
foreach($row as $id => $val) {
16+
if(!is_numeric($id)) {
17+
$r[$id] = intval($val);
18+
}
19+
}
20+
array_push($result, $r);
21+
}
22+
return $result;
1223
}
1324

1425
class AnnualStatistics {
@@ -22,7 +33,17 @@ function execute($mssql, $startDate, $endDate) {
2233

2334
$stmt->execute();
2435
$data = $stmt->fetchAll();
25-
//$data = array_filter($data, "Keyman\\Site\\com\\keyman\\api\\filter_columns_by_name", ARRAY_FILTER_USE_KEY );
26-
return $data;
36+
return filter_columns_by_name($data);
37+
}
38+
39+
function executeDownloadsByMonth($mssql, $startDate, $endDate) {
40+
$stmt = $mssql->prepare('EXEC sp_keyboard_downloads_by_month_statistics :prmStartDate, :prmEndDate');
41+
42+
$stmt->bindParam(":prmStartDate", $startDate);
43+
$stmt->bindParam(":prmEndDate", $endDate);
44+
45+
$stmt->execute();
46+
$data = $stmt->fetchAll();
47+
return filter_columns_by_name($data);
2748
}
2849
}

script/statistics/annual.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@
2828
*/
2929

3030
$stats = new \Keyman\Site\com\keyman\api\AnnualStatistics();
31-
$data = $stats->execute($mssql, $startDate, $endDate);
31+
$summary = $stats->execute($mssql, $startDate, $endDate);
32+
$downloads = $stats->executeDownloadsByMonth($mssql, $startDate, $endDate);
33+
$data = ["summary" => $summary, "keyboardDownloadsByMonth" => $downloads];
3234
json_print($data);

tools/db/build/annual-statistics.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,23 @@ SELECT
3838
(select count(*) from k0.t_keyboard_langtag) AS LanguageKeyboardPairs,
3939
(select count(*) from k0.t_model) AS LexicalModelCount,
4040
(select sum(count) from kstats.t_keyboard_downloads WHERE statdate >= @prmStartDate AND statdate < @prmEndDate) RawKeyboardDownloadCount
41+
GO
42+
43+
DROP PROCEDURE IF EXISTS sp_keyboard_downloads_by_month_statistics;
44+
GO
45+
46+
CREATE PROCEDURE sp_keyboard_downloads_by_month_statistics (
47+
@prmStartDate DATE,
48+
@prmEndDate DATE
49+
) AS
50+
51+
select
52+
month(statdate) Month,
53+
year(statdate) Year,
54+
sum(count) RawKeyboardDownloadCount,
55+
sum(count)/day(eomonth(datefromparts(year(statdate),month(statdate),1))) DownloadsPerDay
56+
from kstats.t_keyboard_downloads
57+
WHERE statdate >= @prmStartDate AND statdate < @prmEndDate
58+
group by month(statdate), year(statdate)
59+
order by 2, 1
60+
GO

0 commit comments

Comments
 (0)