1
|
<?php
|
2
|
require_once('./js/log4php/Logger.php');
|
3
|
require_once('./paths.php');
|
4
|
require "./predis/autoload.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
|
|
17
|
global $host;
|
18
|
|
19
|
$this->log = Logger::getLogger(__CLASS__);
|
20
|
if(class_exists("Predis\Client")){
|
21
|
|
22
|
try {
|
23
|
|
24
|
Predis\Autoloader::register();
|
25
|
// $this->cache = new Predis\Client(array( //predis
|
26
|
// "scheme" => $redis_scheme,
|
27
|
// "host" => $redis_host,
|
28
|
// "port" => $redis_port,
|
29
|
// "read_write_timeout" => 600));
|
30
|
|
31
|
// $this->cache->connect(); //predis
|
32
|
// $this->cache->quit();
|
33
|
|
34
|
|
35
|
$this->log->info("redis host: ".$redis_host);
|
36
|
$this->log->info("redis port: ".$redis_port);
|
37
|
|
38
|
} catch(Exception $e) {
|
39
|
$this->log->error("Error connecting to Redis server: ".$e->getMessage());
|
40
|
$this->cache = null; //predis
|
41
|
}
|
42
|
}
|
43
|
else{
|
44
|
$this->log->info("cache does not exist"); //predis
|
45
|
exit;
|
46
|
}
|
47
|
|
48
|
try {
|
49
|
//for testing
|
50
|
//$str = 'pgsql:host='.$host.';port=5432;dbname=stats;user=sqoop;password=sqoop';
|
51
|
//for deployment
|
52
|
$str = 'pgsql:host='.$host.';port=5432;dbname=stats;user=dnet;password=dnetPwd';
|
53
|
$this->db = new PDO($str);
|
54
|
} catch(Exception $e){
|
55
|
$this->log->error('Could not connect to database: ' . $e->getMessage());
|
56
|
exit;
|
57
|
}
|
58
|
}
|
59
|
|
60
|
|
61
|
private function doQuery($query){
|
62
|
$stmt = $this->db->query($query);
|
63
|
if(!$stmt){
|
64
|
$arr = $this->db->errorInfo();
|
65
|
$this->log->error("Error executing query: ".$query." ".$arr[2]);
|
66
|
return "-";
|
67
|
}
|
68
|
$t = $stmt->fetch();
|
69
|
return number_format($t[0]);
|
70
|
}
|
71
|
|
72
|
private function storeQuery($key, $query) {
|
73
|
global $redis_host;
|
74
|
global $redis_port;
|
75
|
global $redis_scheme;
|
76
|
|
77
|
$this->cache = new Predis\Client(array("scheme" => $redis_scheme, "host" => $redis_host, "port" => $redis_port));
|
78
|
|
79
|
$this->cache->connect(); //predis
|
80
|
$this->cache->hset('STATS_NUMBERS', $key, $this->doQuery($query));
|
81
|
|
82
|
$this->cache->quit();
|
83
|
}
|
84
|
|
85
|
function computeStats() {
|
86
|
/*OVERALL*/
|
87
|
|
88
|
/*1*/
|
89
|
$qpubs = "SELECT count(*) FROM result where type='publication'";
|
90
|
|
91
|
/*2*/
|
92
|
$qoapubs = "SELECT count(*) FROM result WHERE bestlicense='Open Access' and type='publication'";
|
93
|
|
94
|
/*3*/
|
95
|
$qnoapubs = "SELECT count(*) FROM result WHERE bestlicense='Closed Access' and type='publication'";
|
96
|
|
97
|
/*4*/
|
98
|
$qfpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects where result.result_projects = result_projects.id and type='publication'";
|
99
|
|
100
|
/*5*/
|
101
|
$qproj = "SELECT count(*) FROM project";
|
102
|
|
103
|
/*6*/
|
104
|
$qdatasrc = "SELECT count(*) FROM datasource";
|
105
|
|
106
|
/*7*/
|
107
|
$qdtsrcpubs = "select count(*) from datasource where compatibility != 'not available' and compatibility != 'under validation'";
|
108
|
|
109
|
/*8*/
|
110
|
$qdtsrcpubreps = "SELECT count(*) FROM datasource WHERE type='Repository'";
|
111
|
|
112
|
/*9*/
|
113
|
$qdtsrcoaj = "SELECT count(*) FROM datasource WHERE type='Journal'";
|
114
|
|
115
|
/*10*/
|
116
|
$qdtsrcpubaggr = "SELECT count(*) FROM datasource WHERE type='Aggregated Repository'";
|
117
|
|
118
|
/*11*/
|
119
|
$qfunders = "SELECT count(distinct funding_lvl0) FROM project WHERE funding_lvl0 !=''";
|
120
|
|
121
|
|
122
|
/*FP7*/
|
123
|
|
124
|
/*12: total number of fp7 pubs */
|
125
|
$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'";
|
126
|
|
127
|
/*13: number of fp7 projects with publications*/
|
128
|
$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'";
|
129
|
|
130
|
/*14: total number of fp7 projects*/
|
131
|
$qfp7projtotal = "SELECT count(id) FROM project WHERE funding_lvl0 = 'FP7'";
|
132
|
|
133
|
/*15: fp7 open access pubs*/
|
134
|
$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'";
|
135
|
|
136
|
/*16: fp7 restricted pubs*/
|
137
|
$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'";
|
138
|
|
139
|
/*17: fp7 pubs in embargo*/
|
140
|
$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'";
|
141
|
|
142
|
/*18: total number of fp7 pubs with sc39*/
|
143
|
$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'";
|
144
|
|
145
|
/*19: fp7 projs with sc39 and pubs*/
|
146
|
$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'";
|
147
|
|
148
|
/*20: total number of fp7 proj with sc39*/
|
149
|
$qsc39fp7projtotal = "SELECT count(number) from project where funding_lvl0='FP7' and sc39='yes'";
|
150
|
|
151
|
/*21: open access fp7 pubs with sc39*/
|
152
|
$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'";
|
153
|
|
154
|
|
155
|
/*ERC*/
|
156
|
|
157
|
/*22: total number of erc pubs*/
|
158
|
$qercpubstotal = "select count(r.id) from result r natural join result_projects rp join project p on rp.project=p.id where type='publication' and funding_lvl2='ERC'";
|
159
|
|
160
|
/*23: erc projects with pubs*/
|
161
|
$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'";
|
162
|
|
163
|
/*24: total erc projects*/
|
164
|
$qercprojtotal = "SELECT count(id) FROM project WHERE funding_lvl2 = 'ERC'";
|
165
|
|
166
|
/*25: erc open access pubs*/
|
167
|
$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'";
|
168
|
|
169
|
/*26: erc restricted pubs*/
|
170
|
$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'";
|
171
|
|
172
|
/*27: erc embargo pubs*/
|
173
|
$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'";
|
174
|
|
175
|
|
176
|
/*WT*/
|
177
|
|
178
|
/*28: total number of wt pubs*/
|
179
|
$qwtpubstotal = "select count(r.id) from result r natural join result_projects rp join project p on rp.project=p.id where type='publication' and date <> '' and funding_lvl0='WT'";
|
180
|
|
181
|
/*29: wt projects with pubs*/
|
182
|
$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'";
|
183
|
|
184
|
/*30: total wt projects*/
|
185
|
$qwtprojtotal = "SELECT count(id) FROM project WHERE funding_lvl0 = 'WT'";
|
186
|
|
187
|
/*31: wt open access pubs*/
|
188
|
$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'";
|
189
|
|
190
|
/*32: wt restricted pubs*/
|
191
|
$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'";
|
192
|
|
193
|
/*33: wt embargo pubs*/
|
194
|
$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'";
|
195
|
|
196
|
|
197
|
/*Natalia's extra stuff */
|
198
|
|
199
|
/*34: datasources with publication results */
|
200
|
$datasrc_withpubs = "SELECT count(distinct rd.datasource) from result_datasources rd join result r on r.id=rd.id where r.type='publication'";
|
201
|
|
202
|
/*35: organisations with publication results */
|
203
|
$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";
|
204
|
|
205
|
/*36: number of datasets */
|
206
|
$data_total = "select count(id) from result where type='dataset';";
|
207
|
|
208
|
/*1*/ $this->storeQuery('pubs', $qpubs);
|
209
|
/*2*/ $this->storeQuery('oapubs', $qoapubs);
|
210
|
/*3*/ $this->storeQuery('noapubs', $qnoapubs);
|
211
|
/*4*/ $this->storeQuery('fpubs', $qfpubs);
|
212
|
/*5*/ $this->storeQuery('proj', $qproj);
|
213
|
/*6*/ $this->storeQuery('datasrc', $qdatasrc);
|
214
|
/*7*/ $this->storeQuery('dtsrcpubs', $qdtsrcpubs);
|
215
|
/*8*/ $this->storeQuery('dtsrcpubreps', $qdtsrcpubreps);
|
216
|
/*9*/ $this->storeQuery('dtsrcoaj', $qdtsrcoaj);
|
217
|
/*10*/ $this->storeQuery('dtsrcpubaggr', $qdtsrcpubaggr);
|
218
|
/*11*/ $this->storeQuery('funders', $qfunders);
|
219
|
|
220
|
/*FP7*/
|
221
|
|
222
|
/*12*/ $this->storeQuery('fp7pubstotal', $qfp7pubstotal);
|
223
|
/*13*/ $this->storeQuery('fp7projpubs', $qfp7projpubs);
|
224
|
/*14*/ $this->storeQuery('fp7projtotal', $qfp7projtotal);
|
225
|
/*15*/ $this->storeQuery('fp7oapubs', $qfp7oapubs);
|
226
|
/*16*/ $this->storeQuery('fp7respubs', $qfp7respubs);
|
227
|
/*17*/ $this->storeQuery('fp7embpubs', $qfp7embpubs);
|
228
|
/*18*/ $this->storeQuery('sc39fp7pubstotal', $qsc39fp7pubstotal);
|
229
|
/*19*/ $this->storeQuery('sc39fp7projpubs', $qsc39fp7projpubs);
|
230
|
/*20*/ $this->storeQuery('sc39fp7projtotal', $qsc39fp7projtotal);
|
231
|
/*21*/ $this->storeQuery('sc39fp7oapubs', $qsc39fp7oapubs);
|
232
|
|
233
|
/*ERC*/
|
234
|
|
235
|
/*22*/ $this->storeQuery('ercpubstotal', $qercpubstotal);
|
236
|
/*23*/ $this->storeQuery('ercprojpubs', $qercprojpubs);
|
237
|
/*24*/ $this->storeQuery('ercprojtotal', $qercprojtotal);
|
238
|
/*25*/ $this->storeQuery('ercoapubs', $qercoapubs);
|
239
|
/*26*/ $this->storeQuery('ercrespubs', $qercrespubs);
|
240
|
/*27*/ $this->storeQuery('ercembpubs', $qercembpubs);
|
241
|
|
242
|
/*WT*/
|
243
|
|
244
|
/*28*/ $this->storeQuery('wtpubstotal', $qwtpubstotal);
|
245
|
/*29*/ $this->storeQuery('wtprojpubs', $qwtprojpubs);
|
246
|
/*30*/ $this->storeQuery('wtprojtotal', $qwtprojtotal);
|
247
|
/*31*/ $this->storeQuery('wtoapubs', $qwtoapubs);
|
248
|
/*32*/ $this->storeQuery('wtrespubs', $qwtrespubs);
|
249
|
/*33*/ $this->storeQuery('wtembpubs', $qwtembpubs);
|
250
|
|
251
|
/*34*/ $this->storeQuery('datasrc_withpubs', $datasrc_withpubs);
|
252
|
/*35*/ $this->storeQuery('org_withpubs', $org_withpubs);
|
253
|
/*36*/ $this->storeQuery('data_total', $data_total);
|
254
|
|
255
|
//$this->log->info("statistics numbers: ".print_r($temp, TRUE));
|
256
|
//$this->cache->connect();
|
257
|
// $this->cache->hmset("STATS_NUMBERS", $temp);
|
258
|
|
259
|
//$this->cache->save();
|
260
|
}
|
261
|
}
|
262
|
|
263
|
$csn = new ComputeStatsNumbers();
|
264
|
$csn->computeStats();
|
265
|
|
266
|
?>
|