Gilles has uploaded a new change for review.

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

Change subject: [WIP] Variant logging
......................................................................

[WIP] Variant logging

This allows to compare the difference on key metrics between
Media Viewer variants. If Media Viewer's key success metric is the amount of 
images viewed with it, a variant that yields more views should
be considered more effective.

In order to test drive this feature, 3 variants are introduced. A control
baseline, a version of the viewer without the animation after the blurred
placeholder and a version without any blurring applied to the placeholder.

This changeset still needs test coverage and a little function documentation.

Bug: T87184
Bug: T71609
Change-Id: Ia8f0149df0371fb809d5b8b40c7d8bcda1fa9c64
---
M MultimediaViewer.php
M MultimediaViewerHooks.php
A resources/mmv/logging/mmv.logging.VariantLogger.js
M resources/mmv/mmv.js
M resources/mmv/ui/mmv.ui.canvas.js
5 files changed, 131 insertions(+), 3 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer 
refs/changes/58/186158/1

diff --git a/MultimediaViewer.php b/MultimediaViewer.php
index d2eb903..91ff8bd 100644
--- a/MultimediaViewer.php
+++ b/MultimediaViewer.php
@@ -125,6 +125,26 @@
        $wgMediaViewerRecordViewDuration = false;
 }
 
+if ( !isset( $wgMediaViewerVariantSamplingFactor ) ) {
+       /**
+        * If set, serves a variant of Media Viewer undergoing testing. A value 
of 1000 means there will be an
+        * 1:1000 chance to use any variant instead of the default Media Viewer 
experience.
+        * False if unset.
+        * @var int|bool
+        */
+       $wgMediaViewerVariantSamplingFactor = false;
+}
+
+if ( !isset( $wgMediaViewerVariants ) ) {
+       /**
+        * If set, defines the keys for the Media Viewer variants being tested. 
Each variant will be served
+        * as much as the other ones.
+        * False if unset.
+        * @var array|bool
+        */
+       $wgMediaViewerVariants = false;
+}
+
 $wgMessagesDirs['MultimediaViewer'] = __DIR__ . '/i18n';
 $wgExtensionMessagesFiles['MultimediaViewer'] = __DIR__ . 
'/MultimediaViewer.i18n.php';
 
@@ -924,6 +944,7 @@
                        'mmv.routing',
                        'mmv.logging.DurationLogger',
                        'mmv.logging.DimensionLogger',
+                       'mmv.logging.VariantLogger',
                        'mmv.logging.ViewLogger',
                        'jquery.fullscreen',
                        'jquery.hidpi',
@@ -1030,6 +1051,18 @@
                ),
        ),
 
+       'mmv.logging.VariantLogger' => $wgMediaViewerResourceTemplate + array(
+               'scripts' => array(
+                       'mmv/logging/mmv.logging.VariantLogger.js',
+               ),
+
+               'dependencies' => array(
+                       'mmv.base',
+                       'mmv.logging.Logger',
+                       'oojs',
+               ),
+       ),
+
        'mmv.logging.ViewLogger' => $wgMediaViewerResourceTemplate + array(
                'scripts' => array(
                        'mmv/logging/mmv.logging.ViewLogger.js',
@@ -1074,6 +1107,7 @@
                'MultimediaViewerDuration' => 10427980,
                'MultimediaViewerAttribution' => 9758179,
                'MultimediaViewerDimensions' => 10014238,
+               'MultimediaViewerVariant' => 11030166,
        );
 };
 
@@ -1087,6 +1121,7 @@
                
$wgResourceModules['mmv.logging.DurationLogger']['dependencies'][] = 
'ext.eventLogging';
                
$wgResourceModules['mmv.logging.AttributionLogger']['dependencies'][] = 
'ext.eventLogging';
                
