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

Change subject: Include reverts from bots
......................................................................

Include reverts from bots

Reverts from bots e.g. ClueBot are important for detecting
vandalism. Include any reverts that bots make in counts for reverts
and bytes changed but not total edits.

Bug: T164558
Change-Id: I0b84803b474244214a2fabfff18a36575d8d748d
---
M lib/EventProcessor.js
M test/features/lib/EventProcessor.js
2 files changed, 36 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/trending-edits 
refs/changes/53/352553/1

diff --git a/lib/EventProcessor.js b/lib/EventProcessor.js
index 5634d5f..65ae357 100644
--- a/lib/EventProcessor.js
+++ b/lib/EventProcessor.js
@@ -88,6 +88,7 @@
         var username = performer.user_text;
         var topic = edit.meta.topic;
         const pages = this.pages;
+        let isBot = performer.user_is_bot;
 
         // ignore the event if it isn't related to enwiki
         if (!/^en\.wikipedia\./.test(edit.meta.domain)) {
@@ -104,16 +105,14 @@
             page.edits -= 1;
             return true;
         } else if (topic === 'mediawiki.revision-create' && 
!edit.page_is_redirect &&
-                !performer.user_is_bot && edit.page_namespace === 0) {
+                edit.page_namespace === 0) {
             if (pages.has(id)) {
                 page = pages.get(id);
-                page.edits++;
-                page.updated = ts;
             } else {
                 page = {
                     id: id,
                     isNew: edit.rev_parent_id === undefined,
-                    edits: 1,
+                    edits: 0,
                     from: ts,
                     updated: ts,
                     rev_len: edit.rev_len,
@@ -129,22 +128,31 @@
                     domain: edit.meta.domain
                 };
             }
-            contributors = page.contributors;
-            if (isAnon) {
-                page.anonEdits += 1;
+            var bytesChanged = edit.rev_len - page.rev_len;
+            if (!isBot) {
+                page.edits++;
+                page.updated = ts;
+                page.bytes = bytesChanged;
+
+                contributors = page.contributors;
+                if (isAnon) {
+                    page.anonEdits += 1;
+                    if (!contributors.names[username]) {
+                        contributors.anons++;
+                    }
+                }
                 if (!contributors.names[username]) {
-                    contributors.anons++;
+                    contributors.total++;
+                    contributors.names[username] = 1;
+                } else {
+                    contributors.names[username]++;
                 }
             }
-            if (!contributors.names[username]) {
-                contributors.total++;
-                contributors.names[username] = 1;
-            } else {
-                contributors.names[username]++;
-            }
-            page.bytes = edit.rev_len - page.rev_len;
             if (isRevert(edit)) {
                 page.reverts++;
+                if (isBot) {
+                    page.bytes = bytesChanged;
+                }
             }
             // update
             pages.set(id, page);
diff --git a/test/features/lib/EventProcessor.js 
b/test/features/lib/EventProcessor.js
index b01462f..04298b3 100644
--- a/test/features/lib/EventProcessor.js
+++ b/test/features/lib/EventProcessor.js
@@ -83,6 +83,19 @@
             'from is timestamp of first recorded edit' );
     });
 
+    it('check reverts from bots are included in data collation', function() {
+        var processor = new EventProcessor({});
+        processor.process( edit( 1, 'Nice', '2016-11-15T18:00:55+00:00', 0, 
false, { rev_len: 20 } ) );
+        processor.process( edit( 1, 'Vandal', '2016-11-15T18:00:55+00:00', 0, 
false, { rev_len: 30 } ) );
+        processor.process( edit( 1, 'Bot', '2016-11-15T18:03:55+00:00', 0, 
true,
+            { rev_len: 20, comment: 'Reverting 1 edit'} ) );
+        var pages = processor.getPages();
+        assert.ok( pages.length === 1, 'Pages with same name are combined into 
single page' );
+        assert.ok( pages[0].edits === 2, 'Edits are counted for all non-bot 
edits' );
+        assert.ok( pages[0].bytes === 0, 'Bytes calculation include reverts 
from bots' );
+        assert.ok( pages[0].reverts === 1, 'Revert is included' );
+    });
+
     it('check processing of contributors', function() {
         var processor = new EventProcessor({});
         processor.process( edit( 1, 'Jon', '2016-11-15T18:00:55+00:00' ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0b84803b474244214a2fabfff18a36575d8d748d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/trending-edits
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

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

Reply via email to