示例#1
0
    def test_9_populate_dataset_class_4_views_previous(self):
        dataset = self._create_package_resource()
        package = helpers.call_action('package_show', id=dataset[0]['id'], include_tracking=True)

        url = url_for(controller='package', action='read',
                             id=package['name'])
        for ip in ['44', '55', '66', '77']:
            self._post_to_tracking(url, ip='111.222.333.{}'.format(ip))
        self._update_tracking_summary()

        target_date = datetime.date.today() + datetime.timedelta(days=30)
        d = jc.Dataset(dataset[0]['id'], target_date)
        assert d.previous_month_views == 4, "Previous views should be 4: {}".format(d.previous_month_views)

        target_date = datetime.date.today() + datetime.timedelta(days=60)
        d = jc.Dataset(dataset[0]['id'], target_date)
        assert d.previous_month_views == 0, "Previous views should be 0: {}".format(d.previous_month_views)
示例#2
0
    def test_6_populate_resource_class_0_downloads(self):
        dataset, resource = self._create_package_resource(resource=True)

        r = jc.Dataset(dataset[0]['id']).resources

        assert r[0].name == resource[0][u'name'], '"{}" != "{}"'.format(r.name, resource[0][u'name'])
        assert r[0].url == resource[0][u'url'], '"{}" != "{}"'.format(r.url, resource[0][u'url'])
        assert r[0].format == resource[0][u'format'], '"{}" != "{}"'.format(r.format, resource[0][u'format'])
        assert r[0].total_downloads == 0, "Should be 0 downlaods: {}".format(r[0].total_downloads)
示例#3
0
    def test_1_populate_dataset_class_0_views_0_resources(self):
        dataset = self._create_package_resource()

        d = jc.Dataset(dataset[0]['id'])

        assert d.name == dataset[0]['title'], '"{}"" != "{}"'.format(d.name, dataset[0]['title'])
        assert len(d.resources) == 0, 'Should be 0 resoruces: {}'.format(len(d.resources))
        assert d.owner == dataset[0]['owner_org'], '"{}"" != "{}"'.format(d.owner, dataset[0]['owner_org'])
        assert d.views == 0, 'Should be 0 views: {}'.format(d.views)
        assert d.private == True, 'Should be private: {}'.format(d.private)
示例#4
0
    def test_10_populate_dataset_class_4_downloads_previous(self):
        dataset, resources = self._create_package_resource(resource=True, num_resources=2)

        url1 = resources[0]['url']
        url2 = resources[1]['url']

        for ip in ['44', '55']:
            self._post_to_tracking(url1, ip='111.222.333.{}'.format(ip), type_='resource')
            self._post_to_tracking(url2, ip='111.222.333.{}'.format(ip), type_='resource')
        self._update_tracking_summary()

        target_date = datetime.date.today() + datetime.timedelta(days=30)
        d = jc.Dataset(dataset[0]['id'], target_date)
        r = d.resources
        print(r[0])
        assert r[0].previous_month_downloads == 2, "Previous dls should be 2: {}".format(r[0].previous_month_downloads)
        assert r[1].previous_month_downloads == 2, "Previous dls should be 2: {}".format(r[1].previous_month_downloads)

        target_date = datetime.date.today() + datetime.timedelta(days=60)
        d = jc.Dataset(dataset[0]['id'], target_date)
        r = d.resources
        assert r[0].previous_month_downloads == 0, "Previous dls should be 0: {}".format(r[0].previous_month_downloads)
示例#5
0
    def test_7_populate_resource_class_1_download(self):
        dataset, resource = self._create_package_resource(resource=True)
        url = resource[0]['url']

        self._post_to_tracking(url, type_='resource')
        self._update_tracking_summary()

        r = jc.Dataset(dataset[0]['id']).resources

        assert r[0].name == resource[0][u'name'], '"{}" != "{}"'.format(r.name, resource[0][u'name'])
        assert r[0].url == resource[0][u'url'], '"{}" != "{}"'.format(r.url, resource[0][u'url'])
        assert r[0].format == resource[0][u'format'], '"{}" != "{}"'.format(r.format, resource[0][u'format'])
        assert r[0].total_downloads == 1, "Should be 1 downlaods: {}".format(r[0].total_downloads)
