Revision 34472
Added by Eri Katsari almost 10 years ago
includestatsnumbers.php | ||
---|---|---|
15 | 15 |
|
16 | 16 |
$GLOBALS['PREDIS_ROOT'] = dirname(__FILE__) . DS . 'predis'; |
17 | 17 |
|
18 |
|
|
18 | 19 |
class plgContentIncludestatsnumbers extends JPlugin { |
19 | 20 |
const CACHE_GROUP = "openaire.stats.plugin"; |
20 | 21 |
private $cache; |
... | ... | |
35 | 36 |
"port" => $this->params->get('cacheport') |
36 | 37 |
"persistent" => 1)); |
37 | 38 |
|
38 |
$this->cache->connect(); |
|
39 |
$this->cache->connect();
|
|
39 | 40 |
|
40 | 41 |
} catch(Exception $e) { |
41 |
JLog :: add("Error connecting to Redis server: ".$e->getMessage(), JLog :: ERROR, 'openaire'); |
|
42 |
JLog :: add("Stats Plugin : Error connecting to Redis server: ".$e->getMessage(), JLog :: ERROR, 'openaire');
|
|
42 | 43 |
$this->cache = null; |
43 | 44 |
} |
44 | 45 |
|
... | ... | |
89 | 90 |
/*35*/$this->codes[] = "{include_number ORG-WITHPUBS}"; |
90 | 91 |
/*36*/$this->codes[] = "{include_number DATA-TOTAL}"; |
91 | 92 |
|
92 |
JLog :: add('Include number Plugin!', JLog :: DEBUG, 'openaire'); |
|
93 |
// FET nums |
|
94 |
/*37*/$this->codes[] = "{include_number FETPUBS}"; |
|
95 |
/*38*/$this->codes[] = "{include_number FETOAPUBS}"; |
|
96 |
/*39*/$this->codes[] = "{include_number FETRESPUBS}"; |
|
97 |
/*40*/$this->codes[] = "{include_number FETEMBPUBS}"; |
|
98 |
|
|
99 |
|
|
100 |
// DATASETS |
|
101 |
/*41*/$this->codes[] = "{include_number DATASETPUBS}"; |
|
102 |
/*42*/$this->codes[] = "{include_number DATASETPROJ}"; |
|
103 |
/*43*/$this->codes[] = "{include_number PUBSDATASETS}"; |
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
// EGI NUMS |
|
109 |
/*44*/$this->codes[] = "{include_number EGIPUBS}"; |
|
110 |
/*45*/$this->codes[] = "{include_number EGIVO}"; |
|
111 |
/*46*/$this->codes[] = "{include_number EGIPROJ}"; |
|
112 |
|
|
113 |
|
|
114 |
// EGI NUMS |
|
115 |
/*47*/$this->codes[] = "{include_number EGIOA}"; |
|
116 |
/*48*/$this->codes[] = "{include_number EGIEMB}"; |
|
117 |
/*49*/$this->codes[] = "{include_number EGIRES}"; |
|
118 |
|
|
119 |
// FCT NUMS |
|
120 |
|
|
121 |
/*ERC*/ |
|
122 |
/*50*/$this->codes[] = "{include_number FCTPUBSTOTAL}"; |
|
123 |
/*51*/$this->codes[] = "{include_number FCTPROJPUBS}"; |
|
124 |
/*52*/$this->codes[] = "{include_number FCTPROJTOTAL}"; |
|
125 |
/*53*/$this->codes[] = "{include_number FCTOAPUBS}"; |
|
126 |
/*54*/$this->codes[] = "{include_number FCTRESPUBS}"; |
|
127 |
/*55*/$this->codes[] = "{include_number FCTEMBPUBS}"; |
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
JLog :: add('Stats Plugin', JLog :: DEBUG, 'openaire'); |
|
93 | 132 |
} |
94 | 133 |
|
95 | 134 |
public function onContentPrepare( $context, &$article, &$params, $page = 0 ) { |
96 |
$regex_base = '\{(include_number)\s+(PUBS|OAPUBS|NOAPUBS|FPUBS|PROJ|DATASRC|DATASRC-PUBS|DATASRC-PUBREPS|DATASRC-PUBOAJ|DATASRC-PUBAGGR|FUNDERS|FP7PUBSTOTAL|FP7PROJPUBS|FP7PROJTOTAL|FP7OAPUBS|FP7RESPUBS|FP7EMBPUBS|SC39FP7PUBSTOTAL|SC39FP7PROJPUBS|SC39FP7PROJTOTAL|SC39FP7OAPUBS|ERCPUBSTOTAL|ERCPROJTOTAL|ERCPROJPUBS|ERCOAPUBS|ERCRESPUBS|ERCEMBPUBS|WTPUBSTOTAL|WTPROJPUBS|WTPROJTOTAL|WTOAPUBS|WTRESPUBS|WTEMBPUBS|DATASRC-WITHPUBS|ORG-WITHPUBS|DATA-TOTAL)\}'; |
|
135 |
$regex_base = '\{(include_number)\s+(PUBS|OAPUBS|NOAPUBS|FPUBS|PROJ|DATASRC|DATASRC-PUBS|DATASRC-PUBREPS|DATASRC-PUBOAJ|DATASRC-PUBAGGR|FUNDERS|FP7PUBSTOTAL|FP7PROJPUBS|FP7PROJTOTAL|FP7OAPUBS|FP7RESPUBS|FP7EMBPUBS|SC39FP7PUBSTOTAL|SC39FP7PROJPUBS|SC39FP7PROJTOTAL|SC39FP7OAPUBS|ERCPUBSTOTAL|ERCPROJTOTAL|ERCPROJPUBS|ERCOAPUBS|ERCRESPUBS|ERCEMBPUBS|WTPUBSTOTAL|WTPROJPUBS|WTPROJTOTAL|WTOAPUBS|WTRESPUBS|WTEMBPUBS|DATASRC-WITHPUBS|ORG-WITHPUBS|DATA-TOTAL|FETPUBS|FETOAPUBS|FETRESPUBS|FETEMBPUBS|DATASETPUBS|DATASETPROJ|PUBSDATASETS|EGIPUBS|EGIVO|EGIPROJ|EGIOA|EGIEMB|EGIRESERCPUBSTOTAL|FCTPROJTOTAL|FCTPROJPUBS|FCTOAPUBS|FCTRESPUBS|FCTEMBPUBS)\}';
|
|
97 | 136 |
$regex = "/$regex_base/"; |
98 | 137 |
|
99 | 138 |
$contents = $article->text; |
100 | 139 |
$found = preg_match_all($regex, $contents, $matches); |
140 |
|
|
141 |
|
|
142 |
//JLog :: add( "Stats Plugin found : matches found: ".$found , JLog :: DEBUG, 'openaire') |
|
101 | 143 |
if (!$found){ return true;} |
102 | 144 |
|
103 | 145 |
try { |
104 | 146 |
$str = 'pgsql:host='.$this->params->get('dbhost').';port='.$this->params->get('dbport').';dbname='.$this->params->get('dbname').';user='.$this->params->get('dbuser').';password='.$this->params->get('dbpass'); |
105 | 147 |
$this->db = new PDO($str); |
106 | 148 |
} catch(Exception $e){ |
107 |
JLog :: add('Could not connect to database: ' . $e->getMessage(), JLog :: ERROR, 'openaire'); |
|
149 |
JLog :: add('Stats Plugin : Could not connect to database: ' . $e->getMessage(), JLog :: ERROR, 'openaire');
|
|
108 | 150 |
return false; |
109 | 151 |
} |
110 | 152 |
$cnt = count($matches); |
111 |
JLog :: add( "matches found: ".$cnt, JLog :: DEBUG, 'openaire');
|
|
153 |
//JLog :: add( "Stats Plugin : matches count found: ".$cnt." for matches ".print_r($matches), JLog :: DEBUG, 'openaire');
|
|
112 | 154 |
|
113 | 155 |
$result = NULL; |
114 | 156 |
if ($this -> cache != null) { |
115 | 157 |
|
116 | 158 |
if($this->cache->exists("STATS_NUMBERS")) { |
117 | 159 |
$result = $this -> cache -> hgetall("STATS_NUMBERS"); |
118 |
JLog :: add("Found in cache!", JLog :: DEBUG, 'openaire'); |
|
160 |
JLog :: add("Stats Plugin : Found in cache!", JLog :: DEBUG, 'openaire');
|
|
119 | 161 |
} else { |
120 | 162 |
$this->cache->quit(); |
121 |
JLog :: add("Not found in cache!", JLog :: DEBUG, 'openaire'); |
|
163 |
JLog :: add("Stats Plugin : Not found in cache!", JLog :: DEBUG, 'openaire');
|
|
122 | 164 |
$result = $this->makequeries(true); |
123 | 165 |
} |
124 | 166 |
|
125 | 167 |
} else {//make the queries but don't cache the result |
126 | 168 |
$result = $this->makequeries(false); |
169 |
|
|
170 |
|
|
127 | 171 |
} |
128 | 172 |
|
129 | 173 |
$article->text = str_replace($this->codes, $result, $article->text); |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
//JLog :: add( "Stats Plugin : $this->codes ".print_r($this->codes), JLog :: DEBUG, 'openaire'); |
|
130 | 178 |
|
179 |
//JLog :: add( "Stats Plugin : result : ".print_r($result), JLog :: DEBUG, 'openaire'); |
|
180 |
|
|
131 | 181 |
return true; |
132 | 182 |
} |
133 | 183 |
|
... | ... | |
148 | 198 |
/*9*/ $qdtsrcoaj = "SELECT count(*) FROM datasource WHERE type='Aggregated Journal'"; |
149 | 199 |
/*10*/$qdtsrcpubaggr = "SELECT count(*) FROM datasource WHERE type='Aggregated Repository'"; |
150 | 200 |
/*11*/$qfunders = "SELECT count(distinct funding_lvl0) FROM project WHERE funding_lvl0 !=''"; |
201 |
|
|
151 | 202 |
|
152 | 203 |
/*FP7*/ |
153 | 204 |
/*12: total number of fp7 pubs */ |
... | ... | |
205 | 256 |
/*35: organisations with publication results */ |
206 | 257 |
$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"; |
207 | 258 |
/*36: number of datasets */ |
208 |
$data_total = "select count(id) from result where type='dataset';"; |
|
259 |
$data_total = "select count(distinct id) from result where type='dataset';";
|
|
209 | 260 |
|
261 |
/*FET */ |
|
210 | 262 |
|
263 |
|
|
264 |
$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 ='fet'"; |
|
265 |
|
|
266 |
$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 ='fet' and r. bestlicense='Open Access'"; |
|
267 |
|
|
268 |
|
|
269 |
$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 ='fet' and r. bestlicense='Restricted'"; |
|
270 |
|
|
271 |
$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 ='fet' and r. bestlicense='Embargo'"; |
|
272 |
|
|
273 |
|
|
274 |
/*DATASETS */ |
|
275 |
|
|
276 |
$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'" ; |
|
277 |
|
|
278 |
//# of datasets linked to projects |
|
279 |
|
|
280 |
$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' "; |
|
281 |
|
|
282 |
//# of publications linked to datasets |
|
283 |
|
|
284 |
$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'"; |
|
285 |
|
|
286 |
/*EGI PAGE NUMS*/ |
|
287 |
|
|
288 |
|
|
289 |
$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'"; |
|
290 |
|
|
291 |
$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' "; |
|
292 |
|
|
293 |
$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'"; |
|
294 |
|
|
295 |
$egioa="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='Open Access'"; |
|
296 |
$egiemb="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='Embargo'"; |
|
297 |
$egires="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='Restricted'"; |
|
298 |
|
|
299 |
/* FCT*/ |
|
300 |
/*FCT*/ |
|
301 |
|
|
302 |
/*22: total number of FCTpubs*/ |
|
303 |
$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'"; |
|
304 |
|
|
305 |
/*23: FCTprojects with pubs*/ |
|
306 |
$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'"; |
|
307 |
/*24: total FCTprojects*/ |
|
308 |
$qfctprojtotal = "SELECT count(id) FROM project WHERE funding_lvl0 = 'FCT'"; |
|
309 |
|
|
310 |
/*25: FCTopen access pubs*/ |
|
311 |
$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'"; |
|
312 |
/*26: FCTrestricted pubs*/ |
|
313 |
$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'"; |
|
314 |
|
|
315 |
/*27: FCTembargo pubs*/ |
|
316 |
$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'"; |
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
211 | 321 |
/*1*/ $temp['pubs'] = $this->doQuery($qpubs); |
212 | 322 |
/*2*/ $temp['oapubs'] = $this->doQuery($qoapubs); |
213 | 323 |
/*3*/ $temp['noapubs'] = $this->doQuery($qnoapubs); |
... | ... | |
252 | 362 |
/*34*/$temp['datasrc_withpubs'] = $this->doQuery($datasrc_withpubs); |
253 | 363 |
/*35*/$temp['org_withpubs'] = $this->doQuery($org_withpubs); |
254 | 364 |
/*36*/$temp['data_total'] = $this->doQuery($data_total); |
365 |
//FET NUMS |
|
366 |
/*37*/$temp['fetpubs'] = $this->doQuery($fetpubs); |
|
367 |
/*38*/$temp['fetoapubs'] = $this->doQuery($fetoapubs); |
|
368 |
/*39*/$temp['fetrespubs'] = $this->doQuery($fetrespubs); |
|
369 |
/*40*/$temp['fetembpubs'] = $this->doQuery($fetembpubs); |
|
255 | 370 |
|
371 |
/*41*/$temp['datasetpubs'] = $this->doQuery($datasetpubs); |
|
372 |
/*42*/$temp['datasetproj'] = $this->doQuery($datasetproj); |
|
373 |
/*43*/$temp['pubsdatasets'] = $this->doQuery($pubsdatasets); |
|
374 |
|
|
375 |
|
|
376 |
/*44*/$temp['egivo'] = $this->doQuery($egivo); |
|
377 |
/*45*/$temp['egiproj'] = $this->doQuery($egiproj); |
|
378 |
/*46*/$temp['egipubs'] = $this->doQuery($egipubs); |
|
379 |
|
|
380 |
|
|
381 |
/*44*/$temp['egioa'] = $this->doQuery($egioa); |
|
382 |
/*45*/$temp['egiemb'] = $this->doQuery($egiemb); |
|
383 |
/*46*/$temp['egires'] = $this->doQuery($egires); |
|
384 |
|
|
385 |
|
|
386 |
/*FCT*/ |
|
387 |
/*22*/$temp['fctpubstotal'] = $this->doQuery($qfctpubstotal); |
|
388 |
/*23*/$temp['fctprojpubs'] = $this->doQuery($qfctprojpubs); |
|
389 |
/*24*/$temp['fctprojtotal'] = $this->doQuery($qfctprojtotal); |
|
390 |
/*25*/$temp['fctoapubs'] = $this->doQuery($qfctoapubs); |
|
391 |
/*26*/$temp['fctrespubs'] = $this->doQuery($qfctrespubs); |
|
392 |
/*27*/$temp['fctembpubs'] = $this->doQuery($qfctembpubs); |
|
393 |
|
|
394 |
|
|
395 |
|
|
256 | 396 |
if($addflag){ |
257 |
JLog:: add("params to store: ".print_r($temp, TRUE), JLog :: ERROR, 'openaire'); |
|
397 |
JLog:: add("Stats Plugin : params to store: ".print_r($temp, TRUE), JLog :: ERROR, 'openaire');
|
|
258 | 398 |
|
259 | 399 |
$this->cache = new Predis\Client(array( |
260 | 400 |
"scheme" => $this->params->get('cachescheme'), |
... | ... | |
273 | 413 |
$stmt = $this->db->query($query); |
274 | 414 |
if(!$stmt){ |
275 | 415 |
$arr = $this->db->errorInfo(); |
276 |
JLog :: add("Error executing query: ".$query." ".$arr[2], JLog :: ERROR, 'openaire'); |
|
416 |
JLog :: add("Stats Plugin : Error executing query: ".$query." ".$arr[2], JLog :: ERROR, 'openaire');
|
|
277 | 417 |
return "-"; |
278 | 418 |
} |
279 | 419 |
$t = $stmt->fetch(); |
Also available in: Unified diff
added fct & fet nums