def test_namespace_edits_with_multiple_namespaces(self):
        cohort = self.session.query(Cohort).filter_by(name='test').one()

        metric = NamespaceEdits(
            namespaces=[0, 209],
            start_date='2013-06-01',
            end_date='2013-08-06',
        )
        report = MetricReport(metric, list(cohort), 'enwiki')
        results = report.task.delay(report).get()

        assert_true(results is not None)
        assert_equal(results[self.test_mediawiki_user_id]['edits'], 3)
    def test_timeseries_day(self):
        metric = NamespaceEdits(
            namespaces=[0],
            start_date='2012-12-31 10:00:00',
            end_date='2013-01-02 00:00:00',
            timeseries=TimeseriesChoices.DAY,
        )
        results = metric(self.editor_ids, self.mwSession)

        assert_equal(results[self.editors[0].user_id]['edits'], {
            '2012-12-31 10:00:00': 1,
            '2013-01-01 00:00:00': 2,
        })
    def test_runs_for_an_entire_wiki(self):
        self.common_cohort_1(cohort=False)
        metric = NamespaceEdits(
            namespaces=[0],
            start_date='2012-12-31 22:59:59',
            end_date='2013-01-01 12:00:00',
        )
        results = metric(None, self.mwSession)

        assert_equal(len(results), 8)
        assert_equal(results[self.editors[0].user_id]['edits'], 3)
        assert_equal(results[self.editors[1].user_id]['edits'], 1)
        # NOTE: this is a bit precarious as it assumes the order of test data inserts
        assert_equal(results[self.editors[0].user_id + 4]['edits'], 3)
    def test_uses_date_range(self):

        metric = NamespaceEdits(namespaces=[0], )
        assert_true(not metric.validate())

        metric = NamespaceEdits(
            namespaces=[0],
            start_date='2013-07-01',
            end_date='2013-07-02',
        )
        metric.fake_csrf()
        assert_true(metric.validate())

        results = metric(list(self.cohort), self.mwSession)
        print results
        assert_equal(results[self.dan_id]['edits'], 1)
Example #5
0
    def test_timeseries_day(self):
        metric = NamespaceEdits(
            namespaces=[0],
            start_date='2012-12-31 00:00:00',
            end_date='2013-01-03 00:00:00',
            timeseries=TimeseriesChoices.DAY,
        )
        options = {
            'individualResults': True,
            'aggregateResults': True,
            'aggregateSum': True,
            'aggregateAverage': True,
            'aggregateStandardDeviation': True,
        }

        ar = AggregateReport(
            metric,
            self.cohort,
            options,
            user_id=self.owner_user_id,
        )
        results = ar.task.delay(ar).get()

        self.session.commit()

        assert_equals(
            results[Aggregation.IND][self.editor(0)]['edits'], {
                '2012-12-31 00:00:00': 1,
                '2013-01-01 00:00:00': 2,
                '2013-01-02 00:00:00': 0,
            })
        assert_equals(
            results[Aggregation.SUM]['edits'], {
                '2012-12-31 00:00:00': 1,
                '2013-01-01 00:00:00': 5,
                '2013-01-02 00:00:00': 2,
            })
        assert_equals(
            results[Aggregation.AVG]['edits'], {
                '2012-12-31 00:00:00': r(0.25),
                '2013-01-01 00:00:00': r(1.25),
                '2013-01-02 00:00:00': r(0.5),
            })
        assert_equals(
            results[Aggregation.STD]['edits'], {
                '2012-12-31 00:00:00': r(0.4330),
                '2013-01-01 00:00:00': r(0.4330),
                '2013-01-02 00:00:00': r(0.8660),
            })
    def test_namespace_edits_with_multiple_namespaces(self):
        metric = NamespaceEdits(
            namespaces=[0, 209],
            start_date='2012-12-31 22:59:59',
            end_date='2013-01-01 12:00:00',
        )
        report = MetricReport(metric, self.cohort.id, self.editor_ids,
                              mediawiki_project)
        results = report.task.delay(report).get()

        # for some reason, during testing with archive, these users lose the session
        # when they're being operated on in the queue
        self.mwSession.add_all(self.editors)

        assert_true(results is not None)
        assert_equal(results[self.editor(0)]['edits'], 3)
 def test_uses_date_range(self):
     
     metric = NamespaceEdits(
         namespaces=[0],
     )
     assert_true(not metric.validate())
     
     metric = NamespaceEdits(
         namespaces=[0],
         start_date='2013-07-01',
         end_date='2013-07-02',
     )
     metric.fake_csrf()
     assert_true(metric.validate())
     
     results = metric(list(self.cohort), self.mwSession)
     print results
     assert_equal(results[self.dan_id]['edits'], 1)
 def test_validates_properly(self):
     
     metric = NamespaceEdits()
     # defaults allow this to validate
     assert_true(metric.validate())
     
     metric = NamespaceEdits(
         namespaces=[0],
         start_date='2013-06-30 00:00:00',
         end_date='2013-07-01 00:00:00',
     )
     # values above are valid
     assert_true(metric.validate())
     
     metric = NamespaceEdits(
         start_date='blah',
     )
     assert_true(not metric.validate())
    def test_time_is_included(self):
        now = datetime.now()
        form = NamespaceEdits(start_date=now)

        assert_equals(form.start_date.data, now)
    def test_time_is_excluded(self):
        today = date.today()
        form = NamespaceEdits(start_date=today)

        assert_equals(form.start_date.data, to_datetime(today))
