jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/376445 )

Change subject: Encode human search relevance survey into html output
......................................................................


Encode human search relevance survey into html output

Moves the search relevance configuration from javascript into php
configuration so it can be run on a larger number of pages without
exploding the size of javascript delivered to everyone with all
that config.

The downside of this approach is that because the config is cached
into the page html any updates have to work their way through varnish
caching. For the initial test this should be fine as we can purge the
relevant pages over some small time period. In the future when we are
doing larger scale collection we just have to keep in mind that
configuration changes take around 7 days to propogate.

Bug: T174387
Change-Id: I7ae522155e67610d25b5857d7b3918559bce8bc7
(cherry picked from commit e722fe1a9b0d41c3597f9f9326e7fc6f0e1cd9c6)
---
M WikimediaEventsHooks.php
M extension.json
M modules/ext.wikimediaEvents.humanSearchRelevance.js
3 files changed, 35 insertions(+), 220 deletions(-)

Approvals:
  20after4: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/WikimediaEventsHooks.php b/WikimediaEventsHooks.php
index 0d8b7e5..709eb12 100644
--- a/WikimediaEventsHooks.php
+++ b/WikimediaEventsHooks.php
@@ -644,4 +644,14 @@
                );
        }
 
+       public static function onMakeGlobalVariablesScript( array &$vars, 
OutputPage $out ) {
+               global $wgWMESearchRelevancePages;
+               if ( $vars['wgAction'] === 'view' ) {
+                       $articleId = $out->getTitle()->getArticleID();
+                       if ( isset( $wgWMESearchRelevancePages[$articleId] ) ) {
+                               $vars['wgWMESearchRelevancePages'] = 
$wgWMESearchRelevancePages[$articleId];
+                       }
+               }
+               return true;
+       }
 }
diff --git a/extension.json b/extension.json
index 63a8487..db369ac 100644
--- a/extension.json
+++ b/extension.json
@@ -73,6 +73,9 @@
                ],
                "ChangesListSpecialPageStructuredFilters": [
                        
"WikimediaEventsHooks::onChangesListSpecialPageStructuredFilters"
+               ],
+               "MakeGlobalVariablesScript": [
+                       "WikimediaEventsHooks::onMakeGlobalVariablesScript"
                ]
        },
        "MessagesDirs": {
@@ -167,7 +170,8 @@
                        ],
                        "skinScripts": {
                                "default": [
-                                       
"ext.wikimediaEvents.searchSatisfaction.js"
+                                       
"ext.wikimediaEvents.searchSatisfaction.js",
+                                       
"ext.wikimediaEvents.humanSearchRelevance.js"
                                ],
                                "minerva": []
                        },
@@ -219,7 +223,10 @@
        "config": {
                "WMEReadingDepthSamplingRate": 0.005,
                "WMEReadingDepthEnabled": false,
-               "WMEStatsdBaseUri": false
+               "WMEStatsdBaseUri": false,
+               "WMESearchRelevancePages": {
+                       "_merge_strategy": "array_plus"
+               }
        },
        "manifest_version": 1
 }
