Nikerabbit has uploaded a new change for review.
https://gerrit.wikimedia.org/r/89635
Change subject: Script to help testing sandbox
......................................................................
Script to help testing sandbox
Change-Id: I661fa7d92e698c671460f850b4f3d38ad2c45bf3
---
A tests/generateRandomSandboxData.php
1 file changed, 117 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate
refs/changes/35/89635/1
diff --git a/tests/generateRandomSandboxData.php
b/tests/generateRandomSandboxData.php
new file mode 100644
index 0000000..4616b15
--- /dev/null
+++ b/tests/generateRandomSandboxData.php
@@ -0,0 +1,117 @@
+<?php
+/**
+ * Script to generate some random data to help testing sandbox.
+ *
+ * @author Niklas Laxström
+ * @license GPL-2.0+
+ * @file
+ */
+
+// Standard boilerplate to define $IP
+if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
+ $IP = getenv( 'MW_INSTALL_PATH' );
+} else {
+ $dir = __DIR__;
+ $IP = "$dir/../../..";
+}
+require_once "$IP/maintenance/Maintenance.php";
+
+class TranslateGenerateRandomSandboxData extends Maintenance {
+
+ public function execute() {
+ $users = 10;
+
+ // For number of translations, limited to [0,20]
+ $mean = 15;
+ $stddev = 20;
+
+ $stash = new TranslationStashStorage( wfGetDB( DB_MASTER ) );
+
+ $languages = array_keys( Language::fetchLanguageNames() );
+
+ for ( $i = 0; $i < $users; $i++ ) {
+ $username = 'Pupu' . wfRandomString( 6 );
+ $password = wfRandomString( 12 );
+ $email = "[email protected]";
+ $user = TranslateSandbox::addUser( $username,
$password, $email );
+
+ $language = $languages[rand( 0, count( $languages )
-1)];
+
+ $count = gauss_ms( $mean, $stddev );
+ $count = min( 20, $count );
+ $count = max( 0, $count );
+
+ for ( $j = 0; $j < $count; $j++ ) {
+ $title = Title::makeTitle( NS_MEDIAWIKI,
wfRandomString( 24 ) . '/' . $language );
+
+ $value = array( 'Pupu söi' );
+ for ( $k = rand( 0, 20 ); $k > 0; $k-- ) {
+ $value[] = wfRandomString( rand( 1, 28
) );
+ }
+
+ $value = implode( "\n", $value );
+ $translation = new StashedTranslation( $user,
$title, $value );
+ $stash->addTranslation( $translation );
+ }
+ }
+ }
+}
+
+function gauss() {
+ static $useExists = false ;
+ static $useValue ;
+
+ if ($useExists) {
+ // Use value from a previous call to this function
+ //
+ $useExists = false ;
+ return $useValue ;
+ } else {
+ // Polar form of the Box-Muller transformation
+ //
+ $w = 2.0 ;
+ while (($w >= 1.0) || ($w == 0.0)) {
+ $x = random_PN() ;
+ $y = random_PN() ;
+ $w = ($x * $x) + ($y * $y) ;
+ }
+ $w = sqrt((-2.0 * log($w)) / $w) ;
+
+ // Set value for next call to this function
+ //
+ $useValue = $y * $w ;
+ $useExists = true ;
+
+ return $x * $w ;
+ }
+} // function gauss()
+
+
+function gauss_ms( $mean,
+ $stddev )
+{
+ // Adjust our gaussian random to fit the mean and standard deviation
+ // The division by 4 is an arbitrary value to help fit the distribution
+ // within our required range, and gives a best fit for $stddev = 1.0
+ //
+ return gauss() * ($stddev/4) + $mean;
+}
+
+
+$maintClass = 'TranslateGenerateRandomSandboxData';
+require_once RUN_MAINTENANCE_IF_MAIN;
+
+function random_0_1()
+{
+ // returns random number using mt_rand() with a flat distribution from 0
to 1 inclusive
+ //
+ return (float) mt_rand() / (float) mt_getrandmax() ;
+} // random_0_1()
+
+
+function random_PN()
+{
+ // returns random number using mt_rand() with a flat distribution from -1
to 1 inclusive
+ //
+ return (2.0 * random_0_1()) - 1.0 ;
+}
--
To view, visit https://gerrit.wikimedia.org/r/89635
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I661fa7d92e698c671460f850b4f3d38ad2c45bf3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits