1
|
<?php
|
2
|
require_once('./js/log4php/Logger.php');
|
3
|
require_once('./paths.php');
|
4
|
require_once('./MYDB.php');
|
5
|
|
6
|
class ComputeStatsNumbers {
|
7
|
private $log;
|
8
|
private $db;
|
9
|
private $cache = null; //predis
|
10
|
|
11
|
public function __construct(){
|
12
|
|
13
|
global $redis_host;
|
14
|
global $redis_port;
|
15
|
global $redis_scheme;
|
16
|
global $db_name;
|
17
|
GLOBAL $username;
|
18
|
global $password;
|
19
|
global $host;
|
20
|
|
21
|
$this->log = Logger::getLogger(__CLASS__);
|
22
|
Logger::configure('./js/log4php/log4php.xml');
|
23
|
|
24
|
if(class_exists("Predis\Client")){
|
25
|
|
26
|
try {
|
27
|
//todo changed timeout from 0 to -1
|
28
|
$this->cache = new Predis\Client(array("scheme" => $redis_scheme,"host" => $redis_host,"port" => $redis_port,"read_write_timeout" => -1));
|
29
|
$this->log->info("redis host: ".$redis_host." and redis port: ".$redis_port);
|
30
|
} catch(Exception $e) {
|
31
|
$this->log->error("Error connecting to Redis server: ".$e->getMessage());
|
32
|
$this->cache = null;
|
33
|
}
|
34
|
}
|
35
|
else{
|
36
|
$this->log->info("cache does not exist"); //predis
|
37
|
exit;
|
38
|
}
|
39
|
//NOW GET DB
|
40
|
try {
|
41
|
$str = 'pgsql:host='.$host.";port=5432;dbname=".$db_name.";user=".$username.";password=".$password;
|
42
|
|
43
|
$this->db = new PDO($str);
|
44
|
|
45
|
//TODO set search path here
|
46
|
} catch(Exception $e){
|
47
|
$this->log->error('Could not connect to database: ' . $e->getMessage());
|
48
|
exit;
|
49
|
}
|
50
|
}
|
51
|
|
52
|
|
53
|
private function doQuery($query){
|
54
|
$stmt = $this->db->query($query);
|
55
|
if(!$stmt){
|
56
|
$arr = $this->db->errorInfo();
|
57
|
$this->log->error("Error executing query: ".$query." ".$arr[2]);
|
58
|
return "-";
|
59
|
}
|
60
|
$t = $stmt->fetch();
|
61
|
|
62
|
return number_format($t[0]);
|
63
|
}
|
64
|
//TODO here store Queries in cache
|
65
|
private function storeQuery($key, $query) {
|
66
|
$res=$this->doQuery($query);
|
67
|
|
68
|
//$this->cache = new Predis\Client(array("scheme" => $redis_scheme, "host" => $redis_host, "port" => $redis_port));
|
69
|
$this->cache->connect(); //predis
|
70
|
$this->cache->hset('SHADOW_STATS_NUMBERS',$key,$res);
|
71
|
$this->log->info("Stored query : ".$key." ".$this->cache->hget('SHADOW_STATS_NUMBERS',$key));
|
72
|
$this->cache->quit();
|
73
|
|
74
|
}
|
75
|
|
76
|
function computeStats() {
|
77
|
|
78
|
global $redis_host;
|
79
|
/*OVERALL*/
|
80
|
|
81
|
/*1*/
|
82
|
$qpubs = "SELECT count(*) FROM result where type='publication'";
|
83
|
|
84
|
/*2*/
|
85
|
$qoapubs = "SELECT count(*) FROM result WHERE bestlicense='Open Access' and type='publication'";
|
86
|
|
87
|
/*3*/
|
88
|
$qnoapubs = "SELECT count(*) FROM result WHERE bestlicense='Closed Access' and type='publication'";
|
89
|
|
90
|
/*4*/
|
91
|
$qfpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects where result.result_projects = result_projects.id and type='publication'";
|
92
|
|
93
|
/*5*/
|
94
|
$qproj = "SELECT count(*) FROM project";
|
95
|
|
96
|
/*6*/
|
97
|
$qdatasrc = "SELECT count(*) FROM datasource";
|
98
|
|
99
|
/*7*/
|
100
|
$qdtsrcpubs = "select count(*) from datasource where compatibility != 'not available' and compatibility != 'under validation'";
|
101
|
|
102
|
/*8*/
|
103
|
$qdtsrcpubreps = "SELECT count(*) FROM datasource WHERE type='Repository'";
|
104
|
|
105
|
/*9*/
|
106
|
$qdtsrcoaj = "SELECT count(*) FROM datasource WHERE type='Journal'";
|
107
|
|
108
|
/*10*/
|
109
|
$qdtsrcpubaggr = "SELECT count(*) FROM datasource WHERE type='Aggregated Repository'";
|
110
|
|
111
|
/*11*/
|
112
|
$qfunders = "SELECT count(distinct funding_lvl0) FROM project WHERE funding_lvl0 !=''";
|
113
|
|
114
|
|
115
|
/*FP7*/
|
116
|
|
117
|
/*12: total number of fp7 pubs */
|
118
|
$qfp7pubstotal = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id and type='publication' and result_projects.project = project.id and funding_lvl0 = 'FP7'";
|
119
|
|
120
|
/*13: number of fp7 projects with publications*/
|
121
|
$qfp7projpubs = "SELECT count(distinct project.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id and type='publication' and result_projects.project = project.id and funding_lvl0='FP7'";
|
122
|
|
123
|
/*14: total number of fp7 projects*/
|
124
|
$qfp7projtotal = "SELECT count(id) FROM project WHERE funding_lvl0 = 'FP7'";
|
125
|
|
126
|
/*15: fp7 open access pubs*/
|
127
|
$qfp7oapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result_projects = result_projects.id AND result_projects.project = project.id and type='publication' and funding_lvl0 = 'FP7' and bestlicense='Open Access'";
|
128
|
|
129
|
/*16: fp7 restricted pubs*/
|
130
|
$qfp7respubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and bestlicense='Restricted' and type='publication'";
|
131
|
|
132
|
/*17: fp7 pubs in embargo*/
|
133
|
$qfp7embpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and bestlicense='Embargo' and type='publication'";
|
134
|
|
135
|
/*18: total number of fp7 pubs with sc39*/
|
136
|
$qsc39fp7pubstotal = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result_projects.project = project.id and funding_lvl0 = 'FP7' and sc39='yes' and result.result_projects = result_projects.id and type='publication'";
|
137
|
|
138
|
/*19: fp7 projs with sc39 and pubs*/
|
139
|
$qsc39fp7projpubs = "SELECT count(distinct project.id) FROM result, result_projects, project WHERE result_projects.project=project.id and funding_lvl0 = 'FP7' and sc39='yes' and result.result_projects = result_projects.id and type='publication'";
|
140
|
|
141
|
/*20: total number of fp7 proj with sc39*/
|
142
|
$qsc39fp7projtotal = "SELECT count(number) from project where funding_lvl0='FP7' and sc39='yes'";
|
143
|
|
144
|
/*21: open access fp7 pubs with sc39*/
|
145
|
$qsc39fp7oapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and bestlicense='Open Access' and sc39='yes' and type='publication'";
|
146
|
|
147
|
|
148
|
/*ERC*/
|
149
|
|
150
|
/*22: total number of erc pubs*/
|
151
|
$qercpubstotal = "SELECT count( distinct result.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl2='ERC' and result.result_projects = result_projects.id and result.type='publication'";
|
152
|
|
153
|
|
154
|
/*23: erc projects with pubs*/
|
155
|
$qercprojpubs = "SELECT count(distinct project.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl2='ERC' and result.result_projects = result_projects.id and type='publication'";
|
156
|
|
157
|
/*24: total erc projects*/
|
158
|
$qercprojtotal = "SELECT count(id) FROM project WHERE funding_lvl2 = 'ERC'";
|
159
|
|
160
|
/*25: erc open access pubs*/
|
161
|
$qercoapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and bestlicense='Open Access' and type='publication'";
|
162
|
|
163
|
/*26: erc restricted pubs*/
|
164
|
$qercrespubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and bestlicense='Restricted' and type='publication'";
|
165
|
|
166
|
/*27: erc embargo pubs*/
|
167
|
$qercembpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and bestlicense='Embargo' and type='publication'";
|
168
|
|
169
|
|
170
|
/*WT*/
|
171
|
|
172
|
/*28: total number of wt pubs*/
|
173
|
|
174
|
$qwtpubstotal = "SELECT count(distinct result_projects.id) FROM result,result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'WT' and type='publication'";
|
175
|
|
176
|
|
177
|
/*29: wt projects with pubs*/
|
178
|
$qwtprojpubs = "SELECT count(distinct project.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl0='WT' and result.result_projects = result_projects.id and type='publication'";
|
179
|
|
180
|
/*30: total wt projects*/
|
181
|
$qwtprojtotal = "SELECT count(id) FROM project WHERE funding_lvl0 = 'WT'";
|
182
|
|
183
|
/*31: wt open access pubs*/
|
184
|
$qwtoapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'WT' and bestlicense='Open Access' and type='publication'";
|
185
|
|
186
|
/*32: wt restricted pubs*/
|
187
|
$qwtrespubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'WT' and bestlicense='Restricted' and type='publication'";
|
188
|
|
189
|
/*33: wt embargo pubs*/
|
190
|
$qwtembpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'WT' and bestlicense='Embargo' and type='publication'";
|
191
|
|
192
|
|
193
|
/*FET */
|
194
|
|
195
|
$fetpubs ="select count(distinct rc.id) as field0 from result_concepts rc join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context like 'fet%'";
|
196
|
|
197
|
$fetoapubs ="select count(distinct rc.id) as field0 from result_concepts rc join result r on r.id=rc.id join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context like 'fet%' and r. bestlicense='Open Access'";
|
198
|
/*
|
199
|
$fet_noa_pubs ="select count(distinct rc.id) as field0 from result_concepts rc join result r on r.id=rc.id join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context ='fet' and r. bestlicense='Closed Access'";*/
|
200
|
|
201
|
$fetembpubs ="select count(distinct rc.id) as field0 from result_concepts rc join result r on r.id=rc.id join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context like 'fet%' and r. bestlicense='Embargo'";
|
202
|
$fetrespubs ="select count(distinct rc.id) as field0 from result_concepts rc join result r on r.id=rc.id join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context like 'fet%' and r. bestlicense='Restricted'";
|
203
|
|
204
|
|
205
|
|
206
|
|
207
|
/*Natalia's extra stuff */
|
208
|
|
209
|
|
210
|
/*35: organisations with publication results */
|
211
|
$org_withpubs = "select count(*) from (select dor.organization as organization from datasource_organizations dor join result_datasources rd on rd.datasource=dor.id join result r on r.id=rd.id where r.type='publication' union select por.organization as organization from project_organizations por join result_projects rp on rp.project=por.id join result r on r.id=rp.id where r.type='publication') as foo";
|
212
|
|
213
|
/*36: number of datasets */
|
214
|
$data_total = "select count(distinct id) from result where type='dataset'";
|
215
|
|
216
|
|
217
|
# $datasrc_withpubs = "SELECT count(distinct rd.datasource) from result_datasources rd join result r on r.id=rd.id where r.type='publication'";
|
218
|
|
219
|
$datasrc_withpubs = "SELECT count(distinct rd.datasource) from result_datasources rd ";
|
220
|
|
221
|
|
222
|
/*DATASETS */
|
223
|
|
224
|
$datasetpubs= "select count(distinct r.id) from result r join result_results rr on rr.id=r.id join result rp on rp.id=rr.result where r.type='dataset' and rp.type='publication'" ;
|
225
|
|
226
|
//# of datasets linked to projects
|
227
|
|
228
|
$datasetproj="select count(distinct r.id) from result r join result_projects rp on rp.id=r.id join project p on p.id=rp.project where r.type='dataset' ";
|
229
|
|
230
|
//# of publications linked to datasets
|
231
|
|
232
|
//$pubsdatasets ="select count(distinct r.id) from result r join result_results rr on rr.id=r.id join result rp on rp.id=rr.result where r.type='publication' and rp.type='dataset'";
|
233
|
|
234
|
|
235
|
$pubsdatasets ="select count(distinct rp.id) from result rp where rp.type='dataset'";
|
236
|
/*EGI PAGE NUMS*/
|
237
|
|
238
|
|
239
|
$egivo="select count(distinct c.name) as field0 from result_concepts rc join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.id='egi::virtual'";
|
240
|
|
241
|
$egiproj="select count(distinct c.name) as field0 from result_concepts rc join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.id='egi::projects' ";
|
242
|
|
243
|
$egipubs= " select count( distinct rc.id) as field0 from result r,result_concepts rc, concept con, category cat where rc.id=r.id and con.id=rc.concept and con.category= cat.id and cat.context ='egi'";
|
244
|
|
245
|
$egioa=" select count( distinct rc.id) as field0 from result r,result_concepts rc, concept con, category cat where rc.id=r.id and con.id=rc.concept and con.category= cat.id and cat.context ='egi' and r.bestlicense='Open Access'";
|
246
|
//$eginoa="select count(distinct r.id) as field0 from result r join result_concepts rc on r.id=rc.id join concept c on c.id=rc.concept where bestlicense='Closed Access'";
|
247
|
$egiemb=" select count( distinct rc.id) as field0 from result r,result_concepts rc, concept con, category cat where rc.id=r.id and con.id=rc.concept and con.category= cat.id and cat.context ='egi' and bestlicense='Embargo'";
|
248
|
$egires=" select count( distinct rc.id) as field0 from result r,result_concepts rc, concept con, category cat where rc.id=r.id and con.id=rc.concept and con.category= cat.id and cat.context ='egi' and bestlicense='Restricted'";
|
249
|
|
250
|
/*FCT*/
|
251
|
|
252
|
/*22: total number of FCT pubs*/
|
253
|
$qfctpubstotal = "SELECT count( distinct result.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl0='FCT' and result.result_projects = result_projects.id and result.type='publication'";
|
254
|
|
255
|
/*23: FCT projects with pubs*/
|
256
|
$qfctprojpubs = "SELECT count(distinct project.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl0='FCT' and result.result_projects = result_projects.id and type='publication'";
|
257
|
/*24: total FCT projects*/
|
258
|
$qfctprojtotal = "SELECT count(id) FROM project WHERE funding_lvl0 = 'FCT'";
|
259
|
/*25: FCT open access pubs*/
|
260
|
$qfctoapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FCT' and bestlicense='Open Access' and type='publication'";
|
261
|
/*26: FCT restricted pubs*/
|
262
|
$qfctrespubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FCT' and bestlicense='Restricted' and type='publication'";
|
263
|
|
264
|
/*27: FCT embargo pubs*/
|
265
|
$qfctembpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FCT' and bestlicense='Embargo' and type='publication'";
|
266
|
|
267
|
|
268
|
|
269
|
|
270
|
/*1*/ $this->storeQuery('pubs', $qpubs);
|
271
|
/*2*/ $this->storeQuery('oapubs', $qoapubs);
|
272
|
/*3*/ $this->storeQuery('noapubs', $qnoapubs);
|
273
|
/*4*/ $this->storeQuery('fpubs', $qfpubs);
|
274
|
/*5*/ $this->storeQuery('proj', $qproj);
|
275
|
/*6*/ $this->storeQuery('datasrc', $qdatasrc);
|
276
|
/*7*/ $this->storeQuery('dtsrcpubs', $qdtsrcpubs);
|
277
|
/*8*/ $this->storeQuery('dtsrcpubreps', $qdtsrcpubreps);
|
278
|
/*9*/ $this->storeQuery('dtsrcoaj', $qdtsrcoaj);
|
279
|
/*10*/ $this->storeQuery('dtsrcpubaggr', $qdtsrcpubaggr);
|
280
|
/*11*/ $this->storeQuery('funders', $qfunders);
|
281
|
|
282
|
/*FP7*/
|
283
|
|
284
|
/*12*/ $this->storeQuery('fp7pubstotal', $qfp7pubstotal);
|
285
|
/*13*/ $this->storeQuery('fp7projpubs', $qfp7projpubs);
|
286
|
/*14*/ $this->storeQuery('fp7projtotal', $qfp7projtotal);
|
287
|
/*15*/ $this->storeQuery('fp7oapubs', $qfp7oapubs);
|
288
|
/*16*/ $this->storeQuery('fp7respubs', $qfp7respubs);
|
289
|
/*17*/ $this->storeQuery('fp7embpubs', $qfp7embpubs);
|
290
|
/*18*/ $this->storeQuery('sc39fp7pubstotal', $qsc39fp7pubstotal);
|
291
|
/*19*/ $this->storeQuery('sc39fp7projpubs', $qsc39fp7projpubs);
|
292
|
/*20*/ $this->storeQuery('sc39fp7projtotal', $qsc39fp7projtotal);
|
293
|
/*21*/ $this->storeQuery('sc39fp7oapubs', $qsc39fp7oapubs);
|
294
|
|
295
|
/*ERC*/
|
296
|
|
297
|
/*22*/ $this->storeQuery('ercpubstotal', $qercpubstotal);
|
298
|
/*23*/ $this->storeQuery('ercprojpubs', $qercprojpubs);
|
299
|
/*24*/ $this->storeQuery('ercprojtotal', $qercprojtotal);
|
300
|
/*25*/ $this->storeQuery('ercoapubs', $qercoapubs);
|
301
|
/*26*/ $this->storeQuery('ercrespubs', $qercrespubs);
|
302
|
/*27*/ $this->storeQuery('ercembpubs', $qercembpubs);
|
303
|
|
304
|
/*WT*/
|
305
|
|
306
|
/*28*/ $this->storeQuery('wtpubstotal', $qwtpubstotal);
|
307
|
/*29*/ $this->storeQuery('wtprojpubs', $qwtprojpubs);
|
308
|
/*30*/ $this->storeQuery('wtprojtotal', $qwtprojtotal);
|
309
|
/*31*/ $this->storeQuery('wtoapubs', $qwtoapubs);
|
310
|
/*32*/ $this->storeQuery('wtrespubs', $qwtrespubs);
|
311
|
/*33*/ $this->storeQuery('wtembpubs', $qwtembpubs);
|
312
|
/*34*/ $this->storeQuery('datasrc_withpubs', $datasrc_withpubs) ;
|
313
|
//todo commented those for duffy
|
314
|
/*35*/$this->storeQuery('org_withpubs', $org_withpubs);
|
315
|
/*36*/ $this->storeQuery('data_total', $data_total);
|
316
|
|
317
|
|
318
|
//FET NUMS
|
319
|
|
320
|
|
321
|
//FET NUMS
|
322
|
$this->storeQuery('fetpubs', $fetpubs);
|
323
|
$this->storeQuery('fetoapubs', $fetoapubs);
|
324
|
$this->storeQuery('fetrespubs', $fetrespubs);
|
325
|
$this->storeQuery('fetembpubs', $fetembpubs);
|
326
|
|
327
|
//DATASET NUMS
|
328
|
$this->storeQuery('datasetpubs', $datasetpubs);
|
329
|
$this->storeQuery('datasetproj', $datasetproj);
|
330
|
$this->storeQuery('pubsdatasets', $pubsdatasets);
|
331
|
|
332
|
/*EGI nums*/
|
333
|
$this->storeQuery('egipubs', $egipubs);
|
334
|
$this->storeQuery('egivo', $egivo);
|
335
|
$this->storeQuery('egiproj', $egiproj);
|
336
|
|
337
|
|
338
|
$this->storeQuery('egioa', $egioa);
|
339
|
$this->storeQuery('egiemb', $egiemb);
|
340
|
$this->storeQuery('egires', $egires);
|
341
|
|
342
|
//FCT NUMS
|
343
|
|
344
|
/*22*/ $this->storeQuery('fctpubstotal', $qfctpubstotal);
|
345
|
/*23*/ $this->storeQuery('fctprojpubs', $qfctprojpubs);
|
346
|
/*24*/ $this->storeQuery('fctprojtotal', $qfctprojtotal);
|
347
|
/*25*/ $this->storeQuery('fctoapubs', $qfctoapubs);
|
348
|
/*26*/ $this->storeQuery('fctrespubs', $qfctrespubs);
|
349
|
/*27*/ $this->storeQuery('fctembpubs', $qfctembpubs);
|
350
|
|
351
|
|
352
|
|
353
|
}
|
354
|
}
|
355
|
|
356
|
?>
|