diff --git a/modules/ext.wikimediaEvents.humanSearchRelevance.js 
b/modules/ext.wikimediaEvents.humanSearchRelevance.js
index 66667ac..5ee8fb2 100644
--- a/modules/ext.wikimediaEvents.humanSearchRelevance.js
+++ b/modules/ext.wikimediaEvents.humanSearchRelevance.js
@@ -1,10 +1,15 @@
 ( function ( mw, $, undefined ) {
        'use strict';
 
-       function oneIn( populationSize ) {
+       function sample( acceptPercentage ) {
                var rand = mw.user.generateRandomSessionId(),
+                       // take the first 52 bits of the rand value to match js
+                       // integer precision
                        parsed = parseInt( rand.slice( 0, 13 ), 16 );
-               return parsed % populationSize === 0;
+               if ( acceptPercentage >= 1 ) {
+                       return true;
+               }
+               return parsed / Math.pow( 2, 52 ) < acceptPercentage;
        }
 
        function chooseOne( options ) {
@@ -14,228 +19,23 @@
                return options[ Math.floor( parsed / step ) ];
        }
 
-       // Only accept enwiki, NS_MAIN for MVP feasability test
-       if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 ||
-               mw.config.get( 'wgDBname' ) !== 'enwiki'
-       ) {
+       // Page is not part of this test
+       if ( !mw.config.exists( 'wgWMESearchRelevancePages' ) ) {
                return;
        }
 
-       // For the MVP we are simply hardcoding the list of queries and 
articles.
-       // If the MVP shows to return data that isn't complete junk this will be
-       // revisited, perhaps embedding the desired queries into cached page 
render
-       // or some such. oneIn values are tuned for approximately 1000 
impressions
-       // per week.
-       var config = {
-               429700: {
-                       oneIn: 12,
-                       queries: [ 'search engine' ]
-               },
-               1140230: {
-                       oneIn: 1,
-                       queries: [ 'sailor soldier tinker spy' ]
-               },
-               4184791: {
-                       oneIn: 1,
-                       queries: [ '10 items or fewer' ]
-               },
-               28203916: {
-                       oneIn: 1,
-                       queries: [ 'block buster' ]
-               },
-               1692813: {
-                       oneIn: 1,
-                       queries: [ 'sailor soldier tinker spy' ]
-               },
-               4059023: {
-                       oneIn: 9,
-                       queries: [ 'search engine' ]
-               },
-               12432: {
-                       oneIn: 2,
-                       queries: [ 'what is a genius iq?' ]
-               },
-               54255761: {
-                       oneIn: 1,
-                       queries: [ 'who is v for vendetta?' ]
-               },
-               15170457: {
-                       oneIn: 1,
-                       queries: [ 'yesterday beetles' ]
-               },
-               4302959: {
-                       oneIn: 2,
-                       queries: [ 'what is a genius iq?' ]
-               },
-               772896: {
-                       oneIn: 1,
-                       queries: [ 'yesterday beetles' ]
-               },
-               14067873: {
-                       oneIn: 1,
-                       queries: [ 'star and stripes' ]
-               },
-               212645: {
-                       oneIn: 4,
-                       queries: [ 'why is a baby goat a kid?' ]
-               },
-               666918: {
-                       oneIn: 1,
-                       queries: [ 'star and stripes' ]
-               },
-               31840255: {
-                       oneIn: 1,
-                       queries: [ 'what is a genius iq?' ]
-               },
-               73257: {
-                       oneIn: 3,
-                       queries: [ 'who is v for vendetta?' ]
-               },
-               187946: {
-                       oneIn: 19,
-                       queries: [ 'search engine' ]
-               },
-               1891886: {
-                       oneIn: 9,
-                       queries: [ 'who is v for vendetta?' ]
-               },
-               43055: {
-                       oneIn: 5,
-                       queries: [ 'block buster' ]
-               },
-               14705456: {
-                       oneIn: 1,
-                       queries: [ 'sailor soldier tinker spy' ]
-               },
-               308913: {
-                       oneIn: 1,
-                       queries: [ 'star and stripes' ]
-               },
-               4553266: {
-                       oneIn: 1,
-                       queries: [ 'who is v for vendetta?' ]
-               },
-               2848825: {
-                       oneIn: 1,
-                       queries: [ 'yesterday beetles' ]
-               },
-               45144821: {
-                       oneIn: 1,
-                       queries: [ '10 items or fewer' ]
-               },
-               19167553: {
-                       oneIn: 7,
-                       queries: [ 'why is a baby goat a kid?' ]
-               },
-               20412995: {
-                       oneIn: 1,
-                       queries: [ '10 items or fewer' ]
-               },
-               12940960: {
-                       oneIn: 7,
-                       queries: [ 'what is a genius iq?' ]
-               },
-               1163847: {
-                       oneIn: 1,
-                       queries: [ 'why is a baby goat a kid?' ]
-               },
-               5663176: {
-                       oneIn: 1,
-                       queries: [ 'why is a baby goat a kid?' ]
-               },
-               46743209: {
-                       oneIn: 1,
-                       queries: [ '10 items or fewer' ]
-               },
-               19424330: {
-                       oneIn: 1,
-                       queries: [ 'sailor soldier tinker spy' ]
-               },
-               2111074: {
-                       oneIn: 5,
-                       queries: [ 'search engine' ]
-               },
-               33138509: {
-                       oneIn: 1,
-                       queries: [ 'what is a genius iq?' ]
-               },
-               4576465: {
-                       oneIn: 7,
-                       queries: [ 'how do flowers bloom?' ]
-               },
-               6218066: {
-                       oneIn: 1,
-                       queries: [ 'yesterday beetles' ]
-               },
-               8964793: {
-                       oneIn: 1,
-                       queries: [ '10 items or fewer' ]
-               },
-               24202203: {
-                       oneIn: 1,
-                       queries: [ 'yesterday beetles' ]
-               },
-               14064991: {
-                       oneIn: 1,
-                       queries: [ 'search engine' ]
-               },
-               2295010: {
-                       oneIn: 2,
-                       queries: [ 'how do flowers bloom?' ]
-               },
-               672166: {
-                       oneIn: 1,
-                       queries: [ 'how do flowers bloom?' ]
-               },
-               4706150: {
-                       oneIn: 1,
-                       queries: [ 'who is v for vendetta?' ]
-               },
-               11011055: {
-                       oneIn: 1,
-                       queries: [ 'how do flowers bloom?' ]
-               },
-               3818608: {
-                       oneIn: 1,
-                       queries: [ 'block buster' ]
-               },
-               638069: {
-                       oneIn: 2,
-                       queries: [ 'sailor soldier tinker spy' ]
-               },
-               1724918: {
-                       oneIn: 1,
-                       queries: [ 'block buster' ]
-               },
-               168617: {
-                       oneIn: 7,
-                       queries: [ 'star and stripes' ]
-               },
-               12820089: {
-                       oneIn: 1,
-                       queries: [ 'how do flowers bloom?' ]
-               },
-               13823739: {
-                       oneIn: 1,
-                       queries: [ 'block buster' ]
-               },
-               14203818: {
-                       oneIn: 1,
-                       queries: [ 'why is a baby goat a kid?' ]
-               },
-               560511: {
-                       oneIn: 2,
-                       queries: [ 'star and stripes' ]
-               }
-       }[ mw.config.get( 'wgArticleId' ) ];
+       // This value is coded into the page output and cached in varnish. That
+       // means any changes to sampling rates or pages chosen will take up to a
+       // week to propogate into the wild.
+       var config = mw.config.get( 'wgWMESearchRelevancePages' );
 
-       // Page is not part of this test
-       if ( config === undefined ) {
+       // bad configuration
+       if ( !config.hasOwnProperty( 'sampleRate' ) || !config.hasOwnProperty( 
'queries' ) ) {
                return;
        }
 
        // This page view not chosen for sampling
-       if ( !oneIn( config.oneIn ) ) {
+       if ( !sample( config.sampleRate ) ) {
                return;
        }
 
@@ -304,8 +104,6 @@
                } );
        }
 
-       // TODO: We probably want to vary this 60s for some AB tests, to see if 
the quality
-       // of human grades varies depending on how long we wait.
        setTimeout( askQuestion, 60000 );
 
 }( mediaWiki, jQuery ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7ae522155e67610d25b5857d7b3918559bce8bc7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikimediaEvents
Gerrit-Branch: wmf/1.30.0-wmf.17
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>
Gerrit-Reviewer: 20after4 <mmod...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to