Jsahleen has submitted this change and it was merged.
Change subject: Reports: Add reporting system for generating limn sql
......................................................................
Reports: Add reporting system for generating limn sql
* Adds classes and system for generating sql for limn dashboards
* Languages externalized to configuration file.
* To use: php path/to/reports.php path/to/ClassReport.php
* Output normally goes to stdout
* To write to file use >
* To append to file use >>
Bug:T90265
Change-Id: Id14f3ffc2e293b4e419c7cab491935bb4d834ea1
---
D generatesql.php
M language/content_translation_beta.sql
M language/content_translation_beta_manual.sql
A reportgenerator/base/ReportInterface.php
A reportgenerator/config/config.json
A reportgenerator/reports.php
A reportgenerator/reports/BetaFeatureEnablementsReport.php
A reportgenerator/reports/BetaFeatureManualEnablementsReport.php
8 files changed, 126 insertions(+), 55 deletions(-)
Approvals:
Jsahleen: Looks good to me, approved
diff --git a/generatesql.php b/generatesql.php
deleted file mode 100644
index 2f5d902..0000000
--- a/generatesql.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-
-$codes = array( 'ca', 'da', 'eo', 'es', 'id', 'ms', 'nn', 'no', 'pt', 'sv' );
-
-// This sql is for all beta feature enablements
-$sql1 = "select *\nfrom\n";
-$first = array_shift( $codes );
-$dbfirst = $first . "wiki";
-$sql1 .= "( select count(*) as $dbfirst from $dbfirst.user_properties where
up_property = 'cx' and up_value = 1 ) $first\nleft join\n";
-$lines = array();
-foreach( $codes as $code ) {
- $db = $code . "wiki";
- $lines[] .= "( select count(*) as $db from $db.user_properties where
up_property = 'cx' and up_value = 1 ) $code on 1=1\n";
-}
-$sql1 .= implode( "left join\n", $lines ) . ";\n";
-file_put_contents( 'language/content_translation_beta.sql', $sql1 );
-
-// This sql is for beta feature enablements that are not auto-enroll
-$sql2 = "select *\nfrom\n";
-$sql2 .= "( select count(*) as $dbfirst from $dbfirst.user_properties where
up_property = 'cx' and up_value = 1 ";
-$sql2 .= "and up_user not in ( select up_user from user_properties where
up_property = 'betafeatures-auto-enroll' and up_value = 1 ) ) $first\nleft
join\n";
-$lines = array();
-foreach( $codes as $code ) {
- $db = $code . "wiki";
- $main = "( select count(*) as $db from $db.user_properties where
up_property = 'cx' and up_value = 1 ";
- $sub = "and up_user not in ( select up_user from user_properties where
up_property = 'betafeatures-auto-enroll' and up_value = 1 ) ) $code on 1=1\n";
- $lines[] = $main . $sub;
-}
-$sql2 .= implode( "left join\n", $lines ) . ";\n";
-file_put_contents( 'language/content_translation_beta_manual.sql', $sql2 );
-
diff --git a/language/content_translation_beta.sql
b/language/content_translation_beta.sql
index c98ce38..abc3ea9 100644
--- a/language/content_translation_beta.sql
+++ b/language/content_translation_beta.sql
@@ -1,15 +1,15 @@
- select current_date() as date,
- cawiki,
- dawiki,
- eowiki,
- eswiki,
- idwiki,
- mswiki,
- nnwiki,
- nowiki,
- ptwiki,
- svwiki
- from
+select current_date() as date,
+ cawiki,
+ dawiki,
+ eowiki,
+ eswiki,
+ idwiki,
+ mswiki,
+ nnwiki,
+ nowiki,
+ ptwiki,
+ svwiki
+ from
( select count(*) as cawiki from cawiki.user_properties where up_property =
'cx' and up_value = 1 ) ca
left join
( select count(*) as dawiki from dawiki.user_properties where up_property =
'cx' and up_value = 1 ) da on 1=1
diff --git a/language/content_translation_beta_manual.sql
b/language/content_translation_beta_manual.sql
index 69c6bb8..c23de31 100644
--- a/language/content_translation_beta_manual.sql
+++ b/language/content_translation_beta_manual.sql
@@ -1,15 +1,15 @@
- select current_date() as date,
- cawiki,
- dawiki,
- eowiki,
- eswiki,
- idwiki,
- mswiki,
- nnwiki,
- nowiki,
- ptwiki,
- svwiki
- from
+select current_date() as date,
+ cawiki,
+ dawiki,
+ eowiki,
+ eswiki,
+ idwiki,
+ mswiki,
+ nnwiki,
+ nowiki,
+ ptwiki,
+ svwiki
+ from
( select count(*) as cawiki from cawiki.user_properties where up_property =
'cx' and up_value = 1 and up_user not in ( select up_user from
cawiki.user_properties where up_property = 'betafeatures-auto-enroll' and
up_value = 1 ) ) ca
left join
( select count(*) as dawiki from dawiki.user_properties where up_property =
'cx' and up_value = 1 and up_user not in ( select up_user from
dawiki.user_properties where up_property = 'betafeatures-auto-enroll' and
up_value = 1 ) ) da on 1=1
diff --git a/reportgenerator/base/ReportInterface.php
b/reportgenerator/base/ReportInterface.php
new file mode 100644
index 0000000..8a50437
--- /dev/null
+++ b/reportgenerator/base/ReportInterface.php
@@ -0,0 +1,5 @@
+<?php
+
+interface ReportInterface {
+ public function run( $config );
+}
diff --git a/reportgenerator/config/config.json
b/reportgenerator/config/config.json
new file mode 100644
index 0000000..b887742
--- /dev/null
+++ b/reportgenerator/config/config.json
@@ -0,0 +1,3 @@
+{
+ "languages": [ "ca", "da", "eo", "es", "id", "ms", "nn", "no", "pt",
"sv" ]
+}
diff --git a/reportgenerator/reports.php b/reportgenerator/reports.php
new file mode 100644
index 0000000..34bcd33
--- /dev/null
+++ b/reportgenerator/reports.php
@@ -0,0 +1,33 @@
+<?php
+
+$dir = __DIR__;
+$input = $argv[1];
+require_once( "$dir/base/ReportInterface.php" );
+$config = json_decode( file_get_contents( "$dir/config/config.json" ), true );
+
+try {
+ if ( !$config ) {
+ throw new Exception( "Configuration file is missing or
unreadable", 1 );
+ }
+ if ( file_exists( $input ) && is_readable( $input ) ) {
+ $reportFile = new SplFileInfo( $input );
+ require_once $reportFile->getRealPath();
+
+ // get the class name from the file name.
+ $class = substr(
+ $reportFile->getFilename(),
+ 0,
+ strpos( $reportFile->getFilename(), '.' .
$reportFile->getExtension() )
+ );
+ if ( !class_exists( $class ) ) {
+ throw new Exception( "Report class $class not defined",
1 );
+ }
+ $report = new $class();
+ $output = $report->run( $config );
+ echo $output;
+ } else {
+ throw new Exception( "Could not load file $input", 1 );
+ }
+} catch ( Exception $e ) {
+ echo $e->getMessage()."\n";
+}
diff --git a/reportgenerator/reports/BetaFeatureEnablementsReport.php
b/reportgenerator/reports/BetaFeatureEnablementsReport.php
new file mode 100644
index 0000000..571aa6f
--- /dev/null
+++ b/reportgenerator/reports/BetaFeatureEnablementsReport.php
@@ -0,0 +1,29 @@
+<?php
+
+class BetaFeatureEnablementsReport implements ReportInterface {
+ public function run( $config ) {
+ $languages = $config['languages'];
+
+ $wikis = array();
+ foreach ( $languages as $language ) {
+ $wikis[$language] = $language . 'wiki';
+ }
+
+ $sql .= "select current_date() as date,\n\t";
+ $sql .= implode( ",\n\t", $wikis );
+ $sql .= "\n\tfrom\n";
+
+ $languageFirst = array_shift( $languages );
+ $wikiFirst = array_shift( $wikis );
+ $sql .= "( select count(*) as $wikiFirst from
$wikiFirst.user_properties where up_property = 'cx' and up_value = 1 )
$languageFirst\nleft join\n";
+
+ $lines = array();
+ foreach( $languages as $language ) {
+ $wiki = $wikis[$language];
+ $lines[] .= "( select count(*) as $wiki from
$wiki.user_properties where up_property = 'cx' and up_value = 1 ) $language on
1=1\n";
+ }
+ $sql .= implode( "left join\n", $lines ) . ";\n";
+
+ return $sql;
+ }
+}
diff --git a/reportgenerator/reports/BetaFeatureManualEnablementsReport.php
b/reportgenerator/reports/BetaFeatureManualEnablementsReport.php
new file mode 100644
index 0000000..1f4d80b
--- /dev/null
+++ b/reportgenerator/reports/BetaFeatureManualEnablementsReport.php
@@ -0,0 +1,32 @@
+<?php
+
+class BetaFeatureManualEnablementsReport implements ReportInterface {
+ public function run( $config ) {
+ $languages = $config['languages'];
+
+ $wikis = array();
+ foreach ( $languages as $language ) {
+ $wikis[$language] = $language . 'wiki';
+ }
+
+ $sql = "select current_date() as date,\n\t";
+ $sql .= implode( ",\n\t", $wikis );
+ $sql .= "\n\tfrom\n";
+
+ $languageFirst = array_shift( $languages );
+ $wikiFirst = array_shift( $wikis );
+ $sql .= "( select count(*) as $wikiFirst from
$wikiFirst.user_properties where up_property = 'cx' and up_value = 1 ";
+ $sql .= "and up_user not in ( select up_user from
$wikiFirst.user_properties where up_property = 'betafeatures-auto-enroll' and
up_value = 1 ) ) $languageFirst\nleft join\n";
+
+ $lines = array();
+ foreach( $languages as $language ) {
+ $wiki = $wikis[$language];
+ $main = "( select count(*) as $wiki from
$wiki.user_properties where up_property = 'cx' and up_value = 1 ";
+ $sub = "and up_user not in ( select up_user from
$wiki.user_properties where up_property = 'betafeatures-auto-enroll' and
up_value = 1 ) ) $language on 1=1\n";
+ $lines[] = $main . $sub;
+ }
+ $sql .= implode( "left join\n", $lines ) . ";\n";
+
+ return $sql;
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/192457
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id14f3ffc2e293b4e419c7cab491935bb4d834ea1
Gerrit-PatchSet: 10
Gerrit-Project: analytics/limn-language-data
Gerrit-Branch: master
Gerrit-Owner: Jsahleen <[email protected]>
Gerrit-Reviewer: Jsahleen <[email protected]>
Gerrit-Reviewer: Milimetric <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Springle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits