Jdlrobson has uploaded a new change for review. https://gerrit.wikimedia.org/r/323072
Change subject: Process contributor information and how biased editing is ...................................................................... Process contributor information and how biased editing is A `contributors` property is recorded on every page with information about the editors working on an article. A bias is calculated based on the most prolific author and the total edits made. Bug: T145554 Change-Id: Ia5f289004b5b7a4ff70f852c8acd04f8117e41d2 --- M lib/processor.js M test/lib/processor.js 2 files changed, 38 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/trending-edits refs/changes/72/323072/1 diff --git a/lib/processor.js b/lib/processor.js index b5d9482..23e1188 100644 --- a/lib/processor.js +++ b/lib/processor.js @@ -16,11 +16,12 @@ * @param {Object} edit */ function process(edit) { - var page; + var page, contributors; var id = edit.page_id; var ts = edit.rev_timestamp; var performer = edit.performer; var isAnon = edit.performer.user_id === undefined; + var username = performer.user_text; var topic = edit.meta.topic; if (topic === 'mediawiki.page-delete') { @@ -38,11 +39,27 @@ pages[id].updated = ts; } else { pages[id] = { id: id, edits: 1, from: ts, updated: ts, - anonEdits: 0, + anonEdits: 0, contributors: { total: 0, anons: 0, names: {}, main: username }, title: edit.page_title }; } + contributors = pages[id].contributors; if (isAnon) { pages[id].anonEdits += 1; + if (!contributors.names[username]) { + contributors.anons++; + } + } + if (!contributors.names[username]) { + contributors.total++; + contributors.names[username] = { + edits: 1 + }; + } else { + contributors.names[username].edits++; + } + if (contributors.names[username].edits > contributors.names[contributors.main].edits) { + contributors.main = username; + pages[id].bias = contributors.names[contributors.main].edits / pages[id].edits; } } } diff --git a/test/lib/processor.js b/test/lib/processor.js index 34446e1..4d7a5c7 100644 --- a/test/lib/processor.js +++ b/test/lib/processor.js @@ -78,6 +78,25 @@ assert.ok( pages[0].from === '2016-11-15T18:00:55+00:00', 'from is timestamp of first recorded edit' ); }); + it('check processing of contributors', function() { + processor.reset(); + processor.process( edit( 1, 'Jon', '2016-11-15T18:00:55+00:00' ) ); + processor.process( edit( 1, 'Jon', '2016-11-15T18:02:55+00:00' ) ); + processor.process( edit( 1, 'Bernd', '2016-11-15T18:03:55+00:00' ) ); + processor.process( edit( 1, 'Bernd', '2016-11-15T18:03:55+00:00' ) ); + processor.process( edit( 1, 'Bernd', '2016-11-15T18:03:55+00:00' ) ); + processor.process( edit( 1, '127.0.0.1', '2016-11-15T18:03:55+00:00' ) ); + processor.process( edit( 1, '127.0.0.5', '2016-11-15T18:03:55+00:00' ) ); + processor.process( edit( 1, '127.0.0.1', '2016-11-15T18:03:55+00:00' ) ); + + var pages = processor.getPages(); + assert.ok( pages[0].contributors.total === 4, 'Total unique editors is tallied up.' ); + assert.ok( pages[0].contributors.anons === 2, 'Total unique anon edits is tallied up.' ); + assert.ok( pages[0].contributors.names.Jon.edits === 2, 'Edits by Jon counted' ); + assert.ok( pages[0].contributors.names['127.0.0.5'].edits === 1, 'Edits by anon counted' ); + assert.ok( pages[0].contributors.main === 'Bernd', 'Top editor recorded' ); + }); + it('counts the number of anonymous edits', function() { processor.reset(); processor.process( edit( 1, 'Jon', '2016-11-15T18:00:55+00:00' ) ); -- To view, visit https://gerrit.wikimedia.org/r/323072 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia5f289004b5b7a4ff70f852c8acd04f8117e41d2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/trending-edits Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits