Sbisson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/345878 )

Change subject: Make thresholds used by filters configurable
......................................................................

Make thresholds used by filters configurable

Change-Id: Id5273fda3eac819b97cbc85c25c04de0b0654f48
---
M extension.json
M includes/Stats.php
M tests/phpunit/includes/StatsTest.php
3 files changed, 69 insertions(+), 2 deletions(-)


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

diff --git a/extension.json b/extension.json
index f22a55a..325ab6c 100644
--- a/extension.json
+++ b/extension.json
@@ -136,6 +136,19 @@
                        "soft": 0.70,
                        "hard": 0.50
                },
+               "OresFiltersThresholds": {
+                       "damaging": {
+                               "likelygood": { "min": 0, "max": 0.55 },
+                               "maybebad": { "min": 0.16, "max": 1 },
+                               "likelybad": { "min": 0.75, "max": 1 },
+                               "verylikelybad": { "min": 0.92, "max": 1 }
+                       },
+                       "goodfaith": {
+                               "good": { "min": 0.35, "max": 1 },
+                               "maybebad": { "min": 0, "max": 0.65 },
+                               "bad": { "min": 0, "max": 0.15 }
+                       }
+               },
                "OresEnabledNamespaces": {},
                "OresWikiId": null,
                "OresRevisionsPerBatch": 30,
diff --git a/includes/Stats.php b/includes/Stats.php
index 8dc2774..5192e07 100644
--- a/includes/Stats.php
+++ b/includes/Stats.php
@@ -98,6 +98,12 @@
        }
 
        public function getThresholds( $model, $fromCache = true ) {
+               global $wgOresFiltersThresholds;
+
+               if ( isset( $wgOresFiltersThresholds[ $model ] ) ) {
+                       return $wgOresFiltersThresholds[ $model ];
+               }
+
                if ( isset( $this->thresholdsConfig[ $model ] ) ) {
                        return $this->parseThresholds( $this->fetchStats( 
$model, $fromCache ), $model );
                } else {
diff --git a/tests/phpunit/includes/StatsTest.php 
b/tests/phpunit/includes/StatsTest.php
index 4dafebf..c43bd57 100644
--- a/tests/phpunit/includes/StatsTest.php
+++ b/tests/phpunit/includes/StatsTest.php
@@ -4,14 +4,21 @@
 
 use MediaWiki\Logger\LoggerFactory;
 use ORES;
-use PHPUnit_Framework_TestCase;
 use WANObjectCache;
 
 /**
  * @group ORES
  * @covers ORES\Stats
  */
-class StatsTest extends PHPUnit_Framework_TestCase {
+class StatsTest extends \MediaWikiTestCase {
+
+       protected function setUp() {
+               parent::setUp();
+
+               $this->setMwGlobals( [
+                       'wgOresFiltersThresholds' => [],
+               ] );
+       }
 
        private function getLoggerMock() {
                return $this->getMockBuilder( 'Psr\Log\LoggerInterface' )
@@ -209,4 +216,45 @@
                );
        }
 
+       public function testGetThresholds_everythingWouldHaveGoneWrong() {
+               $api = $this->getMockBuilder( 'ORES\Api' )->getMock();
+               $api->method( 'request' )
+                       ->with( [ 'model_info' => 'test_stats' ], 'goodfaith' )
+                       ->willReturn( 'this is not the stat object you were 
expecting...' );
+
+               $logger = $this->getLoggerMock();
+
+               $this->setMwGlobals( [
+                       'wgOresFiltersThresholds' => [
+                               "goodfaith" => [
+                                       "good" => [ "min" => 0.7, "max" => 1 ],
+                                       "maybebad" => [ "min" => 0, "max" => 
0.69 ],
+                                       "bad" => [ "min" => 0, "max" => 0.25 ],
+                               ],
+                       ],
+               ] );
+
+               $stats = new ORES\Stats( $api, WANObjectCache::newEmpty(), 
$logger );
+
+               $thresholds = $stats->getThresholds( 'goodfaith', false );
+
+               $this->assertEquals(
+                       $thresholds,
+                       [
+                               'good' => [
+                                       'min' => 0.7,
+                                       'max' => 1,
+                               ],
+                               'maybebad' => [
+                                       'min' => 0,
+                                       'max' => 0.69,
+                               ],
+                               'bad' => [
+                                       'min' => 0,
+                                       'max' => 0.25,
+                               ]
+                       ]
+               );
+       }
+
 }

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

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

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

Reply via email to