-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: annual statistics for reporting
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/* | ||
* Keyman is copyright (C) SIL Global. MIT License. | ||
* | ||
* Basic annual statistics for SIL reports | ||
*/ | ||
|
||
namespace Keyman\Site\com\keyman\api; | ||
|
||
function filter_columns_by_name($key) { | ||
return !is_numeric($key); | ||
} | ||
|
||
class AnnualStatistics { | ||
|
||
function execute($mssql, $startDate, $endDate) { | ||
|
||
$stmt = $mssql->prepare('EXEC sp_annual_statistics :prmStartDate, :prmEndDate'); | ||
|
||
$stmt->bindParam(":prmStartDate", $startDate); | ||
$stmt->bindParam(":prmEndDate", $endDate); | ||
|
||
$stmt->execute(); | ||
$data = $stmt->fetchAll()[0]; | ||
$data = array_filter($data, "Keyman\\Site\\com\\keyman\\api\\filter_columns_by_name", ARRAY_FILTER_USE_KEY ); | ||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/* | ||
* Keyman is copyright (C) SIL Global. MIT License. | ||
* | ||
* Basic annual statistics for SIL reports | ||
*/ | ||
|
||
require_once(__DIR__ . '/../../tools/util.php'); | ||
|
||
allow_cors(); | ||
json_response(); | ||
|
||
require_once(__DIR__ . '/../../tools/db/db.php'); | ||
require_once(__DIR__ . '/annual-statistics.inc.php'); | ||
require_once __DIR__ . '/../../tools/autoload.php'; | ||
use Keyman\Site\Common\KeymanHosts; | ||
$mssql = Keyman\Site\com\keyman\api\Tools\DB\DBConnect::Connect(); | ||
|
||
if(!isset($_REQUEST['startDate']) || !isset($_REQUEST['endDate'])) { | ||
fail('startDate, endDate parameters must be set'); | ||
} | ||
|
||
$startDate = $_REQUEST['startDate']; | ||
$endDate = $_REQUEST['endDate']; | ||
|
||
/** | ||
* https://api.keyman.com/script/statistics/annual.php | ||
*/ | ||
|
||
$stats = new \Keyman\Site\com\keyman\api\AnnualStatistics(); | ||
$data = $stats->execute($mssql, $startDate, $endDate); | ||
json_print($data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Keyman is copyright (C) SIL Global. MIT License. | ||
* | ||
* Basic annual statistics for SIL reports -- SQL Query | ||
*/ | ||
|
||
/* | ||
Some rough notes: | ||
* We have, in our cloud database <AllKeyboards> keyboards | ||
* Of these, <CurrentKeyboards> are listed as "not obsolete". Obsolete | ||
keyboards are keyboards which have been renamed and for which there is a new | ||
version, or keyboards which are non-Unicode. | ||
* We updated <ModifiedKeyboards> keyboards from startDate-endDate, according | ||
to each keyboard's last update date. This can be anything from a metadata | ||
change to significant keyboard rewrite. | ||
* We list <LanguageCount> languages today, for <LanguageKeyboardPairs> | ||
language:keyboard pairs. Many keyboards support more than one language. | ||
* We list <LexicalModelCount> lexical models. | ||
* <RawKeyboardDownloadCount> lists the total number of downloads of keyboards | ||
through keyman.com over the last year. This does not match the number of | ||
users or keyboards in use, but gives a rough volume. | ||
*/ | ||
|
||
DROP PROCEDURE IF EXISTS sp_annual_statistics; | ||
GO | ||
|
||
CREATE PROCEDURE sp_annual_statistics ( | ||
@prmStartDate DATE, | ||
@prmEndDate DATE | ||
) AS | ||
|
||
SELECT | ||
(select count(*) from k0.t_keyboard) AS AllKeyboards, | ||
(select count(*) from k0.t_keyboard where obsolete = 0) AS CurrentKeyboards, | ||
(select count(*) from k0.t_keyboard where last_modified >= @prmStartDate and last_modified < @prmEndDate) AS ModifiedKeyboards, | ||
(select count(distinct tag) from k0.t_keyboard_langtag) AS LanguageCount, | ||
(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters