Matthias Mullie has uploaded a new change for review.

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


Change subject: (bug 37427) Filtering by "helpfulness", ranking mistake
......................................................................

(bug 37427) Filtering by "helpfulness", ranking mistake

Changed "helpful" filter to be based on the percentage of helpful/unhelpful, 
not the absolute difference.

E.g.: 10x helpful & 4x unhelpful (10 - 4 = 6) would have outranked 5x helpful & 
0x unhelpful (5 - 0 = 5)
This was especially confusing since the helpfulness is displayed to users as a 
percentage, which is not what the sort was actually based on.

Bug: 37427
Change-Id: I611f2c73244f97e80956cfbf07dbb548df17bc58
---
M ArticleFeedbackv5.hooks.php
M ArticleFeedbackv5.model.php
M ArticleFeedbackv5.render.php
M ArticleFeedbackv5.utils.php
M sql/ArticleFeedbackv5.sql
A sql/percentage_helpful.sql
6 files changed, 33 insertions(+), 23 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticleFeedbackv5 
refs/changes/62/62962/1

diff --git a/ArticleFeedbackv5.hooks.php b/ArticleFeedbackv5.hooks.php
index e661153..e8e0f05 100644
--- a/ArticleFeedbackv5.hooks.php
+++ b/ArticleFeedbackv5.hooks.php
@@ -91,6 +91,12 @@
                        dirname( __FILE__ ) . '/sql/discuss.sql'
                );
 
+               $updater->addExtensionField(
+                       'aft_feedback',
+                       'aft_percentage_helpful',
+                       dirname( __FILE__ ) . '/sql/percentage_helpful.sql'
+               );
+
                return true;
        }
 
diff --git a/ArticleFeedbackv5.model.php b/ArticleFeedbackv5.model.php
index 59a22f1..e80c7eb 100644
--- a/ArticleFeedbackv5.model.php
+++ b/ArticleFeedbackv5.model.php
@@ -53,6 +53,7 @@
                // even more denormalized stuff, allowing easy DB-indexing sort 
columns
                $aft_has_comment,
                $aft_net_helpful = 0,
+               $aft_percentage_helpful = 0,
                $aft_relevance_score = 0;
 
        /**
@@ -181,7 +182,7 @@
        public static $sorts = array(
                'relevance' => 'aft_relevance_score',
                'age' => 'aft_timestamp',
-               'helpful' => 'aft_net_helpful'
+               'helpful' => 'aft_percentage_helpful'
        );
 
        /**
@@ -465,6 +466,7 @@
                }
 
                $this->aft_net_helpful = $this->aft_helpful - 
$this->aft_unhelpful;
+               $this->aft_percentage_helpful = $this->getHelpfulPercentage();
                $this->aft_relevance_score = $this->getRelevanceScore();
                $this->aft_has_comment = (bool) $this->aft_comment;
                $this->aft_archive_date = $this->getArchiveDate();
@@ -481,6 +483,7 @@
         */
        public function update() {
                $this->aft_net_helpful = $this->aft_helpful - 
$this->aft_unhelpful;
+               $this->aft_percentage_helpful = $this->getHelpfulPercentage();
                $this->aft_relevance_score = $this->getRelevanceScore();
                $this->aft_has_comment = (bool) $this->aft_comment;
                $this->aft_archive_date = $this->getArchiveDate();
@@ -558,6 +561,19 @@
        }
 
        /**
+        * Calculate the helpfulness percentage
+        *
+        * @return int
+        */
+       public function getHelpfulPercentage() {
+               if ( $this->aft_helpful + $this->aft_unhelpful > 0 ) {
+                       return intval( $this->aft_helpful / ( 
$this->aft_helpful + $this->aft_unhelpful ) * 100 );
+               }
+
+               return 0;
+       }
+
+       /**
         * Calculate the relevance score based on the actions performed
         *
         * @return int
diff --git a/ArticleFeedbackv5.render.php b/ArticleFeedbackv5.render.php
index 55e7a12..8f34b81 100644
--- a/ArticleFeedbackv5.render.php
+++ b/ArticleFeedbackv5.render.php
@@ -607,12 +607,8 @@
                } elseif ( $this->isAllowed( 'aft-editor' ) ) {
                        $percent =
                                wfMessage( 
'articlefeedbackv5-form-helpful-votes-percent' )
-                                       ->numParams(
-                                               
ArticleFeedbackv5Utils::percentHelpful(
-                                                       $record->aft_helpful,
-                                                       $record->aft_unhelpful
-                                               )
-                                       )->escaped();
+                                       ->numParams( 
$record->getHelpfulPercentage() )
+                                       ->escaped();
 
                        $counts =
                                wfMessage( 
'articlefeedbackv5-form-helpful-votes-count' )
diff --git a/ArticleFeedbackv5.utils.php b/ArticleFeedbackv5.utils.php
index fef25d0..bcf97b4 100644
--- a/ArticleFeedbackv5.utils.php
+++ b/ArticleFeedbackv5.utils.php
@@ -226,20 +226,6 @@
        }
 
        /**
-        * Returns the percentage helpful, given a helpful count and an 
unhelpful count
-        *
-        * @param  $helpful   int the number of helpful votes
-        * @param  $unhelpful int the number of unhelpful votes
-        * @return int        the percentage
-        */
-       public static function percentHelpful( $helpful, $unhelpful ) {
-               if ( $helpful + $unhelpful > 0 ) {
-                       return intval( ( $helpful / ( $helpful + $unhelpful ) ) 
* 100 );
-               }
-               return 0;
-       }
-
-       /**
         * Helper function to create a mask line
         *
         * @param string $type the type (hidden or oversight)
diff --git a/sql/ArticleFeedbackv5.sql b/sql/ArticleFeedbackv5.sql
index 7b7e0d7..503219f 100644
--- a/sql/ArticleFeedbackv5.sql
+++ b/sql/ArticleFeedbackv5.sql
@@ -30,18 +30,19 @@
   aft_unhelpful integer unsigned NOT NULL DEFAULT 0,
   aft_has_comment boolean NOT NULL DEFAULT 0,
   aft_net_helpful integer NOT NULL DEFAULT 0,
+  aft_percentage_helpful integer NOT NULL DEFAULT 0,
   aft_relevance_score integer NOT NULL DEFAULT 0
 ) /*$wgDBTableOptions*/;
 
 -- sort indexes (central feedback page; lots of data - more details indexes 
for most popular actions)
 CREATE INDEX /*i*/relevance ON /*_*/aft_feedback (aft_relevance_score, aft_id, 
aft_has_comment, aft_oversight, aft_archive, aft_hide);
 CREATE INDEX /*i*/age ON /*_*/aft_feedback (aft_timestamp, aft_id, 
aft_has_comment, aft_oversight, aft_archive, aft_hide);
-CREATE INDEX /*i*/helpful ON /*_*/aft_feedback (aft_net_helpful, aft_id, 
aft_has_comment, aft_oversight, aft_archive, aft_hide);
+CREATE INDEX /*i*/helpful ON /*_*/aft_feedback (aft_percentage_helpful, 
aft_id, aft_has_comment, aft_oversight, aft_archive, aft_hide);
 
 -- page-specific
 CREATE INDEX /*i*/relevance_page ON /*_*/aft_feedback (aft_page, 
aft_relevance_score);
 CREATE INDEX /*i*/age_page ON /*_*/aft_feedback (aft_page, aft_timestamp);
-CREATE INDEX /*i*/helpful_page ON /*_*/aft_feedback (aft_page, 
aft_net_helpful);
+CREATE INDEX /*i*/helpful_page ON /*_*/aft_feedback (aft_page, 
aft_percentage_helpful);
 
 -- index for archive-job
 CREATE INDEX /*i*/archive_queue ON /*_*/aft_feedback (aft_archive, 
aft_archive_date);
diff --git a/sql/percentage_helpful.sql b/sql/percentage_helpful.sql
new file mode 100644
index 0000000..2edf25e
--- /dev/null
+++ b/sql/percentage_helpful.sql
@@ -0,0 +1,5 @@
+ALTER TABLE /*_*/aft_feedback
+  ADD COLUMN aft_percentage_helpful integer NOT NULL DEFAULT 0;
+
+UPDATE /*_*/aft_feedback
+  SET aft_percentage_helpful = IF(aft_helpful + aft_unhelpful > 0, aft_helpful 
/ ( aft_helpful + aft_unhelpful ) * 100, 0);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I611f2c73244f97e80956cfbf07dbb548df17bc58
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticleFeedbackv5
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>

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

Reply via email to