Awight has uploaded a new change for review.

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

Change subject: [WIP] messing with thresholds
......................................................................

[WIP] messing with thresholds

Change-Id: I29cba9658cdabf9bd235415396b7125b90e56e51
FIXME: I think parts of this appear in other patches.
---
M includes/Cache.php
M includes/Hooks.php
M includes/Scoring.php
3 files changed, 47 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ORES 
refs/changes/45/259645/1

diff --git a/includes/Cache.php b/includes/Cache.php
index f2f5495..71ce16e 100644
--- a/includes/Cache.php
+++ b/includes/Cache.php
@@ -34,7 +34,7 @@
 
                                $modelVersion = $this->getModelVersion( $model 
);
 
-                               foreach ( $modelOutputs['probabilities'] as 
$class => $probability ) {
+                               foreach ( $modelOutputs['probability'] as 
$class => $probability ) {
                                        $dbData[] = array(
                                                'ores_rev' => $revid,
                                                'ores_model' => $model,
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 6fe9992..b57cc71 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -76,9 +76,8 @@
                $name, array &$tables, array &$fields, array &$conds,
                array &$query_options, array &$join_conds, FormOptions $opts
        ) {
-               global $wgOresDamagingThreshold;
-
                $tables[] = 'ores_classification';
+               $fields[] = 'ores_is_predicted';
                $fields[] = 'ores_probability';
                $join_conds['ores_classification'] = array( 'LEFT JOIN',
                        'rc_this_oldid = ores_rev AND ores_model = \'damaging\' 
' .
@@ -86,9 +85,18 @@
 
                if ( $opts->getValue( 'hidenondamaging' ) ) {
                        // Filter out non-damaging edits.
+
+                       // Only show edits predicted to be damaging.
+                       // Here's to assuming that we'll never want to set the 
threshold
+                       // lower than the precomputed cutoff.
                        $conds[] = 'ores_is_predicted = 1';
-                       $conds[] = 'ores_probability > '
-                               . wfGetDb( DB_SLAVE )->addQuotes( 
$wgOresDamagingThreshold );
+
+                       // If a threshold is set, use that to make the filter 
tighter.
+                       $threshold = Scoring::getThreshold( 'damaging' );
+                       if ( $threshold ) {
+                               $conds[] = 'ores_probability > '
+                                       . wfGetDb( DB_SLAVE )->addQuotes( 
$threshold );
+                       }
                }
 
                return true;
@@ -129,11 +137,14 @@
         * Internal helper to label matching rows
         */
        protected static function processRecentChangesList( RCCacheEntry 
$rcObj, array &$data ) {
-               global $wgOresDamagingThreshold;
-
-               $score = $rcObj->getAttribute( 'ores_probability' );
-               if ( $score && $score >= $wgOresDamagingThreshold ) {
-                       $data['recentChangesFlags']['damaging'] = true;
+               $threshold = Scoring::getThreshold( 'damaging' );
+               if ( $threshold ) {
+                       $score = $rcObj->getAttribute( 'ores_probability' );
+                       $flagged = ( $score && $score >= $threshold );
+               } else {
+                       // Use is_predicted instead.
+                       $flagged = $rcObj->getAttribute( 'ores_is_predicted' );
                }
+               $data['recentChangesFlags']['damaging'] = $flagged;
        }
 }
diff --git a/includes/Scoring.php b/includes/Scoring.php
index 3074f43..6f39db5 100644
--- a/includes/Scoring.php
+++ b/includes/Scoring.php
@@ -2,6 +2,9 @@
 
 namespace ORES;
 
+use RequestContext;
+use UnexpectedValueException;
+
 class Scoring {
        /**
         * @param integer|array $revisions Single or multiple revisions
@@ -10,7 +13,7 @@
         * @return array Results in the form returned by ORES
         * @throws RuntimeException
         */
-       public function getScores( $revisions, $models = null ) {
+       public static function getScores( $revisions, $models = null ) {
                if ( !$models ) {
                        global $wgOresModels;
                        $models = $wgOresModels;
@@ -26,4 +29,26 @@
        public static function instance() {
                return new self();
        }
+
+       /**
+        * Get the configured per-model threshold for detection as a positive 
prediction
+        *
+        * @param string $model Name of the model you want the threshold for
+        * @return float Threshold, between [0, 1]
+        *
+        * TODO:
+        * - Should a null value mean, use the `is_predicted` value?
+        * - Some interesting things should happen here, e.g. per-user settings.
+        */
+       public static function getThreshold( $model ) {
+               switch ( $model ) {
+                       case 'damaging':
+                               $model = ucfirst( $model );
+                               $variable = "Ores{$model}Threshold";
+                               break;
+                       default:
+                               throw new UnexpectedValueException( "No 
threshold set for model [{$model}]." );
+               }
+               return RequestContext::getMain()->getConfig( $variable );
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I29cba9658cdabf9bd235415396b7125b90e56e51
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>

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

Reply via email to