Exemple #1
0
def get_ddg_site_statistics():
    stats = {}
    stats['dataset_count'] = logic.get_action('package_search')({}, {
        "rows": 1
    })['count']
    stats['group_count'] = len(logic.get_action('group_list')({}, {}))
    stats['organization_count'] = len(
        logic.get_action('organization_list')({}, {}))

    result = model.Session.execute('''select count(*) from related r
           left join related_dataset rd on r.id = rd.related_id
           where rd.status = 'active' or rd.id is null''').first()[0]
    stats['related_count'] = result

    stats['unpub_data_count'] = 0
    for fDict in logic.get_action('package_search')(
        {}, {
            "facet.field": ["unpublished"],
            "rows": 1
        })['search_facets']['unpublished']['items']:
        if fDict['name'] == "Unpublished datasets":
            stats['unpub_data_count'] = fDict['count']
            break

    stats['open_count'] = logic.get_action('package_search')({}, {
        "fq": "isopen:true",
        "rows": 1
    })['count']

    stats['api_count'] = logic.get_action('resource_search')({}, {
        "query": ["format:wms"]
    })['count'] + len(datastore_db.get_all_resources_ids_in_datastore())

    return stats
        def fetch_summary_stats():
            connection = model.Session.connection()
            try:
                from ckanext.datastore.db import (
                    get_all_resources_ids_in_datastore)
            except ImportError:
                from ckanext.datastore.backend import (
                    get_all_resources_ids_in_datastore)

            result = []
            result.append(
                ('Total Datasets', logic.get_action('package_search')({}, {
                    "rows": 1
                })['count']))
            result.append(
                ('Total Machine Readable/Data API Resources',
                 logic.get_action('resource_search')({}, {
                     "query": ["format:wms"]
                 })['count'] + len(get_all_resources_ids_in_datastore())))
            result.append(('Total Organisations',
                           len(logic.get_action('organization_list')({}, {}))))

            res = connection.execute(
                "select 'Total Archived Datasets', count(*) from package where (state='active' or state='draft' or state='draft-complete') and private = 't' and package.id not in (select package_id from package_extra where key = 'harvest_portal') union \
                            select 'Total Data Files/Resources', count(*) from resource where state='active' and package_id not in (select package_id from package_extra where key = 'harvest_portal')"
            ).fetchall()

            for measure, value in res:
                if measure == 'Total Archived Datasets':
                    result.insert(0, (measure, value))
                else:
                    result.append((measure, value))

            return result
Exemple #3
0
    def test_get_all_resources_ids_in_datastore(self):
        resource_in_datastore = factories.Resource()
        resource_not_in_datastore = factories.Resource()
        data = {
            'resource_id': resource_in_datastore['id'],
            'force': True,
        }
        helpers.call_action('datastore_create', **data)

        resource_ids = db.get_all_resources_ids_in_datastore()

        assert resource_in_datastore['id'] in resource_ids
        assert resource_not_in_datastore['id'] not in resource_ids
Exemple #4
0
    def test_get_all_resources_ids_in_datastore(self):
        resource_in_datastore = factories.Resource()
        resource_not_in_datastore = factories.Resource()
        data = {
            'resource_id': resource_in_datastore['id'],
            'force': True,
        }
        helpers.call_action('datastore_create', **data)

        resource_ids = db.get_all_resources_ids_in_datastore()

        assert resource_in_datastore['id'] in resource_ids
        assert resource_not_in_datastore['id'] not in resource_ids
Exemple #5
0
 def _submit_all(self):
     question = (
         "Data in any datastore resource that isn't in their source files "
         "(e.g. data added using the datastore API) will be permanently "
         "lost. Are you sure you want to proceed?")
     answer = cli.query_yes_no(question, default=None)
     if answer == 'yes':
         resources_ids = datastore_db.get_all_resources_ids_in_datastore()
         print 'Submitting %d datastore resources' % len(resources_ids)
         datapusher_submit = p.toolkit.get_action('datapusher_submit')
         for resource_id in resources_ids:
             print('Submitting %s...' % resource_id),
             data_dict = {
                 'resource_id': resource_id,
                 'ignore_hash': True,
             }
             if datapusher_submit(None, data_dict):
                 print 'OK'
             else:
                 print 'Fail'
 def _submit_all(self):
     question = (
         "Data in any datastore resource that isn't in their source files "
         "(e.g. data added using the datastore API) will be permanently "
         "lost. Are you sure you want to proceed?"
     )
     answer = cli.query_yes_no(question, default=None)
     if answer == 'yes':
         resources_ids = datastore_db.get_all_resources_ids_in_datastore()
         print 'Submitting %d datastore resources' % len(resources_ids)
         datapusher_submit = p.toolkit.get_action('datapusher_submit')
         for resource_id in resources_ids:
             print ('Submitting %s...' % resource_id),
             data_dict = {
                 'resource_id': resource_id,
                 'ignore_hash': True,
             }
             if datapusher_submit(None, data_dict):
                 print 'OK'
             else:
                 print 'Fail'
Exemple #7
0
 def _submit_all(self):
     resources_ids = datastore_db.get_all_resources_ids_in_datastore()
     self._submit(resource_ids)
Exemple #8
0
 def _submit_all(self):
     resources_ids = datastore_db.get_all_resources_ids_in_datastore()
     self._submit(resource_ids)
def get_ddg_site_statistics():
    stats = {}
    stats['dataset_count'] = logic.get_action('package_search')({}, {"rows": 1})['count']
    stats['group_count'] = len(logic.get_action('group_list')({}, {}))
    stats['organization_count'] = len(logic.get_action('organization_list')({}, {}))

    result = model.Session.execute(
        '''select count(*) from related r
           left join related_dataset rd on r.id = rd.related_id
           where rd.status = 'active' or rd.id is null''').first()[0]
    stats['related_count'] = result

    stats['unpub_data_count'] = 0
    for fDict in logic.get_action('package_search')({}, {"facet.field":["unpublished"],"rows":1})['search_facets']['unpublished']['items']:
        if fDict['name'] == "Unpublished datasets":
            stats['unpub_data_count'] = fDict['count']
            break

    stats['open_count'] = logic.get_action('package_search')({}, {"fq":"isopen:true","rows":1})['count']

    stats['api_count'] = logic.get_action('resource_search')({}, {"query":["format:wms"]})['count'] + len(datastore_db.get_all_resources_ids_in_datastore())

    return stats