Milimetric has uploaded a new change for review. https://gerrit.wikimedia.org/r/81282
Change subject: pages created fix with test ...................................................................... pages created fix with test Change-Id: I30392006f3fe86d3409a530588b1bcb61b8e4e58 --- M tests/fixtures.py M tests/test_metrics/test_pages_created.py M wikimetrics/metrics/pages_created.py 3 files changed, 33 insertions(+), 16 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics refs/changes/82/81282/1 diff --git a/tests/fixtures.py b/tests/fixtures.py index 3310a5f..2eec249 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -34,21 +34,26 @@ pass # create test data for metric PagesCreated - def createTestDataMetricPagesCreated(self, user): + def createTestDataMetricPagesCreated(self, user, second_user): mw_page_evan1 = Page(page_namespace=301, page_title='Page1') mw_page_evan2 = Page(page_namespace=302, page_title='Page2') mw_page_evan3 = Page(page_namespace=303, page_title='Page3') - self.mwSession.add_all([mw_page_evan1, mw_page_evan2, mw_page_evan3]) + mw_page_dan1 = Page(page_namespace=301, page_title='Page4') + self.mwSession.add_all( + [mw_page_evan1, mw_page_evan2, mw_page_evan3, mw_page_dan1] + ) self.mwSession.commit() revisions = [] r1 = None r2 = None r3 = None + r4 = None for i in range(0, 3): parent_id1 = (0 if r1 is None else r1.rev_id) parent_id2 = (0 if r2 is None else r2.rev_id) parent_id3 = (0 if r3 is None else r3.rev_id) + parent_id4 = (0 if r4 is None else r4.rev_id) print("rev_id1=" + str(parent_id1) + "\n", sys.stderr) r1 = Revision( rev_page=mw_page_evan1.page_id, @@ -74,8 +79,16 @@ rev_len=100, rev_timestamp=datetime(2013, 8, 20) ) - revisions.append([r1, r2, r3]) - self.mwSession.add_all([r1, r2, r3]) + r4 = Revision( + rev_page=mw_page_dan1.page_id, + rev_user=second_user.user_id, + rev_comment='Dan edit ' + str(i), + rev_parent_id=parent_id4, + rev_len=100, + rev_timestamp=datetime(2013, 8, 20) + ) + revisions.append([r1, r2, r3, r4]) + self.mwSession.add_all([r1, r2, r3, r4]) self.mwSession.commit() def setUp(self): @@ -111,7 +124,7 @@ ]) self.mwSession.commit() - self.createTestDataMetricPagesCreated(mw_user_evan) + self.createTestDataMetricPagesCreated(mw_user_evan, mw_user_dan) # edits in between Dan and Evan edits rev_before_1 = Revision( diff --git a/tests/test_metrics/test_pages_created.py b/tests/test_metrics/test_pages_created.py index 23902b5..572f23e 100644 --- a/tests/test_metrics/test_pages_created.py +++ b/tests/test_metrics/test_pages_created.py @@ -19,6 +19,7 @@ ) results = metric(list(self.cohort), self.mwSession) assert_equal(results[self.evan_id]["pages_created"], 3) + assert_equal(results[self.dan_id]["pages_created"], 1) # same thing as before, but this time we leave one page created # out of the date range to see if date ranges work properly diff --git a/wikimetrics/metrics/pages_created.py b/wikimetrics/metrics/pages_created.py index bcc30b0..3f2f27f 100644 --- a/wikimetrics/metrics/pages_created.py +++ b/wikimetrics/metrics/pages_created.py @@ -60,18 +60,21 @@ if session.bind.name == 'mysql': start_date = mediawiki_date(self.start_date) end_date = mediawiki_date(self.end_date) - p = dict(session - .query(Revision.rev_user, func.count(Page.page_id)) - .join(Page) - .filter(Page.page_namespace.in_(self.namespaces.data)) - .filter(Revision.rev_parent_id == 0) - .filter(Revision.rev_user.in_(user_ids)) - .filter(Revision.rev_timestamp >= start_date) - .filter(Revision.rev_timestamp <= end_date) - .all() - ) + + pages_by_user = dict( + session + .query(Revision.rev_user, func.count(Page.page_id)) + .join(Page) + .filter(Page.page_namespace.in_(self.namespaces.data)) + .filter(Revision.rev_parent_id == 0) + .filter(Revision.rev_user.in_(user_ids)) + .filter(Revision.rev_timestamp >= start_date) + .filter(Revision.rev_timestamp <= end_date) + .group_by(Revision.rev_user) + .all() + ) return { - user_id: {'pages_created': p.get(user_id, 0)} + user_id: {'pages_created': pages_by_user.get(user_id, 0)} for user_id in user_ids } -- To view, visit https://gerrit.wikimedia.org/r/81282 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I30392006f3fe86d3409a530588b1bcb61b8e4e58 Gerrit-PatchSet: 1 Gerrit-Project: analytics/wikimetrics Gerrit-Branch: master Gerrit-Owner: Milimetric <dandree...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits