Smalyshev has uploaded a new change for review.

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

Change subject: Relevancy runner in python
......................................................................

Relevancy runner in python

Bug: T116872
Change-Id: I2bb85deb9ec0443cbebf22d01c417f09e29ca609
---
A relevance.ini
A relevancyRunner.py
2 files changed, 93 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/discovery/relevancylab 
refs/changes/77/251177/1

diff --git a/relevance.ini b/relevance.ini
new file mode 100644
index 0000000..033af2c
--- /dev/null
+++ b/relevance.ini
@@ -0,0 +1,23 @@
+; Example config file
+[settings]
+; Host to run queries on
+labHost = suggesty.eqiad.wmflabs
+; Command to run a query
+searchCommand = sudo -u vagrant mwscript 
extensions/CirrusSearch/maintenance/runSearch.php 
+; Working directory
+workDir = /tmp/relevance
+; JSON Diff tool
+jsonDiffTool = python jsondiff.py -d 
+; Metric reporting tool
+metricTool = echo metric
+
+[test1]
+name = Test 1
+queries = test1.q
+;config = test1.json
+
+[test2]
+name = Test 2
+queries = test2.q
+config = test2.json
+
diff --git a/relevancyRunner.py b/relevancyRunner.py
new file mode 100755
index 0000000..d2d7c4c
--- /dev/null
+++ b/relevancyRunner.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python  
+# relevancyRunner.py - 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
+
+import os
+import sys
+import argparse
+import ConfigParser
+import pipes
+import subprocess
+import re
+
+def getSafeName(name):
+    return re.sub(r'[^a-zA-Z0-9]', '-', name)
+
+def ensureDir(dirname):
+    if not os.path.exists(dirname):
+        os.makedirs(dirname)
+
+def runSearch(config, section):
+    qname = getSafeName(config.get(section, 'name'))
+    qdir = config.get('settings', 'workDir') + "/queries/" + qname
+    ensureDir(qdir)
+    cmdline = config.get('settings', 'searchCommand')
+    if config.has_option(section, 'config'):
+        cmdline += " --options " + pipes.quote(open(config.get(section, 
'config')).read())
+    runCommand("cat %s | ssh %s %s > %s" % (config.get(section, 'queries'), 
config.get('settings', 'labHost'), pipes.quote(cmdline), qdir + "/results"))
+    return qdir + "/results"
+
+def checkSettings(config, section, settings):
+    for s in settings:
+        if not config.has_option(section, s):
+            raise ValueError("Section [%s] missing configuration %s" % 
(section, s))
+    pass
+
+def runCommand(cmd):
+    print "RUNNING "+cmd
+    subprocess.check_call(cmd, shell=True) 
+
+parser = argparse.ArgumentParser(description='Run relevance lab queries',
+    prog=sys.argv[0])
+parser.add_argument('-c', '--config', dest='config', help='Configuration file 
name', required=True)
+args = parser.parse_args()
+
+config = ConfigParser.ConfigParser()
+config.readfp(open(args.config))
+checkSettings(config, 'settings', ['labHost', 'workDir', 'jsonDiffTool', 
'metricTool', 'searchCommand'])
+checkSettings(config, 'test1', [ 'name', 'queries'])
+checkSettings(config, 'test2', [ 'name', 'queries'])
+
+res1 = runSearch(config, 'test1')
+res2 = runSearch(config, 'test2')
+comparisonDir =  config.get('settings', 
'workDir')+"/comparisons/"+getSafeName(config.get('test1', 
'name'))+"_"+getSafeName(config.get('test2', 'name'))
+ensureDir(comparisonDir)
+
+runCommand("%s %s %s %s" % (config.get('settings', 'jsonDiffTool'), 
comparisonDir + "/diffs", res1, res2))
+runCommand("%s %s %s %s" % (config.get('settings', 'metricTool'), 
comparisonDir, res1, res2))
+

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2bb85deb9ec0443cbebf22d01c417f09e29ca609
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/discovery/relevancylab
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