Project

General

Profile

1 39920 sandro.lab
import json
2
import pysolr
3
4
5
solr_server = pysolr.Solr("http://node0.d.dli.research-infrastructures.eu:8983/solr/DLIF-index-cleaned_shard1_replica1")
6
"""
7
result =solr_server.search(q="localidentifier:'10.5517/ccp8ql7' ", rows=20, **{
8
   'facet':'true',
9
   'start':10,
10
   'facet.field':['entitytype', 'provenance']
11
});
12
"""
13
14
15
def getPointingTo(query, type):
16
    result = solr_server.search(q=query, rows=10, **{
17
       'facet':'true',
18
       'facet.field':['relatedobjtype'],
19
       'fq':'entitytype:"%s"'%type,
20
       'fq':'entitytype:"publication"'
21
22
    })
23
24
    fields =result.facets['facet_fields']
25
26
    return {type: [{'key':fields['relatedobjtype'][i], 'value':fields['relatedobjtype'][i+1]} for i in range(0,len(fields['relatedobjtype']),2)]}
27
28
29
def get_stats(self):
30
        stats = {}
31
        response = self.solr_server.search(q='*:*', rows=0, **{
32
            'facet': 'true',
33
            'facet.field': ['provenance']
34
            })
35
        d = response.facets['facet_fields']['provenance']
36
        stats['dataset'] = [[d[i], d[i+1]] for i in range(0, len(d), 2)]
37
        response = self.solr_server.search(q='*:*', rows=0, **{
38
            'facet': 'true',
39
            'facet.field': ['provenance'],
40
            'fq': ['entitytype:"publication"']
41
        })
42
        d = response.facets['facet_fields']['provenance']
43
        stats['publication'] = [[d[i], d[i+1]] for i in range(0, len(d), 2)]
44
        return stats
45
46
47
def get_stats_detail_part2(stat_dict):
48
    response =solr_server.search(q='*:*', rows=0, **{
49
           'facet':'true',
50
           'facet.field':['provenance'],
51
            'fq': ['entitytype:"publication"']
52
        })
53
    res = response.facets['facet_fields']
54
    data= res['provenance']
55
    total_pubs = [(data[i], data[i+1]) for i in range(len(data)) if (i % 2) == 0]
56
    for item in total_pubs:
57
        if item[0] not in stat_dict:
58
             stat_dict[item[0]] = {'totalObject': 0, 'totalPublication': 0, 'totalDatasets': 0, 'totalRelations': 0}
59
        stat_dict[item[0]]['totalPublication'] =item[1]
60
61
    response =solr_server.search(q='*:*', rows=0, **{
62
           'facet':'true',
63
           'facet.field':['provenance'],
64
            'fq': ['entitytype:"dataset"']
65
        })
66
    res = response.facets['facet_fields']
67
    data= res['provenance']
68
    total_datasets = [(data[i], data[i+1]) for i in range(len(data)) if (i % 2) == 0]
69
    for item in total_datasets:
70
        if item[0] not in stat_dict:
71
             stat_dict[item[0]] ={}
72
        stat_dict[item[0]]['totalDatasets'] =item[1]
73
74
75
76
77
def get_stats_detail():
78
    response =solr_server.search(q='*:*', rows=0, **{
79
           'facet':'true',
80
           'facet.field':['provenance', 'relationprovenance']
81
        })
82
    res = response.facets['facet_fields']
83
    data= res['provenance']
84
    repo_name = [data[i] for i in range(len(data)) if (i % 2) == 0]
85
    stat_dict = {}
86
    total_item = [(data[i], data[i+1]) for i in range(len(data)) if (i % 2) == 0]
87
    for repo in  repo_name:
88
        stat_dict[repo] ={'totalObject': 0, 'totalPublication': 0, 'totalDatasets': 0, 'totalRelations': 0}
89
    for item in total_item:
90
        stat_dict[item[0]]['totalObject'] =item[1]
91
    data= res['relationprovenance']
92
    total_rels = [(data[i], data[i+1]) for i in range(len(data)) if (i % 2) == 0]
93
    for item in total_rels:
94
        if item[0] not in stat_dict:
95
             stat_dict[item[0]] ={'totalObject': 0, 'totalPublication': 0, 'totalDatasets': 0, 'totalRelations': 0}
96
        stat_dict[item[0]]['totalRelations'] =item[1]
97
    return stat_dict
98
99
100
101
import urllib2
102
103
104
import re
105
p = re.compile("((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)")
106
107
print p.match("http://data.aims.gov.au/extpubs/do/viewpub.do?articleid=7037")
108
109
110
111
112
data =urllib2.urlopen("http://node0.d.dli.research-infrastructures.eu:8080/dli/mvc/ui/stats/getLastStats")
113
json.loads(data.read())
114