Smalyshev has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/250909

Change subject: Initial version of relevance lab runner
......................................................................

Initial version of relevance lab runner

Bug: T116872
Change-Id: I09621925bf01bfa00d2fdb97a4f446f743664dbc
---
A maintenance/relevanceRunner.php
1 file changed, 121 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch 
refs/changes/09/250909/1

diff --git a/maintenance/relevanceRunner.php b/maintenance/relevanceRunner.php
new file mode 100644
index 0000000..a612f56
--- /dev/null
+++ b/maintenance/relevanceRunner.php
@@ -0,0 +1,121 @@
+<?php
+
+namespace CirrusSearch\Maintenance;
+
+/**
+ * Run relevance lab queries
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+$IP = getenv( 'MW_INSTALL_PATH' );
+if ( $IP === false ) {
+       $IP = __DIR__ . '/../../..';
+}
+require_once ("$IP/maintenance/Maintenance.php");
+require_once (__DIR__ . '/../includes/Maintenance/Maintenance.php');
+
+class RelevanceRunner extends \Maintenance {
+       /**
+        * Tool internal settings
+        *
+        * @var array
+        */
+       private $config;
+
+       public function __construct() {
+               //parent::__construct();
+               $this->addDescription( 'Run relevance test.' );
+               $this->addOption( 'config', 'Configuration file name', true, 
true );
+       }
+
+       /**
+        * Run single remote search invocation
+        * @param unknown $configFile
+        * @param unknown $queryFile
+        * @param unknown $qname
+        * @return string
+        */
+       private function runSearch( $configFile, $queryFile, $qname ) {
+               $qdir = $this->config['workDir'] . "/queries/" . $qname;
+               wfMkdirParents( $qdir );
+               $this->runCommand( "scp $queryFile 
{$this->config['labHost']}:/tmp/$qname.queries" );
+               $cmdline = "cat /tmp/$qname.queries | 
{$this->config['searchCommand']}";
+               if ( $configFile && filesize( $configFile ) != 0 ) {
+                       copy( $configFile, "$qdir/runSearchConf.json" );
+                       $cmdline .= " --options " . escapeshellarg( 
file_get_contents( $configFile ) );
+               }
+               $result = $this->runRemote( $this->config['labHost'], $cmdline 
);
+               file_put_contents( "$qdir/results", $result );
+               return "$qdir/results";
+       }
+
+       /**
+        * Run shell command
+        * @param unknown $cmd
+        * @return string
+        */
+       private function runCommand( $cmd ) {
+               echo "RUNNING: $cmd\n";
+               // return md5( $cmd );
+               return wfShellExec( $cmd );
+       }
+
+       private function runRemote( $host, $cmd ) {
+               $scmd = "ssh $host " . escapeshellarg($cmd);
+               $result = $this->runCommand( $scmd );
+               echo "RESULT: $result\n";
+               return $result;
+       }
+
+       /**
+        * Check that $this->config contains settings given as arguments.
+        */
+       private function checkSettings( $config, $name, $checks ) {
+               foreach ( $checks as $check ) {
+                       if ( empty( $config[$check] ) ) {
+                               $this->error( "Config setting $check is missing 
in $name", 1 );
+                       }
+               }
+       }
+
+       public function execute() {
+               $configFile = $this->getOption( "config", "relevance.ini" );
+               $config = parse_ini_file( $this->getOption( "config", 
"relevance.ini" ), true );
+               chdir( dirname( $configFile ) );
+
+               if ( empty( $config['test1'] ) || empty( $config['test2'] ) || 
empty( $config['settings'] ) ) {
+                       $this->error( "Configuration should have sections: 
test1, test2 and settings", 1 );
+               }
+               $this->config = $config['settings'];
+               $this->checkSettings( $this->config, 'settings',
+                               array( 'labHost', 'workDir', 'jsonDiffTool', 
'metricTool', 'searchCommand' ) );
+               $this->checkSettings( $config['test1'], 'test1', array( 'name', 
'queries' ) );
+               $this->checkSettings( $config['test2'], 'test2', array( 'name', 
'queries' ) );
+
+               $qname1 = preg_replace( "/[^a-zA-Z0-9]/", "-", 
$config['test1']['name'] );
+               $qname2 = preg_replace( "/[^a-zA-Z0-9]/", "-", 
$config['test2']['name'] );
+
+               $res1 = $this->runSearch( $config['test1']['config'], 
$config['test1']['queries'], $qname1 );
+               $res2 = $this->runSearch( $config['test2']['config'], 
$config['test2']['queries'], $qname2 );
+
+               $comparisonDir = $this->config['workDir'] . "/comparisons/" . 
"{$qname1}_{$qname2}";
+               wfMkdirParents( $comparisonDir );
+
+               $this->runCommand( "{$this->config['jsonDiffTool']} $res1 $res2 
$comparisonDir/diffs" );
+               $this->runCommand( "{$this->config['metricTool']} $res1 $res2 
$comparisonDir" );
+       }
+}
+
+$maintClass = 'CirrusSearch\Maintenance\RelevanceRunner';
+require_once RUN_MAINTENANCE_IF_MAIN;
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/250909
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I09621925bf01bfa00d2fdb97a4f446f743664dbc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to