示例#6
0
    def test_5_populate_dataset_class_1_view_2_resource(self):
        dataset, resources = self._create_package_resource(resource=True, num_resources=2)
        package = helpers.call_action('package_show', id=dataset[0]['id'], include_tracking=True)
        url = url_for(controller='package', action='read',
                             id=package['name'])
        self._post_to_tracking(url)
        self._update_tracking_summary()

        d = jc.Dataset(dataset[0]['id'])

        assert d.name == dataset[0]['title'], '"{}" != "{}"'.format(d.name, dataset[0]['title'])
        assert len(d.resources) == 2, 'Should be 2 resource: {}'.format(len(d.resources))
        assert d.owner == dataset[0]['owner_org'], '"{}"" != "{}"'.format(d.owner, dataset[0]['owner_org'])
        assert d.views == 1, 'Should be 1 views: {}'.format(d.views)
        assert d.private == True, 'Should be private: {}'.format(d.private)
示例#7
0
    def test_3_populate_dataset_class_4_views_0_resources(self):
        dataset = self._create_package_resource()
        package = helpers.call_action('package_show', id=dataset[0]['id'], include_tracking=True)

        url = url_for(controller='package', action='read',
                             id=package['name'])
        for ip in ['44', '55', '66', '77']:
            self._post_to_tracking(url, ip='111.222.333.{}'.format(ip))
        self._update_tracking_summary()

        d = jc.Dataset(dataset[0]['id'])

        assert d.name == dataset[0]['title'], '"{}"" != "{}"'.format(d.name, dataset[0]['title'])
        assert len(d.resources) == 0, 'Should be 0 resoruces: {}'.format(len(d.resources))
        assert d.owner == dataset[0]['owner_org'], '"{}"" != "{}"'.format(d.owner, dataset[0]['owner_org'])
        assert d.views == 4, 'Should be 4 views: {}'.format(d.views)
        assert d.private == True, 'Should be private: {}'.format(d.private)
示例#8
0
    def gather_data(self, engine, journal):
        org = h.get_org(journal)
        packages = org['packages']

        views_total = h.total_views_across_journal_datasets(
            packages[0]['owner_org'], engine_check=engine)
        downloads_total = h.total_downloads_journal(packages[0]['owner_org'],
                                                    engine_check=engine)

        views_monthly = h.last_month_views_across_journal_datasets(
            packages[0]['owner_org'], engine_check=engine)
        downloads_monthly = h.total_downloads_journal(packages[0]['owner_org'],
                                                      engine_check=engine,
                                                      monthly=True)

        package_list = []
        for package in packages:
            package_list.append(jc.Dataset(engine, package['id']))
            package_list = sorted(package_list,
                                  key=lambda x: x.views,
                                  reverse=True)

        num_resources = sum([len(p.resources) for p in package_list])

        summary = [['Datasets', 'Resources', 'Total Views', 'Total Downloads'],
                   [
                       len(packages), num_resources, views_total,
                       downloads_total
                   ]]

        data = {
            'prefix': config.get('ckan.site_url'),
            'journal': org['title'],
            'summary': summary,
            'packages_text': self.create_main_text(package_list),
            'packages': self.create_main_table(package_list),
            'package_num': len(packages),
            'package_resources': num_resources,
            'package_view_total': views_total,
            'package_download_total': downloads_total,
            'package_view_monthly': views_monthly,
            'package_download_monthly': downloads_monthly,
        }
        #'organization': h.get_org(packages[0]['owner_org']),
        return data
示例#9
0
    def test_8_populate_multi_resource_classes_multi_download(self):
        datasets, resources = self._create_package_resource(resource=True, num_resources=3)

        url1 = resources[0]['url']
        url2 = resources[1]['url']
        url3 = resources[2]['url']

        for ip in ['44', '55', '77', '88']:
            self._post_to_tracking(url1, ip='111.222.333.{}'.format(ip), type_='resource')
            self._post_to_tracking(url2, ip='111.222.333.{}'.format(ip), type_='resource')
        self._post_to_tracking(url3, type_='resource')
        self._update_tracking_summary()

        d = jc.Dataset(datasets[0]['id'])
        r = d.resources

        assert d.total_downloads == 9, 'Should be 9 downloads: {}'.format(d.total_downloads)
        assert r[0].total_downloads == 4, 'Should be 4: {}'.format(r[0].total_downlaods)
        assert r[1].total_downloads == 4, 'Should be 4: {}'.format(r[1].total_downlaods)
        assert r[2].total_downloads == 1, 'Should be : {}'.format(r[2].total_downlaods)