Esempio n. 1
0
    def test_display_dataset(self):
        # Test that a newer dataset with display=False isn't returned.
        factories.DataSetFactory(display=False)

        response = self.client.get(
            reverse('metric', args=[self.flag_metric.id]))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['dataSet'], self.dataset.name)
Esempio n. 2
0
    def test_display(self):
        # Test that a newer experiment with display=False isn't returned.
        factories.DataSetFactory(display=False)

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        data = response.json()
        self.assertEqual(len(data['experiments']), 2)
        self.assertEqual(data['experiments'][0]['id'], self.dataset.id)
        self.assertEqual(data['experiments'][1]['id'], self.dataset_older.id)
Esempio n. 3
0
    def setUpTestData(cls):
        # This will create 3 datasets (1 of which being hidden) with 2
        # populations of 1 metric each.

        def create_collections(dataset, population, flag_metric, count_metric):
            kwargs = {'dataset': dataset}
            if population:
                kwargs['population'] = population

            count_collection = factories.CollectionFactory(metric=count_metric,
                                                           **kwargs)
            factories.PointFactory.create_batch(3, collection=count_collection)

            flag_collection = factories.CollectionFactory(metric=flag_metric,
                                                          **kwargs)
            factories.PointFactory.create_batch(3, collection=flag_collection)

        count_metric = factories.MetricFactory(type='CountHistogram')
        flag_metric = factories.MetricFactory(type='FlagHistogram')

        # Create 2 viewable datasets.
        dataset_older = factories.DataSetFactory()
        create_collections(dataset_older, 'control', flag_metric, count_metric)
        create_collections(dataset_older, None, flag_metric, count_metric)

        dataset = factories.DataSetFactory()
        create_collections(dataset, 'control', flag_metric, count_metric)
        create_collections(dataset, None, flag_metric, count_metric)

        # Create 1 non-viewable dataset.
        dataset_hidden = factories.DataSetFactory(display=False)
        create_collections(dataset_hidden, 'control', flag_metric,
                           count_metric)
        create_collections(dataset_hidden, None, flag_metric, count_metric)

        # Save these for use in tests.
        cls.dataset = dataset
        cls.dataset_older = dataset_older
        cls.dataset_hidden = dataset_hidden
        cls.flag_metric = flag_metric
        cls.count_metric = count_metric
Esempio n. 4
0
 def test_display(self):
     # Test that an experiment with display=False isn't returned.
     dataset = factories.DataSetFactory(display=False)
     response = self.client.get(reverse('v2-experiment-by-id',
                                        args=[dataset.id]))
     assert response.status_code == 404
Esempio n. 5
0
    def setUpTestData(cls):
        # This will create 3 datasets (1 of which being hidden) with 2
        # populations of 1 metric each.

        def collections_and_points(metric, **kwargs):
            coll = factories.CollectionFactory(metric=metric, **kwargs)
            factories.PointFactory.create_batch(3, collection=coll)
            return coll

        def create_collections(dataset,
                               population,
                               flag_metric,
                               count_metric,
                               create_subgroups=True):

            kwargs = {'dataset': dataset}
            if population:
                kwargs['population'] = population

            coll = collections_and_points(count_metric, **kwargs)
            if create_subgroups:
                kwargs.pop('population', None)
                for sg in SUBGROUPS:
                    collections_and_points(count_metric,
                                           population=coll.population,
                                           subgroup=sg,
                                           **kwargs)

            if population:
                kwargs['population'] = population
            coll = collections_and_points(flag_metric, **kwargs)
            if create_subgroups:
                kwargs.pop('population', None)
                for sg in SUBGROUPS:
                    collections_and_points(flag_metric,
                                           population=coll.population,
                                           subgroup=sg,
                                           **kwargs)

        count_metric = factories.MetricFactory(type='CountHistogram')
        flag_metric = factories.MetricFactory(type='FlagHistogram')

        # Create 2 viewable datasets.
        dataset_older = factories.DataSetFactory()
        create_collections(dataset_older, 'control', flag_metric, count_metric)
        create_collections(dataset_older, 'chaos', flag_metric, count_metric)

        dataset = factories.DataSetFactory()
        create_collections(dataset, 'control', flag_metric, count_metric)
        create_collections(dataset, 'chaos', flag_metric, count_metric)

        # Create 1 non-viewable dataset.
        dataset_hidden = factories.DataSetFactory(display=False)
        create_collections(dataset_hidden,
                           'control',
                           flag_metric,
                           count_metric,
                           create_subgroups=False)
        create_collections(dataset_hidden,
                           'chaos',
                           flag_metric,
                           count_metric,
                           create_subgroups=False)

        # Create some stats tied to datasets.
        for pop in ('control', 'chaos'):
            factories.StatsFactory(dataset=dataset,
                                   metric=None,
                                   population=pop)
            factories.StatsFactory(dataset=dataset,
                                   metric=None,
                                   population=pop)

        # Save these for use in tests.
        cls.dataset = dataset
        cls.dataset_older = dataset_older
        cls.dataset_hidden = dataset_hidden
        cls.flag_metric = flag_metric
        cls.count_metric = count_metric
Esempio n. 6
0
    def setUpTestData(cls):
        scalar_metric = factories.MetricFactory(source_name='scalar_metric',
                                                type='UintScalar',
                                                description='scalar metric')
        dataset = factories.DataSetFactory()
        coll = factories.CollectionFactory(metric=scalar_metric,
                                           dataset=dataset,
                                           population='control')
        total = 3053.0
        data = {
            1: 100,
            2: 500,
            3: 300,
            4: 200,
            5: 190,
            6: 180,
            7: 170,
            8: 160,
            9: 150,
            10: 140,
            11: 130,
            12: 120,
            13: 110,
            14: 100,
            15: 90,
            16: 80,
            17: 70,
            18: 60,
            19: 50,
            20: 40,
            21: 30,
            22: 20,
            23: 10,
            24: 9,
            25: 8,
            26: 7,
            27: 6,
            28: 5,
            29: 4,
            30: 3,
            31: 2,
            32: 1,
            33: 1,
            34: 1,
            35: 1,
            36: 1,
            37: 1,
            38: 1,
            39: 1,
            40: 1
        }

        for rank, bucket in enumerate(sorted(data.keys()), 1):
            count = data[bucket]
            factories.PointFactory(collection=coll,
                                   bucket=bucket,
                                   proportion=count / total,
                                   count=count,
                                   rank=rank)

        cls.dataset = dataset
        cls.metric = scalar_metric