$wgResourceModules['mmv.logging.DimensionLogger']['dependencies'][] = 
'ext.eventLogging';
+               
$wgResourceModules['mmv.logging.VariantLogger']['dependencies'][] = 
'ext.eventLogging';
        }
 
        if ( $wgMediaViewerEnableByDefault ) {
diff --git a/MultimediaViewerHooks.php b/MultimediaViewerHooks.php
index dcd8960..7b6ba78 100644
--- a/MultimediaViewerHooks.php
+++ b/MultimediaViewerHooks.php
@@ -150,7 +150,7 @@
                       $wgMediaViewerDurationLoggingSamplingFactor, 
$wgMediaViewerDurationLoggingLoggedinSamplingFactor,
                       $wgMediaViewerAttributionLoggingSamplingFactor, 
$wgMediaViewerDimensionLoggingSamplingFactor,
                       $wgMediaViewerIsInBeta, 
$wgMediaViewerUseThumbnailGuessing, $wgMediaViewerImageQueryParameter,
-                      $wgMediaViewerRecordViewDuration;
+                      $wgMediaViewerRecordViewDuration, 
$wgMediaViewerVariantSamplingFactor, $wgMediaViewerVariants;
 
                $vars['wgMultimediaViewer'] = array(
                        'infoLink' => self::$infoLink,
@@ -166,6 +166,8 @@
                        'imageQueryParameter' => 
$wgMediaViewerImageQueryParameter,
                        'recordViewDuration' => 
$wgMediaViewerRecordViewDuration,
                        'tooltipDelay' => 1000,
+                       'variantSamplingFactor' => 
$wgMediaViewerVariantSamplingFactor,
+                       'variants' => $wgMediaViewerVariants,
                );
                $vars['wgMediaViewer'] = true;
                $vars['wgMediaViewerIsInBeta'] = $wgMediaViewerIsInBeta;
diff --git a/resources/mmv/logging/mmv.logging.VariantLogger.js 
b/resources/mmv/logging/mmv.logging.VariantLogger.js
new file mode 100644
index 0000000..d414637
--- /dev/null
+++ b/resources/mmv/logging/mmv.logging.VariantLogger.js
@@ -0,0 +1,85 @@
+/*
+ * This file is part of the MediaWiki extension MediaViewer.
+ *
+ * MediaViewer 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.
+ *
+ * MediaViewer 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 MediaViewer.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+( function ( mw, $, oo ) {
+       var L;
+
+       /**
+        * Writes EventLogging entries for variant actions
+        * @class mw.mmv.logging.VariantLogger
+        * @extends mw.mmv.logging.Logger
+        * @constructor
+        */
+       function VariantLogger() {
+       }
+
+       oo.inheritClass( VariantLogger, mw.mmv.logging.Logger );
+
+       L = VariantLogger.prototype;
+
+       L.variants = mw.config.get( 'wgMultimediaViewer' ).variants;
+
+       /**
+        * @override
+        * @inheritdoc
+        */
+       L.samplingFactor = mw.config.get( 'wgMultimediaViewer' 
).variantSamplingFactor;
+
+       /**
+        * @override
+        * @inheritdoc
+        */
+       L.schema = 'MultimediaViewerVariant';
+
+       if ( !$.isNumeric( L.samplingFactor )
+               || L.samplingFactor < 1
+               || !$.isArray( L.variants )
+               || Math.floor( Math.random() * L.samplingFactor ) !== 0 ) {
+               L.variant = false;
+               mw.log( 'Running Media Viewer with no variant' );
+       } else {
+               L.variant = L.variants[ Math.floor( Math.random() * 
L.variants.length ) ];
+               mw.log( 'Running Media Viewer with variant', L.variant );
+       }
+
+       L.is = function( variant ) {
+               return L.variant === variant;
+       }
+
+       L.isAny = function ( variants ) {
+               return $.inArray( L.variant, variants );
+       }
+
+       /**
+        * @override
+        * @inheritdoc
+        */
+       L.log = function( action ) {
+               if ( !L.variant ) {
+                       return;
+               }
+
+               data = {};
+               data[ 'variant' ] = L.variant;
+               data[ 'action' ] = action;
+
+               mw.log( 'mw.mmv.logging.VariantLogger', data );
+               return mw.mmv.logging.Logger.prototype.log.call( this, data );
+       }
+
+       mw.mmv.variantLogger = new VariantLogger();
+} ( mediaWiki, jQuery, OO ) );
diff --git a/resources/mmv/mmv.js b/resources/mmv/mmv.js
index 6368a95..804ef46 100644
--- a/resources/mmv/mmv.js
+++ b/resources/mmv/mmv.js
@@ -430,7 +430,7 @@
 
                // We only animate unblurWithAnimation if the image wasn't 
loaded from the cache
                // A load in < 10ms is considered to be a browser cache hit
-               if ( this.blurredThumbnailShown && loadTime > 10 ) {
+               if ( this.blurredThumbnailShown && loadTime > 10 && 
!mw.mmv.variantLogger.isAny( [ 'no-blur-animation', 'no-blur' ] ) ) {
                        this.ui.canvas.unblurWithAnimation();
                } else {
                        this.ui.canvas.unblur();
@@ -441,6 +441,8 @@
                mw.mmv.actionLogger.log( 'image-view' ).then( function ( 
wasEventLogged ) {
                        viewer.viewLogger.setLastViewLogged( wasEventLogged );
                } );
+
+               mw.mmv.variantLogger.log( 'image-view' );
        };
 
        /**
@@ -828,6 +830,7 @@
         */
        MMVP.nextImage = function () {
                mw.mmv.actionLogger.log( 'next-image' );
+               mw.mmv.variantLogger.log( 'next-image' );
                this.loadIndex( this.currentIndex + 1 );
        };
 
@@ -836,6 +839,7 @@
         */
        MMVP.prevImage = function () {
                mw.mmv.actionLogger.log( 'prev-image' );
+               mw.mmv.variantLogger.log( 'prev-image' );
                this.loadIndex( this.currentIndex - 1 );
        };
 
diff --git a/resources/mmv/ui/mmv.ui.canvas.js 
b/resources/mmv/ui/mmv.ui.canvas.js
index 07ed90f..470bdb2 100644
--- a/resources/mmv/ui/mmv.ui.canvas.js
+++ b/resources/mmv/ui/mmv.ui.canvas.js
@@ -293,7 +293,9 @@
 
                // Only blur the placeholder if it's blown up significantly
                if ( blowupFactor > Canvas.BLUR_BLOWUP_FACTOR_THRESHOLD ) {
-                       this.blur( $imagePlaceholder );
+                       if ( !mw.mmv.variantLogger.is( 'no-blur' ) ) {
+                               this.blur( $imagePlaceholder );
+                       }
                        blurredThumbnailShown = true;
                }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia8f0149df0371fb809d5b8b40c7d8bcda1fa9c64
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MultimediaViewer
Gerrit-Branch: master
Gerrit-Owner: Gilles <gdu...@wikimedia.org>

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

Reply via email to