Example #11
0
    def test_finish_timeseries(self):
        metric = NamespaceEdits(
            namespaces=[0],
            start_date='2012-12-31 00:00:00',
            end_date='2013-01-03 00:00:00',
            timeseries=TimeseriesChoices.DAY,
        )
        options = {
            'individualResults': True,
            'aggregateResults': True,
            'aggregateSum': True,
            'aggregateAverage': True,
            'aggregateStandardDeviation': True,
        }
        ar = AggregateReport(
            metric,
            self.cohort,
            options,
            user_id=self.owner_user_id,
        )

        finished = ar.finish([
            {
                1: {
                    'edits': {
                        'date1': 1,
                        'date2': 2
                    }
                },
                2: {
                    'edits': {
                        'date1': 0,
                        'date2': 1
                    }
                },
                3: {
                    'edits': {
                        'date1': 0,
                        'date2': 0
                    }
                },
                None: {
                    'edits': {
                        'date1': None,
                        'date2': None
                    }
                }
            },
        ])

        assert_equals(finished[Aggregation.SUM]['edits'], {
            'date1': 1,
            'date2': 3
        })
        assert_equals(finished[Aggregation.AVG]['edits'], {
            'date1': r(0.3333),
            'date2': r(1.0)
        })
        assert_equals(finished[Aggregation.STD]['edits'], {
            'date1': r(0.4714),
            'date2': r(0.8165)
        })

        finished = ar.finish([
            {
                1: {
                    'other_sub_metric': {
                        'date3': r(2.3),
                        'date4': 0
                    }
                },
                2: {
                    'other_sub_metric': {
                        'date3': 0,
                        'date4': r(3.4)
                    }
                },
                3: {
                    'other_sub_metric': {
                        'date3': None,
                        'date4': None
                    }
                },
                None: {
                    'other_sub_metric': {
                        'date3': None,
                        'date4': None
                    }
                }
            },
        ])

        assert_equals(finished[Aggregation.SUM]['other_sub_metric'], {
            'date3': r(2.3),
            'date4': r(3.4)
        })
        assert_equals(finished[Aggregation.AVG]['other_sub_metric'], {
            'date3': r(1.15),
            'date4': r(1.7)
        })
        assert_equals(finished[Aggregation.STD]['other_sub_metric'], {
            'date3': r(1.15),
            'date4': r(1.7)
        })
 def test_mediawiki_date(self):
     edits = NamespaceEdits(start_date='2013-06-01')
     mw_date = mediawiki_date(edits.start_date)
     assert_equals(mw_date, '20130601000000')