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
30 changes: 26 additions & 4 deletions script/statistics/annual-statistics.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@

namespace Keyman\Site\com\keyman\api;

function filter_columns_by_name($key) {
return !is_numeric($key);
// strip out repeated columns with numeric keys (by default the results returned
// give each column twice, once with a column name, and once with a column index)
function filter_columns_by_name($data) {
$result = [];
foreach($data as $row) {
$r = [];
foreach($row as $id => $val) {
if(!is_numeric($id)) {
$r[$id] = intval($val);
}
}
array_push($result, $r);
}
return $result;
}

class AnnualStatistics {
Expand All @@ -22,7 +34,17 @@ function execute($mssql, $startDate, $endDate) {

$stmt->execute();
$data = $stmt->fetchAll();
//$data = array_filter($data, "Keyman\\Site\\com\\keyman\\api\\filter_columns_by_name", ARRAY_FILTER_USE_KEY );
return $data;
return filter_columns_by_name($data);
}

function executeDownloadsByMonth($mssql, $startDate, $endDate) {
$stmt = $mssql->prepare('EXEC sp_keyboard_downloads_by_month_statistics :prmStartDate, :prmEndDate');

$stmt->bindParam(":prmStartDate", $startDate);
$stmt->bindParam(":prmEndDate", $endDate);

$stmt->execute();
$data = $stmt->fetchAll();
return filter_columns_by_name($data);
}
}
4 changes: 3 additions & 1 deletion script/statistics/annual.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
*/

$stats = new \Keyman\Site\com\keyman\api\AnnualStatistics();
$data = $stats->execute($mssql, $startDate, $endDate);
$summary = $stats->execute($mssql, $startDate, $endDate);
$downloads = $stats->executeDownloadsByMonth($mssql, $startDate, $endDate);
$data = ["summary" => $summary, "keyboardDownloadsByMonth" => $downloads];
json_print($data);
20 changes: 20 additions & 0 deletions tools/db/build/annual-statistics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,23 @@ SELECT
(select count(*) from k0.t_keyboard_langtag) AS LanguageKeyboardPairs,
(select count(*) from k0.t_model) AS LexicalModelCount,
(select sum(count) from kstats.t_keyboard_downloads WHERE statdate >= @prmStartDate AND statdate < @prmEndDate) RawKeyboardDownloadCount
GO

DROP PROCEDURE IF EXISTS sp_keyboard_downloads_by_month_statistics;
GO

CREATE PROCEDURE sp_keyboard_downloads_by_month_statistics (
@prmStartDate DATE,
@prmEndDate DATE
) AS

select
month(statdate) Month,
year(statdate) Year,
sum(count) RawKeyboardDownloadCount,
sum(count)/day(eomonth(datefromparts(year(statdate),month(statdate),1))) DownloadsPerDay
from kstats.t_keyboard_downloads
WHERE statdate >= @prmStartDate AND statdate < @prmEndDate
group by month(statdate), year(statdate)
order by 2, 1
GO