Example #1
0
def get_services_full():
	field= "publisher_name" 

	# SOLR query
	fq= more_filters() #filtra pkg in base alle organizzazioni dell'utente
	data_dict= {'facet.field':[field], 'fq':fq} 
	diz= h.get_action('package_search',data_dict )
	
	if len(diz['facets']) == 0:
		return json.dumps({"labels":None, "data": None, "count": 0})
	else:
		diz= diz['facets'][field]

		count= len(diz) 
		diz= sorted(diz.items(), key=itemgetter(1), reverse=True)

		labels=[] 
		data=[]	
		for elem in diz:
			if elem[0] != "":
				labels.append(elem[0])			
				data.append(elem[1])
			else: #if the key is null don't count it
				count-=1
		return json.dumps({"labels":labels[5:], "data": data[5:], "count": count}) 
Example #2
0
def get_tags():	
	field= "tags"
	
	# SOLR query
	fq= more_filters() #filtra pkg in base alle organizzazioni dell'utente
	data_dict= {'facet.field':[field], 'fq':fq} 
	diz= h.get_action('package_search',data_dict )
	
	#print diz['facets'][field]
	if len(diz['facets']) == 0:
		return None
	else:
			
		diz= diz['facets'][field]
		count= len(diz) 
		diz= sorted(diz.items(), key=itemgetter(1), reverse=True)

		list=[]
		for elem in diz:
			target = {"text": elem[0], "size": elem[1]}
			list.append(target)
		
		if len(list)>=20: #prendo solo i 20 piu frequenti
			list=list[:20]
		
		return json.dumps(list)
Example #3
0
    def login_user(self, tup):
        if tup:
            user = tup[0]

            user_object = model.User.get(user)
            if not user_object:
                user_object = model.User.get('api')
                c.userobj = user_object
                c.user = '******'

                try:
                    # Create user
                    user_attributes = tup[1]
                    user_name = user
                    user_email = user_attributes["email"].text
                    user_password = "******"
                    user_fullname = user_attributes[
                        "firstName"].text + " " + user_attributes[
                            "lastName"].text

                    h.get_action(
                        'user_create', {
                            "name": user_name,
                            "email": user_email,
                            "password": user_password,
                            "fullname": user_fullname
                        })

                    rememberer = request.environ['repoze.who.plugins'][
                        'friendlyform']
                    identity = {'repoze.who.userid': user}
                    response.headerlist += rememberer.remember(
                        request.environ, identity)
                except logic.ActionError:
                    base.abort(401, _('Error while creating new user'))
            else:
                c.userobj = user_object
                c.user = user

                rememberer = request.environ['repoze.who.plugins'][
                    'friendlyform']
                identity = {'repoze.who.userid': user}
                response.headerlist += rememberer.remember(
                    request.environ, identity)

            self.logged_in()
Example #4
0
def get_numDatasets():
	# SOLR query
	fq = more_filters()  # filtra pkg in base alle organizzazioni dell'utente
	# fq += ' +dataset_type:dataset'
	data_dict = {'fq': fq}
	diz = h.get_action('package_search', data_dict)
	num_pkg = diz['count']
	return num_pkg
Example #5
0
def get_numResources():
	
	#print '...in get_NumResources\n'
	field = "num_resources"
	count = 0


	# SOLR query
	fq = more_filters()  # filtra pkg in base alle organizzazioni dell'utente

	data_dict = {'fq': fq, 'rows': '3000'}
	if not c.user:
		data_dict = {'rows': '3000'} # non filtro per organizzazione

	# new

	diz = h.get_action('package_search', data_dict)
	
	if len(diz['results']) > 0:

		for pkg in diz['results']:
			if 'resources' in pkg:
				for res in pkg[ 'resources']:
					# se sloggato non conto risorse private
					if not (not c.user and res['resource_capacity'] == 'private'):
						count += 1


	"""
	data_dict = {'facet.field': [field], 'fq': fq}
	if not c.user:
		data_dict = {'facet.field': [field]} # non filtro per organizzazione


	diz = h.get_action('package_search', data_dict)

	
	#print diz
	if len(diz['facets']) > 0:
		diz = diz['facets'][field]
		#print diz
		for elem in diz.items():
			#print int(elem[0])
			#print int(elem[1])

			# ad esempio {'3':1} dice che esiste 1 pkg con 3 risorse

			count += int(elem[0]) * int(elem[1])
	"""
	
	return count
Example #6
0
def get_numGroups():
	count =0
	diz = h.get_action('group_list')
	count = len(diz)
	return count
    def statistiche(self):

        #redirect('/dashboard')
        f = open("statistiche.txt", "w")

        c.organo = []
        organo = h.get_action('organization_list', {
            'all_fields': True,
            'include_dataset_count': True
        })
        for ooo in organo:
            c.organo.append(ooo['display_name'] + ": " +
                            str(ooo['package_count']))

        group_diz = {}
        group_list = h.get_action('group_list', {
            'all_fields': True,
            'include_dataset_count': True
        })
        org_list = h.get_action('organization_list', {})
        c.stat = []

        for group in group_list:
            c.statistiche = ""
            g = unicodedata.normalize('NFKD', group['display_name']).encode(
                'ascii', 'ignore')
            f.write('\nGRUPPO: ' + g.upper() + ' --> ' +
                    str(group['package_count']) + ' dataset:\n')
            g = unicodedata.normalize('NFKD',
                                      group['name']).encode('ascii', 'ignore')

            c.statistiche = c.statistiche + '\nGRUPPO: ' + g.upper(
            ) + ' --> ' + str(group['package_count']) + ' dataset:\n'

            q = '+groups:"' + g + '"'
            data_dict = {
                'q': q,
                'rows': 2000,
            }
            diz = h.get_action('package_search', data_dict)
            results = diz['results']

            privati = 0
            pubblici = 0
            for pkg in diz['results']:
                if pkg['private']:
                    privati += 1
                else:
                    pubblici += 1

            c.statistiche = c.statistiche + ' priv ' + str(
                privati) + ' , pub ' + str(pubblici)

            if diz['results']:
                for org in org_list:
                    o = unicodedata.normalize('NFKD',
                                              org).encode('ascii', 'ignore')
                    f.write('> org = ' + o)
                    c.statistiche = c.statistiche + '> org = > org =  ' + o.upper(
                    )
                    q = '+groups:"' + g + '"' + ' +organization:"' + o + '"'
                    #fq='capacity:"public"'
                    data_dict = {
                        'q': q,
                        'rows': 2000,
                    }
                    diz = h.get_action('package_search', data_dict)
                    results = diz['results']
                    c.statistiche = c.statistiche + ' (' + str(
                        len(diz['results'])) + ' DS TOT) > org =\nRIS: \n'
                    wms = 0
                    shp = 0
                    altro = 0
                    priv_wms = 0
                    pub_wms = 0
                    priv_shp = 0
                    pub_shp = 0
                    priv_altro = 0
                    pub_altro = 0
                    senza_risorse = 0
                    privati = 0
                    for pkg in diz['results']:
                        if pkg['private']:
                            privati += 1
                        if pkg['num_resources'] == 0:
                            senza_risorse += 1

                        for res in pkg[u'resources']:
                            if res[u'format'].upper() == u'WMS':
                                wms += 1
                                if res[u'resource_capacity'] == u'public' and pkg[
                                        u'private'] == False:
                                    pub_wms += 1
                                else:
                                    priv_wms += 1
                            elif res[u'format'].upper() == u'SHP':
                                shp += 1
                                if res[u'resource_capacity'] == u'public' and pkg[
                                        u'private'] == False:
                                    pub_shp += 1
                                else:
                                    priv_shp += 1
                            else:
                                altro += 1
                                if res[u'resource_capacity'] == u'public' and pkg[
                                        u'private'] == False:
                                    pub_altro += 1
                                else:
                                    priv_altro += 1

                    tot = wms + shp + altro
                    tot_priv = priv_wms + priv_shp + priv_altro
                    tot_pub = pub_wms + pub_shp + pub_altro
                    f.write('\nwms: ' + str(wms) + ' ( privati ' +
                            str(priv_wms) + ', pubblici ' + str(pub_wms) + ')')
                    c.statistiche = c.statistiche + '\nwms: ' + str(
                        wms) + ' ( privati ' + str(
                            priv_wms) + ', pubblici ' + str(pub_wms) + ')'
                    f.write('\nshp: ' + str(shp) + ' ( privati ' +
                            str(priv_shp) + ', pubblici ' + str(pub_shp) + ')')
                    c.statistiche = c.statistiche + '\nshp: ' + str(
                        shp) + ' ( privati ' + str(
                            priv_shp) + ', pubblici ' + str(pub_shp) + ')'
                    f.write('\naltre: ' + str(altro) + ' ( privati ' +
                            str(priv_altro) + ', pubblici ' + str(pub_altro) +
                            ')')
                    c.statistiche = c.statistiche + '\naltre: ' + str(
                        altro) + ' ( privati ' + str(
                            priv_altro) + ', pubblici ' + str(pub_altro) + ')'
                    f.write('\ntotali: ' + str(tot) + ' ( privati ' +
                            str(tot_priv) + ', pubblici ' + str(tot_pub) +
                            ')\n\n')
                    c.statistiche = c.statistiche + '\ntotali: ' + str(
                        tot) + ' ( privati ' + str(
                            tot_priv) + ', pubblici ' + str(tot_pub) + ')\n\n'
                    if senza_risorse > 0:
                        c.statistiche = c.statistiche + '\n; Senza RIS:' + str(
                            senza_risorse)
            c.stat.append(c.statistiche)

        f.close()

        return render('statistiche.html')