1
|
<?php
|
2
|
/*
|
3
|
Has a database object, a codifier object and a cache object ....
|
4
|
gets requests for data (from view), codifys them, checks if there are in the cache, if not gets them from db, if yes, gets them from cache
|
5
|
places restrictions on them and sends them to model
|
6
|
also sets up the view
|
7
|
|
8
|
*/
|
9
|
require_once("paths.php");
|
10
|
//setting up the logger
|
11
|
require_once('./js/log4php/Logger.php');
|
12
|
Logger::configure('./js/log4php/log4php.xml');
|
13
|
$logger = Logger::getLogger("controller");
|
14
|
require_once('MYDB.php');
|
15
|
//require_once('error_handler.php');
|
16
|
//require_once('help_functions.php');
|
17
|
|
18
|
class Controller {
|
19
|
|
20
|
private $database;
|
21
|
private $log;
|
22
|
private $data = null;
|
23
|
private $chart;
|
24
|
private $chart2;
|
25
|
private $colors = array();
|
26
|
private $size = 30;
|
27
|
|
28
|
|
29
|
private $myqueries = null;
|
30
|
|
31
|
function __construct($myflag = true){
|
32
|
|
33
|
// this creates a logger named "Controller"
|
34
|
$this->log = Logger::getLogger(__CLASS__);
|
35
|
$this->database = new MYDB();
|
36
|
|
37
|
if($myflag) {
|
38
|
$this->database->loadSchema($GLOBALS['schema_file']);
|
39
|
} else {
|
40
|
$this->database->doConnect($GLOBALS['schema_file']);
|
41
|
}
|
42
|
|
43
|
$this->myqueries = array();
|
44
|
$this->myqueries['mperf1'] = array();
|
45
|
$this->myqueries['mperf1']['q'] = "select funding_lvl1, max(daysfromend) from result_projects, project where result_projects.project=project.id and funding_lvl0='FP7' group by funding_lvl1 order by funding_lvl1";
|
46
|
$this->myqueries['aperf1'] = array();
|
47
|
$this->myqueries['aperf1']['q'] = "select funding_lvl1, avg(daysfromend) from result_projects, project where result_projects.project=project.id and funding_lvl0='FP7' and daysfromend>=0 group by funding_lvl1 order by funding_lvl1";
|
48
|
|
49
|
$this->myqueries['mperf2'] = array();
|
50
|
$this->myqueries['mperf2']['q'] = "select funding_lvl2, max(daysfromend) from result_projects, project where result_projects.project=project.id and funding_lvl0='FP7' group by funding_lvl2 order by funding_lvl2";
|
51
|
$this->myqueries['aperf2'] = array();
|
52
|
$this->myqueries['aperf2']['q'] = "select funding_lvl2, avg(daysfromend) from result_projects, project where result_projects.project=project.id and funding_lvl0='FP7' and daysfromend>=0 group by funding_lvl2 order by funding_lvl2";
|
53
|
|
54
|
$this->myqueries['maperf1'] = array();
|
55
|
$this->myqueries['maperf1']['q'] = "select funding_lvl1, max(daysfromend), avg(daysfromend) from result_projects, project where result_projects.project=project.id and funding_lvl0='FP7' and daysfromend>=0 group by funding_lvl1 order by funding_lvl1";
|
56
|
|
57
|
$this->myqueries['maperf2'] = array();
|
58
|
$this->myqueries['maperf2']['q'] = "select funding_lvl2, max(daysfromend), avg(daysfromend) from result_projects, project where result_projects.project=project.id and funding_lvl0='FP7' and daysfromend>=0 group by funding_lvl2 order by funding_lvl2";
|
59
|
|
60
|
$this->myqueries['pubsperf1'] = array();
|
61
|
$this->myqueries['pubsperf1']['q'] = "select extract(year from date(r.date)), count(distinct p.id) as field0, funding_lvl1 from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id where extract(year from date(r.date)) >= 2007 and date <> '' and funding_lvl0='FP7' and date(r.date) < now() group by funding_lvl1, extract(year from date(r.date)) order by extract(year from date(r.date)), funding_lvl1";
|
62
|
|
63
|
$this->myqueries['pubsperf2'] = array();
|
64
|
$this->myqueries['pubsperf2']['q'] = "select extract(year from date(r.date)), count(distinct r.id) as field0, funding_lvl2 from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id where extract(year from date(r.date)) >= 2007 and date <> '' and funding_lvl0='FP7' and funding_lvl2 <> '' and date(r.date) < now() group by funding_lvl2, extract(year from date(r.date)) order by extract(year from date(r.date)), funding_lvl2";
|
65
|
|
66
|
$this->myqueries['pubsperf1_double'] = array();
|
67
|
$this->myqueries['pubsperf1_double']['q'] = "select funding_lvl1, count(sq.id), sum((case when access_mode='Open Access' then 1 else 0 end)) as open from (select distinct r.id, access_mode, funding_lvl1 from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id where funding_lvl0='FP7' and type='publication') as sq group by sq.funding_lvl1 order by funding_lvl1";
|
68
|
|
69
|
$this->myqueries['pubsperf2_double'] = array();
|
70
|
$this->myqueries['pubsperf2_double']['q'] = "select funding_lvl2, count(sq.id), sum((case when access_mode='Open Access' then 1 else 0 end)) as open from (select distinct r.id, access_mode, funding_lvl2 from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id where funding_lvl0='FP7' and funding_lvl2 <> '' and type='publication') as sq group by sq.funding_lvl2 order by funding_lvl2";
|
71
|
|
72
|
$this->myqueries['pubsperf1_total'] = array();
|
73
|
$this->myqueries['pubsperf1_total']['q'] = "select funding_lvl1, count(sq.id) from (select distinct r.id, access_mode, funding_lvl1 from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id where funding_lvl0='FP7' and type='publication') as sq group by sq.funding_lvl1 order by funding_lvl1";
|
74
|
|
75
|
$this->myqueries['pubsperf2_total'] = array();
|
76
|
$this->myqueries['pubsperf2_total']['q'] = "select funding_lvl2, count(sq.id) from (select distinct r.id, access_mode, funding_lvl2 from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id where funding_lvl0='FP7' and funding_lvl2 <> '' and type='publication') as sq group by sq.funding_lvl2 order by funding_lvl2";
|
77
|
|
78
|
$this->myquerie['allproj'] = array();
|
79
|
$this->myqueries['allproj']['q'] = "select acronym, startdate, enddate, funding_lvl1, funding_lvl2, numpubs, delayedpubs, case when daysforlastpub>0 then daysforlastpub else 0 end as days from project where funding_lvl0='FP7' and numpubs>0 and enddate!='' and cast(enddate as date) < CURRENT_DATE order by days desc, funding_lvl1, funding_lvl2";
|
80
|
|
81
|
$this->myqueries['erctime'] = array();
|
82
|
|
83
|
$this->myqueries['erctime']['q'] = "select r.year, count(r.id) from result r natural join result_projects rp join project p on rp.project=p.id where type='publication' and r.year >= 2007 and r.year > 0 and funding_lvl2='ERC' and r.year < 2015 group by r.year order by r.year ; ";
|
84
|
|
85
|
|
86
|
|
87
|
/* WT IS NOW A FUNDER */
|
88
|
$this->myqueries['wttime'] = array();
|
89
|
$this->myqueries['wttime']['q'] = " select r.year, count(r.id) from result r natural join result_projects rp join project p on rp.project=p.id where type='publication' and r.year >= 2007 and r.year >0 and funder='Wellcome Trust' and r.year < 2015 group by r.year order by r.year;";
|
90
|
/*
|
91
|
$this->myqueries['wttime'] = array();
|
92
|
$this->myqueries['wttime']['q'] = " select r.year, count(r.id) from result r natural join result_projects rp join project p on rp.project=p.id where type='publication' and r.year >= 2007 and r.year >0 and funding_lvl0='WT' and r.year < 2015 group by r.year order by r.year;";
|
93
|
|
94
|
*/
|
95
|
$this->myqueries['projpubs'] = array();
|
96
|
$this->myqueries['projpubs']['q'] = "SELECT project.funding_lvl1 as xfield, count(distinct project.id) as field0 FROM project, project_results, result WHERE project.project_results=project_results.id and project_results.result=result.id and (project.funding_lvl0='FP7') and (project.haspubs='yes') and (result.type='publication') GROUP BY project.funding_lvl1 ORDER BY project.funding_lvl1 LIMIT 30";
|
97
|
|
98
|
$this->myqueries['projpubsf2'] = array();
|
99
|
$this->myqueries['projpubsf2']['q'] = "SELECT project.funding_lvl2 as xfield, count(distinct project.id) as field0 FROM project, project_results, result WHERE project.project_results=project_results.id and project_results.result=result.id and (project.funding_lvl0='FP7') and (project.funding_lvl2 <> '' ) and (project.haspubs='yes') and (result.type='publication') GROUP BY project.funding_lvl2 ORDER BY project.funding_lvl2 LIMIT 30";
|
100
|
|
101
|
$this->myqueries['fp7pubsdtsrc']= array();
|
102
|
$this->myqueries['fp7pubsdtsrc']['q'] = "select datasource.type, count(distinct result_projects.id) from result_projects, project, result_datasources, datasource, result where result.id=result_projects.id and result.type='publication' and result_projects.project=project.id and result_datasources.datasource=datasource.id and result_projects.id=result_datasources.id and funding_lvl0='FP7'group by datasource.type";
|
103
|
|
104
|
// ERI - TODO egi timeline has been updated- change it everywhere
|
105
|
$this->myqueries['egiTimeline']= array();
|
106
|
$this->myqueries['egiTimeline']['q'] = "select r.year as xfield, count(r.id) as field0 from result r,result_concepts rc, concept con, context ctx, category cat where rc.id=r.id and con.id=rc.concept and con.category= cat.id and lower(cat.context)= lower(ctx.name) and cat.context ='egi' and r.year>0 group by r.year order by r.year asc;";
|
107
|
|
108
|
$this->myqueries['egiProjects']= array();
|
109
|
$this->myqueries['egiProjects']['q'] = "select c.name as xfield, 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.id='egi::projects' group by c.name order by c.name;";
|
110
|
|
111
|
$this->myqueries['egiVO']= array();
|
112
|
$this->myqueries['egiVO']['q'] = "select c.name as xfield, 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.id='egi::virtual' group by c.name order by c.name;";
|
113
|
|
114
|
$this->myqueries['egiOA']= array();
|
115
|
$this->myqueries['egiOA']['q'] = "select bestlicense as xfield, 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 group
|
116
|
by r.bestlicense";
|
117
|
|
118
|
|
119
|
//FET queries
|
120
|
|
121
|
$this->myqueries['fetTimeline']= array();
|
122
|
|
123
|
$this->myqueries['fetTimeline']['q'] = "select r.year as xfield, count(distinct r.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 like 'fet%' and r.year >0 group by r.year order by r.year asc;";
|
124
|
$this->myqueries['fetFlagships']= array();
|
125
|
|
126
|
$this->myqueries['fetFlagships']['q'] = "select c.name as xfield , count ( distinct r.id) as field0 from result r,result_concepts rc , project p,concept c ,result_projects rp where rc.id =r.id and r.id=rp.id and rp.project=p.id and c.category ='fet-fp7::flagship' and rc.concept=c.id group by p.id , c.name order by count ( distinct r.id) desc limit 3;";
|
127
|
|
128
|
|
129
|
|
130
|
$this->myqueries['fetProactive']= array();
|
131
|
|
132
|
$this->myqueries['fetProactive']['q'] = "select c.name as xfield , count ( distinct r.id) as field0 from result r,result_concepts rc , project p,concept c ,result_projects rp where rc.id =r.id and r.id=rp.id and rp.project=p.id and c.category ='fet-fp7::proactive' and rc.concept=c.id group by p.id , c.name order by count ( distinct r.id) desc limit 5;";
|
133
|
|
134
|
|
135
|
|
136
|
$this->myqueries['fetOA']= array();
|
137
|
$this->myqueries['fetOA']['q'] = "select bestlicense as xfield, 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 join category cat on cat.id=c.category where cat.id like 'fet%' group by bestlicense ; ";
|
138
|
|
139
|
$this->myqueries['fetOpen']= array();
|
140
|
|
141
|
$this->myqueries['fetOpen']['q'] = "select c.name as xfield , count ( distinct r.id) as field0 from result r,result_concepts rc , project p,concept c ,result_projects rp where rc.id =r.id and r.id=rp.id and rp.project=p.id and c.category ='fet-fp7::open' and rc.concept=c.id group by p.id , c.name order by count ( distinct r.id) desc limit 5;";
|
142
|
|
143
|
|
144
|
|
145
|
|
146
|
|
147
|
|
148
|
/*TODO added WT pie query - copy to beta and prod*/
|
149
|
/*
|
150
|
$this->myqueries['wtOA']= array();
|
151
|
$this->myqueries['wtOA']['q'] =" SELECT bestlicense as xfield,count(distinct result_projects.id) as field0 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' group by bestlicense;";
|
152
|
*/
|
153
|
|
154
|
$this->myqueries['ercOA']= array();
|
155
|
$this->myqueries['ercOA']['q'] ="SELECT bestlicense as xfield,count(distinct result_projects.id) as field0 FROM result,result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and type='publication' group by bestlicense";
|
156
|
|
157
|
|
158
|
|
159
|
/*
|
160
|
WT IS NOW A FUNDER !!!
|
161
|
*/
|
162
|
|
163
|
$this->myqueries['wtOA']= array();
|
164
|
$this->myqueries['wtOA']['q'] =" SELECT bestlicense as xfield,count(distinct result_projects.id) as field0 FROM result,result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funder = 'Wellcome Trust' and type='publication' group by bestlicense;";
|
165
|
|
166
|
|
167
|
/* FCT*/
|
168
|
/*
|
169
|
|
170
|
$this->myqueries['fcttime'] = array();
|
171
|
|
172
|
$this->myqueries['fcttime']['q'] = "select r.year, count( distinct r.id) from result r natural join result_projects rp join project p on rp.project=p.id where type='publication' and r.year >= 2007 and r.year < 2015 and funding_lvl0='FCT' group by r.year order by r.year";
|
173
|
|
174
|
|
175
|
$this->myqueries['fctOA']= array();
|
176
|
$this->myqueries['fctOA']['q'] ="SELECT bestlicense as xfield,count(distinct result_projects.id) as field0 FROM result,result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FCT' and type='publication' group by bestlicense";
|
177
|
|
178
|
|
179
|
$this->myqueries['fctfp7time']= array();
|
180
|
|
181
|
$this->myqueries['fctfp7time']['q']="select r.year, count(distinct r.id) from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id join result_projects rp2 on rp2.id=r.id join project p2 on rp2.project=p2.id where p2.funding_lvl0='FCT' and p.funding_lvl0='FP7' and r.year >= 2007 and r.year < 2015 group by r.year order by r.year ;";
|
182
|
|
183
|
|
184
|
*/
|
185
|
|
186
|
|
187
|
/* FCT FOR NEW FUNDERS*/
|
188
|
|
189
|
|
190
|
$this->myqueries['fcttime'] = array();
|
191
|
|
192
|
$this->myqueries['fcttime']['q'] = "select r.year, count( distinct r.id) from result r natural join result_projects rp join project p on rp.project=p.id where type='publication' and r.year >= 2007 and r.year < 2015 and funder = 'FCT' group by r.year order by r.year";
|
193
|
|
194
|
$this->myqueries['fctOA']= array();
|
195
|
$this->myqueries['fctOA']['q'] ="SELECT bestlicense as xfield,count(distinct result_projects.id) as field0 FROM result,result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funder='FCT' and type='publication' group by bestlicense";
|
196
|
|
197
|
|
198
|
$this->myqueries['fctfp7time']= array();
|
199
|
|
200
|
$this->myqueries['fctfp7time']['q']="select r.year, count(distinct r.id) from result r join result_projects rp on r.id=rp.id join project p on rp.project=p.id join result_projects rp2 on rp2.id=r.id join project p2 on rp2.project=p2.id where p2.funder='FCT' and p.funding_lvl0='FP7' and r.year >= 2007 and r.year < 2015 group by r.year order by r.year ;";
|
201
|
|
202
|
|
203
|
|
204
|
$this->colors[0] = '#4572A7';
|
205
|
$this->colors[1] = '#AA4643';
|
206
|
$this->colors[2] = '#89A54E';
|
207
|
|
208
|
$this->types[0] = 'column';
|
209
|
$this->types[1] = 'spline';
|
210
|
$this->types[2] = 'spline';
|
211
|
|
212
|
/*set up*/
|
213
|
$this->chart = array();
|
214
|
$this->chart['chart'] = array();
|
215
|
//$this->chart['exporting'] = array();
|
216
|
$this->chart['title'] = array();
|
217
|
$this->chart['xAxis'] = array();
|
218
|
$this->chart['xAxis']['labels'] = array();
|
219
|
$this->chart['xAxis']['title'] = array();
|
220
|
$this->chart['xAxis']['categories'] = array();
|
221
|
$this->chart['yAxis'] = array();
|
222
|
$this->chart['tooltip'] = array();
|
223
|
$this->chart['legend'] = array();
|
224
|
$this->chart['series'] = array();
|
225
|
/*more*/
|
226
|
//$this->chart['exporting']['enabled'] = true;
|
227
|
$this->chart['chart']['renderTo'] = 'chart';
|
228
|
$this->chart['chart']['reflow'] = false;
|
229
|
$this->chart['chart']['showAxes'] = true;
|
230
|
$this->chart['chart']['zoomType'] = 'xy';
|
231
|
//$this->chart['chart']['margin'] = 'auto';
|
232
|
//$this->chart['chart']['marginRight'] = 70;
|
233
|
//$this->chart['chart']['marginBottom'] = 70;
|
234
|
//$this->chart['chart']['height'] = 450;
|
235
|
//$this->chart['chart']['spacingBottom'] = 100;
|
236
|
$this->chart['credits']['enabled'] = false;
|
237
|
//$this->chart['credits']['text'] = "from OpenAIRE via HighCharts".date("d / m / Y");
|
238
|
//$this->chart['credits']['href'] = "#";
|
239
|
//$this->chart['credits']['position'] = array();
|
240
|
//$this->chart['credits']['position']['y'] = -2;
|
241
|
|
242
|
|
243
|
/*$this->chart['xAxis']['labels']['overflow'] = null;//'justify';
|
244
|
$this->chart['xAxis']['labels']['style'] = array();
|
245
|
$this->chart['xAxis']['labels']['style']['font-size'] = '10px';
|
246
|
|
247
|
$this->chart['xAxis']['showEmpty'] = true;
|
248
|
$this->chart['xAxis']['labels']['enabled'] = true;
|
249
|
$this->chart['xAxis']['labels']['style'] = array();
|
250
|
$this->chart['xAxis']['labels']['style']['font-size'] = '8px';
|
251
|
//$this->chart['xAxis']['labels']['style']['margin-left'] = '10px';
|
252
|
//$this->chart['xAxis']['labels']['style']['margin-right'] = '10px';*/
|
253
|
$this->chart['xAxis']['startOnTick'] = true;
|
254
|
$this->chart['xAxis']['endOnTick'] = true;
|
255
|
$this->chart['xAxis']['showFirstLabel'] = true;
|
256
|
$this->chart['xAxis']['showLastLabel'] = true;
|
257
|
|
258
|
$this->chart['tooltip']['percentageDecimals'] = 1;
|
259
|
$this->chart['tooltip']['valueDecimals'] = 1;
|
260
|
$this->chart['legend']['layout'] = 'vertical';
|
261
|
$this->chart['legend']['align'] = 'right';
|
262
|
$this->chart['legend']['verticalAlign'] = 'top';
|
263
|
$this->chart['legend']['floating'] = true;
|
264
|
$this->chart['legend']['borderWidth'] = 0;
|
265
|
$this->chart['legend']['x'] = -10;
|
266
|
$this->chart['legend']['y'] = 50;
|
267
|
$this->chart['legend']['padding'] = 3;
|
268
|
$this->chart['legend']['itemMarginBottom'] = 5;
|
269
|
|
270
|
//for scatter plots
|
271
|
$this->chart['plotOptions'] = array();
|
272
|
$this->chart['plotOptions']['series'] = array();
|
273
|
$this->chart['plotOptions']['series']['showCheckbox'] = true;
|
274
|
$this->chart['plotOptions']['series']['selected'] = true;
|
275
|
$this->chart['plotOptions']['scatter'] = array();
|
276
|
$this->chart['plotOptions']['scatter']['marker'] = array();
|
277
|
$this->chart['plotOptions']['scatter']['marker']['radius'] = 5;
|
278
|
$this->chart['plotOptions']['scatter']['marker']['states'] = array();
|
279
|
$this->chart['plotOptions']['scatter']['marker']['states']['hover'] = array();
|
280
|
$this->chart['plotOptions']['scatter']['marker']['states']['hover']['enabled'] = true;
|
281
|
$this->chart['plotOptions']['scatter']['marker']['states']['hover']['lineColor'] = 'rgb(100,100,100)';
|
282
|
$this->chart['plotOptions']['scatter']['states'] = array();
|
283
|
$this->chart['plotOptions']['scatter']['states']['hover'] = array();
|
284
|
$this->chart['plotOptions']['scatter']['states']['hover']['marker'] = array();
|
285
|
$this->chart['plotOptions']['scatter']['states']['hover']['marker']['enabled'] = false;
|
286
|
|
287
|
$this->chart['plotOptions']['area'] = array();
|
288
|
$this->chart['plotOptions']['area']['stacking'] = null;
|
289
|
|
290
|
$this->chart['plotOptions']['areaspline'] = array();
|
291
|
$this->chart['plotOptions']['areaspline']['stacking'] = null;
|
292
|
|
293
|
//for pie charts
|
294
|
$this->chart['plotOptions']['pie'] = array();
|
295
|
$this->chart['plotOptions']['pie']['allowPointSelect'] = true;
|
296
|
//$this->chart['plotOptions']['pie']['size'] = '50%';
|
297
|
$this->chart['plotOptions']['pie']['cursor'] = 'pointer';
|
298
|
$this->chart['plotOptions']['pie']['showInLegend'] = true;
|
299
|
$this->chart['plotOptions']['pie']['dataLabels'] = array();
|
300
|
$this->chart['plotOptions']['pie']['dataLabels']['enabled'] = true;
|
301
|
$this->chart['plotOptions']['pie']['dataLabels']['color'] = '#000000';
|
302
|
$this->chart['plotOptions']['pie']['dataLabels']['connectorColor'] = '#000000';
|
303
|
$this->chart['plotOptions']['pie']['dataLabels']['crop'] = false;
|
304
|
$this->chart['plotOptions']['pie']['dataLabels']['distance'] = 10;
|
305
|
//$this->chart['plotOptions']['pie']['dataLabels']['formatter'] = '';
|
306
|
//for column
|
307
|
$this->chart['plotOptions']['column'] = array();
|
308
|
$this->chart['plotOptions']['column']['allowPointSelect'] = true;
|
309
|
$this->chart['plotOptions']['column']['cursor'] = 'pointer';
|
310
|
$this->chart['plotOptions']['column']['showInLegend'] = true;
|
311
|
$this->chart['plotOptions']['column']['grouping'] = true;
|
312
|
|
313
|
$this->chart['plotOptions']['area'] = array();
|
314
|
}
|
315
|
|
316
|
function makeQuery($viztype,$persistent) {
|
317
|
if(!isset($_GET['data'])){
|
318
|
$this->log->info("data param not set: ". print_r($_GET,true));
|
319
|
return 'empty';
|
320
|
}
|
321
|
else {
|
322
|
$data = $_GET['data'];
|
323
|
|
324
|
|
325
|
$this->data = json_decode($data,true);//print_r($this->data);
|
326
|
$this->log->debug("data param decoded: ". print_r($this->data,true));
|
327
|
$cachedData = $this->data;
|
328
|
//unset($cachedData['yaxisheaders']);
|
329
|
//unset($cachedData['fieldsheaders']);
|
330
|
unset($cachedData['title']);
|
331
|
unset($cachedData['subtitle']);
|
332
|
//unset($cachedData['xaxistitle']);
|
333
|
unset($cachedData['theme']);
|
334
|
unset($cachedData['xStyle']);
|
335
|
$this->size = $this->data['size'];
|
336
|
return @$this->computeChartObject($viztype,$persistent);
|
337
|
}
|
338
|
}
|
339
|
|
340
|
function computeChartObject($viztype,$persistent){
|
341
|
//$this->log->info("DATA: ".print_r($this->data,true));
|
342
|
if(!isset($this->data['query'])){
|
343
|
$this->log->info("query not set");
|
344
|
//TODO here add persistent value??
|
345
|
$this->queryResult = $this->database->getData($this->data,$persistent);
|
346
|
}
|
347
|
else{
|
348
|
$this->log->info("query set");
|
349
|
$this->queryResult = array("type"=>"chart","data"=>$this->database->performQuery($this->myqueries[$this->data['query']]['q'],true));
|
350
|
|
351
|
}
|
352
|
|
353
|
|
354
|
$this->log->info("data from DB: ".print_r($this->queryResult,true));
|
355
|
if($viztype=="chart"){
|
356
|
if($this->queryResult['type'] == 'scatter'){
|
357
|
$this->createScatterData();
|
358
|
}
|
359
|
else{
|
360
|
$this->createChartData();
|
361
|
}
|
362
|
|
363
|
if(isset($this->data['in']) && count($this->data['in'])){
|
364
|
$this->chart2 = $this->chart;
|
365
|
for($w=0;$w<count($this->chart['series']);$w++){
|
366
|
//$whichfield = $this->data['in'][$w]['f'];
|
367
|
//$this->chart2 = $this->chart;
|
368
|
$data = $this->chart2['series'][$w]['data'];
|
369
|
for($i=1;$i<count($this->chart2['xAxis']['categories']);$i++){
|
370
|
$data[$i] += $data[$i-1];
|
371
|
}
|
372
|
$this->chart2['series'][$w]['data'] = $data;
|
373
|
}
|
374
|
//return json_encode(array($this->chart,$this->chart2),JSON_NUMERIC_CHECK);
|
375
|
return json_encode(array($this->chart,$this->chart2));
|
376
|
}
|
377
|
|
378
|
//return json_encode($this->chart,JSON_NUMERIC_CHECK);
|
379
|
return json_encode($this->chart);
|
380
|
}
|
381
|
if($viztype=='table'){
|
382
|
//return json_encode($this->queryResult,JSON_NUMERIC_CHECK);
|
383
|
return json_encode($this->queryResult);
|
384
|
}
|
385
|
}
|
386
|
|
387
|
function COM_getMeasMetadata(){
|
388
|
if(!isset($_GET['table'])) {
|
389
|
echo 'empty';
|
390
|
}
|
391
|
else{
|
392
|
echo json_encode($this->database->getMeasMetadata($_GET['table']));
|
393
|
}
|
394
|
}
|
395
|
|
396
|
function COM_defaultChart() {
|
397
|
//get the default values for this table
|
398
|
$temp = $this->database->getDefaultData($_GET['table']);
|
399
|
if($temp == 'empty')
|
400
|
echo json_encode("empty");
|
401
|
else{
|
402
|
$this->size = $temp['size'];
|
403
|
//$this->queryResult = $temp['data'];
|
404
|
$this->data = $temp['selectedData'];
|
405
|
//echo json_encode($this->data,JSON_NUMERIC_CHECK);
|
406
|
echo json_encode($this->data);
|
407
|
}
|
408
|
//$this->data['group'] = '';
|
409
|
//$this->data['color'] = '';
|
410
|
//print_r($this->queryResult);return;
|
411
|
/*if($this->data['type'] == 'chart')
|
412
|
$this->createChartData();
|
413
|
else
|
414
|
$this->createScatterData();
|
415
|
$toreturn = array();
|
416
|
$toreturn['chart'] = $this->chart;
|
417
|
$toreturn['selectedData'] = $this->data;
|
418
|
echo json_encode($toreturn,JSON_NUMERIC_CHECK);*/
|
419
|
}
|
420
|
|
421
|
function defaultChart() {
|
422
|
//get the default values for this table
|
423
|
$temp = $this->database->getDefaultData($_GET['table']);
|
424
|
$this->queryResult = $temp['data'];
|
425
|
$this->data = $temp['selectedData'];
|
426
|
$this->data['group'] = '';
|
427
|
$this->data['color'] = 'no';
|
428
|
//print_r($this->queryResult);return;
|
429
|
if($temp['type'] == 'chart')
|
430
|
$this->createChartData($temp['type']);
|
431
|
else
|
432
|
$this->createScatterData('');
|
433
|
//$this->chart['chart']['type'] = $temp['type'];
|
434
|
//print_r($this->chart);return;
|
435
|
//print_r($this->data);
|
436
|
$toreturn = array();
|
437
|
$toreturn['chart'] = $this->chart;
|
438
|
$toreturn['selectedData'] = $this->data;
|
439
|
//return json_encode($toreturn,JSON_NUMERIC_CHECK);
|
440
|
return json_encode($toreturn);
|
441
|
}
|
442
|
|
443
|
function defaultChartSelections() {
|
444
|
//get the default values for this table
|
445
|
$temp = $this->database->getDefaultData($_GET['table']);
|
446
|
$this->queryResult = $temp['data'];
|
447
|
$this->data = $temp['selectedData'];
|
448
|
|
449
|
//echo json_encode($this->data,JSON_NUMERIC_CHECK);
|
450
|
echo json_encode($this->data);
|
451
|
}
|
452
|
|
453
|
function COM_getFilterData(){
|
454
|
if(!isset($_GET['table']) || !isset($_GET['field'])) {
|
455
|
echo 'empty';
|
456
|
}
|
457
|
else {
|
458
|
echo $this->computeFilterObject($_GET['table'],$_GET['field'],true);
|
459
|
}
|
460
|
}
|
461
|
|
462
|
function getFilterData($table, $field){
|
463
|
return $this->computeFilterObject($table,$field,false);
|
464
|
}
|
465
|
|
466
|
function computeFilterObject($table, $field, $encode){
|
467
|
$flds = explode("-",$field);
|
468
|
if(count($flds)>1){
|
469
|
$ctable = $flds[count($flds)-2];
|
470
|
$field = $flds[count($flds)-1];
|
471
|
}
|
472
|
else {
|
473
|
$ctable = $table;
|
474
|
$field = $field;
|
475
|
}
|
476
|
//call mydb function
|
477
|
if($encode)
|
478
|
//return json_encode($this->database->getFilterData($ctable,$field),JSON_NUMERIC_CHECK);
|
479
|
return json_encode($this->database->getFilterData($ctable,$field));
|
480
|
else
|
481
|
return $this->database->getFilterData($ctable,$field);
|
482
|
}
|
483
|
|
484
|
function COM_get_schema(){
|
485
|
$facts = $this->database->getFacts();
|
486
|
$dimensions = $this->database->getDimensions();
|
487
|
$response = array();
|
488
|
$menu = array();
|
489
|
if($facts === null) {
|
490
|
$this->log->error("there are no fact tables");
|
491
|
echo "empty";
|
492
|
return;
|
493
|
}//print_r($facts);
|
494
|
foreach($facts as $facttable){
|
495
|
$newfact = array();
|
496
|
$newfact['name'] = $facttable['name'];
|
497
|
if(!isset($facttable['meas'][0]))
|
498
|
$newfact['meas'][] = $facttable['meas'];
|
499
|
else
|
500
|
$newfact['meas'] = $facttable['meas'];
|
501
|
$newfact['dim'] = array();
|
502
|
//gia kathe dim theloume: name, type, data, kai attrib opou to attrib mporei na einai ki ayto dim
|
503
|
//otan pigainoume se bathos stin ierarxia twn diastasewn kratame touw progonous kai an ftasoume se diastasi pou yparxei stous progonous tin agnooume
|
504
|
foreach($facttable['dim'] as $curdim) {
|
505
|
$newdim = array();
|
506
|
$newdim['name'] = $curdim['name'];
|
507
|
$newdim['type'] = $curdim['type'];
|
508
|
//$newdim['data'] = $curdim['data'];//may not need it
|
509
|
if(isset($curdim['view']))
|
510
|
$newdim['view'] = $curdim['view'];
|
511
|
if(isset($curdim['dimtable']))
|
512
|
$newdim['dimtable'] = 'no';
|
513
|
else{
|
514
|
$newdim['dimtable'] = 'yes';
|
515
|
$newdim['attrib'] = array();
|
516
|
|
517
|
//need to find table $curdim['refer']['table'] from all the dimentions
|
518
|
$tabledim = search($dimensions, 'name', $curdim['name']);
|
519
|
//print_r($tabledim);
|
520
|
for($i=0;$i<count($tabledim);$i++){
|
521
|
if(isset($tabledim[$i]['type']) && $tabledim[$i]['type']=='dimension')
|
522
|
break;
|
523
|
}
|
524
|
$newdim['attrib'] = $this->makeAttrList($tabledim[$i]['attrib'],$dimensions,array($curdim['name']),$facttable['name']);
|
525
|
}
|
526
|
//I am interested in all the attributes of this dimension
|
527
|
array_push($newfact['dim'],$newdim);
|
528
|
}
|
529
|
array_push($menu,$newfact);
|
530
|
}
|
531
|
$response['name'] = $GLOBALS['db_name'];
|
532
|
$response['schema'] = $menu;
|
533
|
echo json_encode($response);
|
534
|
}
|
535
|
|
536
|
function makeAttrList($attrList, $dimensions, $ancestors,$facttable){
|
537
|
$newList = array();
|
538
|
if(is_array($attrList)) {
|
539
|
foreach($attrList as $attr) {
|
540
|
if($attr['name'] != 'id' && $attr['name']!=$facttable) {
|
541
|
$newAttr = array();
|
542
|
$newAttr['name'] = $attr['name'];
|
543
|
if(isset($newAttr['view']))
|
544
|
$newAttr['view'] = $attr['view'];
|
545
|
$newAttr['type'] = $attr['type'];
|
546
|
if(isset($attr['analysed']) && !in_array($attr['name'],$ancestors)){
|
547
|
|
548
|
$finddim = search($dimensions, 'name', $attr['name']);
|
549
|
$nextdim = search($finddim,'type','dimension');//print_r($nextdim);
|
550
|
$newnewList = $this->makeAttrList($nextdim[0]['attrib'],$dimensions, array_merge($ancestors,array($attr['name'])),$facttable);
|
551
|
$ancestors[] = $attr['name'];
|
552
|
$newAttr['analysed'] = $attr['name'];
|
553
|
$newAttr['attrib']= $newnewList;
|
554
|
}
|
555
|
else{
|
556
|
$newAttr['attrib']= array();
|
557
|
}
|
558
|
array_push($newList,$newAttr);
|
559
|
}
|
560
|
}
|
561
|
}
|
562
|
return $newList;
|
563
|
}
|
564
|
|
565
|
|
566
|
/*
|
567
|
type = color | group | ''
|
568
|
*/
|
569
|
function createScatterData(){
|
570
|
unset($this->chart['xAxis']['categories']);
|
571
|
$this->chart['chart']['type'] = 'bubble';
|
572
|
$xaxisindex = 0;
|
573
|
$yaxisindex = 1;
|
574
|
$left = 0;
|
575
|
$right = 0;
|
576
|
$fields = count($this->data['fields']);
|
577
|
$dimindex = 1+$fields;
|
578
|
if($this->data['group'] == '')
|
579
|
$this->chart['xAxis']['title']['text'] = $this->data['xaxis']['name'];
|
580
|
else
|
581
|
$this->chart['xAxis']['title']['text'] = $this->data['xaxis']['agg'].'('.$this->data['xaxis']['name'].')';
|
582
|
//arxikopoiisi
|
583
|
//posoi yaxis??
|
584
|
$this->chart['yAxis'] = array();
|
585
|
$yaxis = $this->data['fields'][$fields-1]['yaxis'];
|
586
|
$tempy = -1;
|
587
|
for($f=0;$f<count($this->data['fields']);$f++){
|
588
|
if($this->data['fields'][$f]['yaxis']!=$tempy+1){//new y
|
589
|
$tempy++;
|
590
|
$this->chart['yAxis'][$tempy] = array();
|
591
|
$this->chart['yAxis'][$tempy]['labels'] = array();
|
592
|
$this->chart['yAxis'][$tempy]['labels']['enabled'] = true;
|
593
|
$this->chart['yAxis'][$tempy]['labels']['overflow'] = 'justify';
|
594
|
//$this->chart['yAxis'][$tempy]['offset'] = 70;
|
595
|
$this->chart['yAxis'][$tempy]['title'] = array();
|
596
|
if($this->data['yaxisheaders'][$tempy] !=''){
|
597
|
$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['yaxisheaders'][$tempy];
|
598
|
}
|
599
|
else{
|
600
|
if($this->data['fieldsheaders'][$f] !=''){
|
601
|
$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['fieldsheaders'][$f];
|
602
|
}
|
603
|
else{
|
604
|
if($this->data['group'] == '')
|
605
|
$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['fields'][$f]['fld'];
|
606
|
else
|
607
|
$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['fields'][$f]['agg'].'('.$this->data['fields'][$f]['fld'].')';
|
608
|
}
|
609
|
}
|
610
|
if($right>=$left){
|
611
|
$left++;
|
612
|
}
|
613
|
else{
|
614
|
$right++;
|
615
|
$this->chart['yAxis'][$tempy]['opposite'] = true;
|
616
|
}
|
617
|
}
|
618
|
else if($this->data['yaxisheaders'][$tempy] == ""){//more in the name
|
619
|
if($this->data['fieldsheaders'][$f] !=''){
|
620
|
$this->chart['yAxis'][$tempy]['title']['text'] .= " / ".$this->data['fieldsheaders'][$f];
|
621
|
}
|
622
|
else{
|
623
|
if($this->data['group'] == '')
|
624
|
$this->chart['yAxis'][$tempy]['title']['text'] .= " / ".$this->data['fields'][$f]['fld'];
|
625
|
else
|
626
|
$this->chart['yAxis'][$tempy]['title']['text'] .= " / ".$this->data['fields'][$f]['agg'].'('.$this->data['fields'][$f]['fld'].')';
|
627
|
}
|
628
|
}
|
629
|
}
|
630
|
$this->chart['series'] = array();
|
631
|
$this->chart['legend']['enabled'] = false;
|
632
|
//an einai group exw ena series
|
633
|
if(($this->data['group'] && $this->data['group'] != '') || $this->data['color'] == ''){//ena series kai diaforetiko onoma gia kathe data
|
634
|
for($f=0;$f<$fields;$f++){
|
635
|
$this->chart['series'][$f] = array();
|
636
|
$this->chart['series'][$f]['data'] = array();
|
637
|
if($this->data['fields'][$f]['yaxis']!=1)
|
638
|
$this->chart['series'][$f]['yAxis'] = $this->data['fields'][$f]['yaxis']-1;
|
639
|
}
|
640
|
//for($line=0;$line<10;$line++){
|
641
|
for($line=0;$line<count($this->queryResult['data']);$line++){
|
642
|
for($f=0;$f<$fields;$f++){
|
643
|
//insert a new data object to the only series
|
644
|
$data = array();
|
645
|
$data['x'] = $this->queryResult['data'][$line][$xaxisindex];
|
646
|
$data['y'] = $this->queryResult['data'][$line][$yaxisindex+$f];
|
647
|
if($this->data['group'] != ''){
|
648
|
$data['name'] = $this->queryResult['data'][$line][$dimindex];
|
649
|
if($this->data['fieldsheaders'][$f]=="")
|
650
|
$this->chart['series'][$f]['name'] = $this->data['fields'][$f]['agg'].'('.$this->data['fields'][$f]['fld'].')';
|
651
|
else
|
652
|
$this->chart['series'][$f]['name'] = $this->data['fieldsheaders'][$f];
|
653
|
}
|
654
|
else{
|
655
|
if($this->data['fieldsheaders'][$f]=="")
|
656
|
$this->chart['series'][$f]['name'] = $this->data['fields'][$f]['fld'];
|
657
|
else
|
658
|
$this->chart['series'][$f]['name'] = $this->data['fieldsheaders'][$f];
|
659
|
}
|
660
|
$this->chart['series'][$f]['data'][] = $data;
|
661
|
}
|
662
|
}//print_r($this->chart['series']);
|
663
|
}
|
664
|
//an einai color exw ena series gia kathe timi tou dimindex
|
665
|
else{
|
666
|
$this->chart['legend']['enabled'] = true;
|
667
|
$curseries = '';
|
668
|
$seriescount = 0;
|
669
|
//for($line=0;$line<10;$line++){
|
670
|
for($line=0;$line<count($this->queryResult['data']);$line++){
|
671
|
if($this->queryResult['data'][$line][$dimindex] != $curseries){
|
672
|
$curseries = $this->queryResult['data'][$line][$dimindex];
|
673
|
for($f=0;$f<$fields;$f++){
|
674
|
$this->chart['series'][$seriescount+$f] = array();
|
675
|
if($this->data['fieldsheaders'][$f]!='')
|
676
|
$this->chart['series'][$seriescount+$f]['name'] = $this->data['fieldsheaders'][$f]." for ".$this->queryResult['data'][$line][$dimindex];
|
677
|
else
|
678
|
$this->chart['series'][$seriescount+$f]['name'] = $this->data['fields'][$f]['fld']." for ".$this->queryResult['data'][$line][$dimindex];
|
679
|
$this->chart['series'][$seriescount+$f]['data'] = array();
|
680
|
}
|
681
|
$seriescount += $fields;
|
682
|
}
|
683
|
for($f=0;$f<$fields;$f++){
|
684
|
$this->chart['series'][$seriescount-$fields+$f]['data'][] = array($this->queryResult['data'][$line][$xaxisindex],$this->queryResult['data'][$line][$yaxisindex+$f]);
|
685
|
}
|
686
|
}
|
687
|
}
|
688
|
|
689
|
}
|
690
|
|
691
|
function createChartData(){
|
692
|
$this->chart['xAxis']['categories'] = array();
|
693
|
unset($this->chart['chart']['type']);
|
694
|
$this->chart['series'] = array();
|
695
|
$this->chart['yAxis'] = array();
|
696
|
$xaxisindex = 0;
|
697
|
$yaxisindex = 1;
|
698
|
$left = 0;
|
699
|
$right = 0;
|
700
|
//print_r($this->queryResult['data']);
|
701
|
$fields = count($this->data['fields']);
|
702
|
$dimindex = 1+$fields;
|
703
|
if(isset($this->data['xaxistitle']))
|
704
|
//if($this->data['xaxistitle']!='')
|
705
|
$this->chart['xAxis']['title']['text'] = $this->data['xaxistitle'];
|
706
|
else{
|
707
|
$xaxis = explode("-",$this->data['xaxis']['name']);
|
708
|
$this->chart['xAxis']['title']['text'] = $xaxis[count($xaxis)-1];
|
709
|
}
|
710
|
$this->chart['legend']['enabled'] = true;
|
711
|
//posoi yaxis??
|
712
|
$yaxis = $this->data['fields'][$fields-1]['yaxis'];
|
713
|
$tempy = -1;
|
714
|
for($f=0;$f<count($this->data['fields']);$f++){
|
715
|
if($this->data['fields'][$f]['yaxis']!=$tempy+1){//new y
|
716
|
$tempy++;
|
717
|
$this->chart['yAxis'][$tempy] = array();
|
718
|
$this->chart['yAxis'][$tempy]['labels'] = array();
|
719
|
$this->chart['yAxis'][$tempy]['labels']['enabled'] = true;
|
720
|
$this->chart['yAxis'][$tempy]['labels']['overflow'] = 'justify';
|
721
|
$this->chart['yAxis'][$tempy]['min'] = 0;
|
722
|
//$this->chart['yAxis'][$tempy]['offset'] = 70;
|
723
|
$this->chart['yAxis'][$tempy]['title'] = array();
|
724
|
if($this->data['yaxisheaders'][$tempy]!=''){
|
725
|
$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['yaxisheaders'][$tempy];
|
726
|
if($this->data['fieldsheaders'][$f] == '' && (($f<count($this->data['fields'])-1 && $this->data['fields'][$f]['yaxis']!=$this->data['fields'][$f+1]['yaxis']) || $f==count($this->data['fields'])-1)){//the fields name is not set and it is the only field in the axis
|
727
|
$this->data['fieldsheaders'][$f] = $this->data['yaxisheaders'][$tempy];
|
728
|
}
|
729
|
}
|
730
|
else{
|
731
|
if($this->data['fieldsheaders'][$f] !=''){
|
732
|
$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['fieldsheaders'][$f];
|
733
|
}
|
734
|
else {
|
735
|
$this->chart['yAxis'][$tempy]['title']['text'] = $this->data['fields'][$f]['agg'].'('.$this->data['fields'][$f]['fld'].')';
|
736
|
}
|
737
|
}
|
738
|
if($right>=$left){
|
739
|
$left++;
|
740
|
}
|
741
|
else{
|
742
|
$right++;
|
743
|
$this->chart['yAxis'][$tempy]['opposite'] = true;
|
744
|
}
|
745
|
}
|
746
|
else if($this->data['yaxisheaders'][$tempy]==''){//more in the name
|
747
|
if($this->data['fieldsheaders'][$f] !='')
|
748
|
$this->chart['yAxis'][$tempy]['title']['text'] .= " / ".$this->data['fieldsheaders'][$f];
|
749
|
else
|
750
|
$this->chart['yAxis'][$tempy]['title']['text'] .= " / ".$this->data['fields'][$f]['agg'].'('.$this->data['fields'][$f]['fld'].')';
|
751
|
}
|
752
|
}
|
753
|
|
754
|
if($this->data['group'] != ''){//periptwsi analyze
|
755
|
$this->chartDataGroup();
|
756
|
}
|
757
|
else{//polloi yaxis xwris group
|
758
|
$this->chartDataMultiY();
|
759
|
}
|
760
|
|
761
|
if(count($this->chart['xAxis']['categories']) > 30){
|
762
|
$this->chart['xAxis']['labels']['formatter'] = 'trim';
|
763
|
//$this->chart['xAxis']['labels']['rotation'] = 90;
|
764
|
}//print_r($this->chart);
|
765
|
else{
|
766
|
$trimflag = false;
|
767
|
for($i=0;$i<count($this->chart['xAxis']['categories']);$i++){
|
768
|
if(is_string($this->chart['xAxis']['categories'][$i]) && strlen($this->chart['xAxis']['categories'][$i])>10){
|
769
|
$trimflag = true;
|
770
|
break;
|
771
|
}
|
772
|
}
|
773
|
if($trimflag){
|
774
|
$this->chart['xAxis']['labels']['formatter'] = 'cond-trim';
|
775
|
//$this->chart['xAxis']['labels']['rotation'] = 90;
|
776
|
}
|
777
|
}
|
778
|
}
|
779
|
|
780
|
function chartDataGroup(){
|
781
|
//ena series gia kathe field gia kathe timi tou groupdim
|
782
|
//read data
|
783
|
$res = $this->queryResult['data'];
|
784
|
$seriesindex = array();
|
785
|
$names = array();
|
786
|
$name = '';
|
787
|
$seriescount = 0;
|
788
|
$curseries = '';
|
789
|
$xaxisindex = 0;
|
790
|
$yaxisindex = 1;
|
791
|
$fields = count($this->data['fields']);
|
792
|
$dimindex = 1+$fields;
|
793
|
|
794
|
($this->size >= count($this->queryResult['data'])) ? $num=count($this->queryResult['data']) : $num=$this->size;
|
795
|
//$num = $this->size;
|
796
|
$flag = true;
|
797
|
for($line=0;$line<$num;$line++){
|
798
|
//list with x axis categories
|
799
|
if(!in_array($res[$line][$xaxisindex],$this->chart['xAxis']['categories'])){
|
800
|
if(count($this->chart['xAxis']['categories'])<$num){
|
801
|
$this->chart['xAxis']['categories'][] = $res[$line][$xaxisindex];
|
802
|
$flag = true;
|
803
|
}
|
804
|
else{
|
805
|
$flag = false;
|
806
|
}
|
807
|
}
|
808
|
else{
|
809
|
$flag = true;
|
810
|
}
|
811
|
if($flag){
|
812
|
//insert new data in currentseries or make new one
|
813
|
if($this->queryResult['data'][$line][$dimindex] != $curseries){
|
814
|
$curseries = $this->queryResult['data'][$line][$dimindex];
|
815
|
for($f=0;$f<$fields;$f++){
|
816
|
if($this->data['fieldsheaders'][$f]!="")
|
817
|
$names[$f] = $this->data['fieldsheaders'][$f] ." for ".$curseries;
|
818
|
else
|
819
|
$names[$f] = $curseries;
|
820
|
if(!isset($seriesindex[$names[$f]])){
|
821
|
$seriesindex[$names[$f]] = array();
|
822
|
$seriesindex[$names[$f]]['name'] = $names[$f];
|
823
|
if($this->data['fields'][$f]['type'] !='area')
|
824
|
$seriesindex[$names[$f]]['type'] = $this->data['fields'][$f]['type'];
|
825
|
else
|
826
|
$this->chart->type='area';
|
827
|
if($this->data['fields'][$f]['yaxis']>1){
|
828
|
$seriesindex[$names[$f]]['yAxis'] = $this->data['fields'][$f]['yaxis']-1;
|
829
|
}
|
830
|
$seriesindex[$names[$f]]['data'] = array();
|
831
|
if($curseries == "UNKNOWN")
|
832
|
$seriesindex[$names[$f]]['visible'] = false;
|
833
|
|
834
|
if(isset($this->data['fields'][$f]['c']) && $this->data['fields'][$f]['c'] == true)
|
835
|
$seriesindex[$names[$f]]['c'] = true;
|
836
|
else
|
837
|
$seriesindex[$names[$f]]['c'] = false;
|
838
|
}
|
839
|
}
|
840
|
$seriescount += $fields;
|
841
|
}
|
842
|
$index = array_search($this->queryResult['data'][$line][$xaxisindex],$this->chart['xAxis']['categories']);
|
843
|
for($f=0;$f<$fields;$f++){
|
844
|
if($this->data['fieldsheaders'][$f]!="")
|
845
|
$name = $this->data['fieldsheaders'][$f] . " for ".$curseries;
|
846
|
else
|
847
|
$name = $this->data['fields'][$f]['agg'].'('.$this->data['fields'][$f]['fld'].") for ".$curseries;
|
848
|
$lastindex = count($seriesindex[$name]['data']);
|
849
|
for($t=$lastindex;$t<$index;$t++){
|
850
|
$seriesindex[$name]['data'][$t] = 0;
|
851
|
}
|
852
|
$seriesindex[$name]['data'][$index] = $this->queryResult['data'][$line][$yaxisindex+$f];
|
853
|
}
|
854
|
}
|
855
|
}
|
856
|
foreach($seriesindex as $s){
|
857
|
$this->chart['series'][] = $s;
|
858
|
}
|
859
|
}
|
860
|
|
861
|
function chartDataMultiY(){
|
862
|
$xaxisindex = 0;
|
863
|
$yaxisindex = 1;
|
864
|
//1 series gia kathe field
|
865
|
for($i=0; $i<count($this->data['fields']);$i++){
|
866
|
$this->chart['series'][] = array();
|
867
|
if($this->data['fieldsheaders'][$i]!='')
|
868
|
$this->chart['series'][$i]['name'] = $this->data['fieldsheaders'][$i];
|
869
|
else
|
870
|
$this->chart['series'][$i]['name'] = $this->data['fields'][$i]['agg'].'('.$this->data['fields'][$i]['fld'].')';
|
871
|
if($this->data['fields'][$i]['type'] != 'area')
|
872
|
$this->chart['series'][$i]['type'] = $this->data['fields'][$i]['type'];
|
873
|
else
|
874
|
$this->chart->type='area';
|
875
|
//$this->chart['series'][$i]['yAxis'] = $this->data['fields'][$i]['yAxis'];
|
876
|
|
877
|
if($this->data['fields'][$i]['yaxis']>1){
|
878
|
$this->chart['series'][$i]['yAxis'] = $this->data['fields'][$i]['yaxis']-1;
|
879
|
}
|
880
|
$this->chart['series'][$i]['data'] = array();
|
881
|
}
|
882
|
//read data
|
883
|
$res = $this->queryResult['data'];
|
884
|
|
885
|
($this->size >= count($this->queryResult['data'])) ? $num=count($this->queryResult['data']) : $num=$this->size;
|
886
|
//$num = $this->size;
|
887
|
$flag = true;
|
888
|
for($line=0;$line<$num;$line++){
|
889
|
//list with x axis categories
|
890
|
if(!in_array($res[$line][$xaxisindex],$this->chart['xAxis']['categories'])){
|
891
|
if(count($this->chart['xAxis']['categories'])<$num){
|
892
|
$this->chart['xAxis']['categories'][] = $res[$line][$xaxisindex];
|
893
|
$flag = true;
|
894
|
}
|
895
|
else{
|
896
|
$flag = false;
|
897
|
}
|
898
|
}
|
899
|
else{
|
900
|
$flag = true;
|
901
|
}
|
902
|
//insert new data in each series
|
903
|
if($flag){
|
904
|
for($s=0;$s<count($this->data['fields']);$s++) {
|
905
|
if($this->data['fields'][$s]['type'] == 'pie'){
|
906
|
$this->chart['series'][$s]['data'][$line]['name'] = $res[$line][$xaxisindex];
|
907
|
$this->chart['series'][$s]['data'][$line]['y'] = $res[$line][$s+$yaxisindex];
|
908
|
}
|
909
|
else {
|
910
|
$this->chart['series'][$s]['data'][] = $res[$line][$s+$yaxisindex];
|
911
|
}
|
912
|
}
|
913
|
}
|
914
|
}
|
915
|
|
916
|
if(count($this->data['fields']) == 1)
|
917
|
$this->chart['legend']['enabled'] = false;
|
918
|
}
|
919
|
|
920
|
function COM_performQuery() {
|
921
|
|
922
|
if(!isset($_GET['query']) || $_GET['query'] == ''){
|
923
|
$this->log->error("no query string");
|
924
|
return;
|
925
|
}
|
926
|
|
927
|
|
928
|
if(isset($_GET['persistent']))
|
929
|
{ $persistent=$_GET['persistent'];
|
930
|
}
|
931
|
else
|
932
|
{
|
933
|
$persistent="true";
|
934
|
}
|
935
|
|
936
|
$query = urldecode($_GET['query']);
|
937
|
|
938
|
$this->log->info("performing query: ".$query);
|
939
|
|
940
|
$resp = json_encode($this->database->performQuery($query, $persistent)); //$this->log->info("response: ".$resp);
|
941
|
echo $resp;
|
942
|
}
|
943
|
|
944
|
function sortSeries() {
|
945
|
//exoume mia series gia kathe field
|
946
|
//prepei na broume ayti ti series kai me basi ayti na kanoume sort kai oles tis alles kai ta categories tou xaxis
|
947
|
$snum = 0;
|
948
|
for($snum=0;$snum<$this->data['fields'];$snum++){
|
949
|
if($this->data['fields'][$snum]['agg']."(".$this->data['fields'][$snum]['fld'].")" == $this->data['sort'])
|
950
|
break;
|
951
|
}
|
952
|
//kanw sort ayto to series diatirontas ta kleidia opws einai kai meta kanw sort tis ypoloipes me basi ti seira kleidiwn aytinis
|
953
|
if($this->data['order'] && $this->data['order'] == 'd'){
|
954
|
arsort($this->chart['series'][$snum]['data']);
|
955
|
}
|
956
|
else{
|
957
|
asort($this->chart['series'][$snum]['data']);
|
958
|
}
|
959
|
//ypoloipes
|
960
|
//categories
|
961
|
$tempordered = array() ;
|
962
|
foreach (array_keys($this->chart['xAxis']['categories']) as $key) {
|
963
|
$tempordered[$key] = $this->chart['xAxis']['categories'][$key] ;
|
964
|
}
|
965
|
$this->chart['xAxis']['categories'] = $tempordered;
|
966
|
|
967
|
for($i=0;$i<$this->data['fields'];$i++){
|
968
|
if($i!=$snum){
|
969
|
unset($tempordered);
|
970
|
$tempordered = array();
|
971
|
$myarray = $this->chart['series'][$i]['data'];
|
972
|
foreach (array_keys($myarray) as $key) {
|
973
|
$tempordered[$key] = $myarray[$key] ;
|
974
|
}
|
975
|
$this->chart['series'][$i]['data'] = $tempordered;
|
976
|
}
|
977
|
}
|
978
|
}
|
979
|
|
980
|
|
981
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
982
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
983
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
984
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
985
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
986
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
987
|
|
988
|
function COM_makeQuery() {
|
989
|
if(!isset($_GET['data'])){
|
990
|
$this->log->info("data param not set: ". print_r($_GET,true));
|
991
|
echo 'empty';
|
992
|
}
|
993
|
else {
|
994
|
$viztype = $_GET['type'];
|
995
|
$data = $_GET['data'];
|
996
|
$this->data = json_decode($data,true);
|
997
|
|
998
|
$cachedData = $this->data;
|
999
|
unset($cachedData['yaxisheaders']);
|
1000
|
unset($cachedData['fieldsheaders']);
|
1001
|
unset($cachedData['title']);
|
1002
|
unset($cachedData['subtitle']);
|
1003
|
unset($cachedData['xaxistitle']);
|
1004
|
unset($cachedData['theme']);
|
1005
|
unset($cachedData['xStyle']);
|
1006
|
|
1007
|
$this->size = $this->data['size'];
|
1008
|
|
1009
|
//TODO added persistent option
|
1010
|
$this->persistent= $_GET['persistent'];
|
1011
|
|
1012
|
echo $this->computeChartObject($viztype);
|
1013
|
}
|
1014
|
}
|
1015
|
|
1016
|
function COM_read() {
|
1017
|
if(!isset($_GET['facttable']) || !isset($_GET['dimensions']) || !isset($_GET['measures'])) {
|
1018
|
echo "empty";
|
1019
|
}
|
1020
|
|
1021
|
$dims = explode(';',$_GET['dimensions']);
|
1022
|
$meas = explode(';',$_GET['measures']);
|
1023
|
echo $this->readtest($dims, $meas, $_GET['facttable'],$_GET['aggregation']);
|
1024
|
|
1025
|
}
|
1026
|
|
1027
|
function COM_check_fact() {
|
1028
|
if(!isset($_GET['name'])) {
|
1029
|
echo "empty";
|
1030
|
}
|
1031
|
else{
|
1032
|
$res = $this->database->findTableType($_GET['name']);
|
1033
|
if($res == false) echo 'false';
|
1034
|
else echo $res;
|
1035
|
}
|
1036
|
}
|
1037
|
|
1038
|
function COM_list_of_dim_names() {
|
1039
|
$res = $this->database->getAllDims();
|
1040
|
if($res != false)
|
1041
|
echo json_encode($res);
|
1042
|
else
|
1043
|
echo "false";
|
1044
|
}
|
1045
|
|
1046
|
function COM_search_warehouse_by_dims() {
|
1047
|
if(!isset($_GET['dims'])) {
|
1048
|
echo 'empty';
|
1049
|
}
|
1050
|
else {
|
1051
|
$res = $this->database->searchWarehousebyDims(explode(';',$_GET['dims']));
|
1052
|
if($res == false) echo "false";
|
1053
|
else echo $res;
|
1054
|
}
|
1055
|
}
|
1056
|
|
1057
|
function COM_create_new_fact_table() {
|
1058
|
if(!isset($_GET['table']) || !isset($_GET['dims']) || !isset($_GET['meas'])) {
|
1059
|
echo 'empty';
|
1060
|
}
|
1061
|
else {
|
1062
|
//set up the list of dims
|
1063
|
$dims = explode(',',$_GET['dims']);
|
1064
|
//set up the list of meas
|
1065
|
$new_meas = rtrim($_GET['meas'],';');
|
1066
|
$meas = explode(';',$new_meas);
|
1067
|
//call the db function
|
1068
|
$res = $this->database->createNewFact($_GET['table'], $dims, $meas);
|
1069
|
if($res == false)
|
1070
|
echo 'false';
|
1071
|
else
|
1072
|
echo 'true';
|
1073
|
}
|
1074
|
}
|
1075
|
|
1076
|
function COM_list_of_fact_tables() {
|
1077
|
$res = json_encode($this->database->getFactsNames());
|
1078
|
if($res == null)
|
1079
|
echo 'null';
|
1080
|
else
|
1081
|
echo $res;
|
1082
|
}
|
1083
|
|
1084
|
function COM_list_of_meas() {
|
1085
|
if(!isset($_GET['table'])) {
|
1086
|
echo 'empty';
|
1087
|
}
|
1088
|
else {
|
1089
|
$res = $this->database->findMeas($this->database->findTable($_GET['table'],'fact'));
|
1090
|
if($res == false)
|
1091
|
echo 'false';
|
1092
|
else
|
1093
|
echo json_encode($res);
|
1094
|
}
|
1095
|
}
|
1096
|
|
1097
|
function COM_list_of_dims() {
|
1098
|
$res = $this->database->getDims();
|
1099
|
if($res == false)
|
1100
|
echo 'false';
|
1101
|
else
|
1102
|
echo json_encode($res);
|
1103
|
}
|
1104
|
|
1105
|
function COM_del_meas() {
|
1106
|
if(!isset($_GET['facttable']) || !isset($_GET['name'])) {
|
1107
|
echo "empty";
|
1108
|
}
|
1109
|
else {
|
1110
|
$res = $this->database->delMeas($_GET['facttable'], $_GET['name']);
|
1111
|
if($res == true)
|
1112
|
echo "true";
|
1113
|
else
|
1114
|
echo "false";
|
1115
|
}
|
1116
|
}
|
1117
|
|
1118
|
function COM_add_meas() {
|
1119
|
if(!isset($_GET['facttable']) || !isset($_GET['name']) || !isset($_GET['formal_name']) || !isset($_GET['type'])) {
|
1120
|
echo "empty";
|
1121
|
}
|
1122
|
else {
|
1123
|
$res = $this->database->addMeas($_GET['facttable'], $_GET['name'], $_GET['formal_name'], $_GET['type']);
|
1124
|
if($res == true)
|
1125
|
echo "true";
|
1126
|
else
|
1127
|
echo "false";
|
1128
|
}
|
1129
|
}
|
1130
|
|
1131
|
function COM_meas_range_data() {
|
1132
|
if(!isset($_GET['facttable']) || !isset($_GET['measurement'])) {
|
1133
|
echo "empty";
|
1134
|
}
|
1135
|
else {
|
1136
|
$res = $this->database->measRangeData($_GET['facttable'],$_GET['measurement']);
|
1137
|
echo json_encode($res);
|
1138
|
}
|
1139
|
}
|
1140
|
|
1141
|
function COM_get_dims_fields_list(){
|
1142
|
if(!isset($_GET['table'])) {
|
1143
|
echo "empty";
|
1144
|
}
|
1145
|
else {
|
1146
|
$res = $this->database->getDimsList($_GET['table']);
|
1147
|
|
1148
|
if($res == false)
|
1149
|
echo "false";
|
1150
|
else if($res == null)
|
1151
|
echo "null";
|
1152
|
else
|
1153
|
echo json_encode($res);
|
1154
|
}
|
1155
|
}
|
1156
|
|
1157
|
|
1158
|
function fetchData($table, $dim1, $dim2, $meas, $constraints = null) {
|
1159
|
return $this->database->getJsonData($table, $dim1, $dim2, $meas, $constraints);
|
1160
|
}
|
1161
|
|
1162
|
function readData($table, $dim1, $dim2, $meas, $constraints = null) {
|
1163
|
return $this->database->readData($table, $dim1, $dim2, $meas, $constraints);
|
1164
|
}
|
1165
|
|
1166
|
function timeload($start,$end) {
|
1167
|
$this->database->loadTime($start,$end);
|
1168
|
}
|
1169
|
|
1170
|
function readtest($dimensions,$measures,$table,$aggr) {
|
1171
|
$data = $this->database->readtest($dimensions,$measures,$table,$aggr);
|
1172
|
//echo json_encode($data,JSON_NUMERIC_CHECK);
|
1173
|
echo json_encode($data);
|
1174
|
}
|
1175
|
|
1176
|
|
1177
|
/////////////////////////////////////////////////////////////////////////////////////
|
1178
|
|
1179
|
}
|
1180
|
|
1181
|
/*
|
1182
|
|
1183
|
function createChartDataGroup($givenType) {
|
1184
|
//exoume anagkastika ena mono yaxis
|
1185
|
//ena series gia kathe diaforetiki timi tou tritou pediou
|
1186
|
if($givenType == 'chart'){
|
1187
|
$this->chart['xAxis']['categories'] = array();
|
1188
|
|
1189
|
}
|
1190
|
else{
|
1191
|
unset($this->chart['xAxis']['categories']);
|
1192
|
}
|
1193
|
$this->chart['series'] = array();
|
1194
|
|
1195
|
$currentSeries = "";
|
1196
|
$seriesCnt = -1;
|
1197
|
$numOfColumns = count($this->queryResult[0]);
|
1198
|
if(count($this->data['series']) == 0)
|
1199
|
$sNameIndex = -1;
|
1200
|
else
|
1201
|
$sNameIndex = count($this->data['fields']) +1;
|
1202
|
//$sNameIndex = $numOfColumns-1;
|
1203
|
$xaxisIndex = 0;
|
1204
|
$fStartindex = 1;
|
1205
|
$groupindex = 2;
|
1206
|
$this->chart['xAxis']['title']['text'] = $this->data['xaxis']['name'];
|
1207
|
//arxikopoiisi
|
1208
|
$this->chart['yAxis'] = array();
|
1209
|
$this->chart['series'] = array();
|
1210
|
$this->chart['legend']['enabled'] = false;
|
1211
|
//edw tha ektelestei mono mia fora <-------NA TO ALLAKSW
|
1212
|
for($i=0; $i<count($this->data['fields']);$i++){
|
1213
|
//gia kathe field, exoume enan yaxis kai ena series
|
1214
|
$this->chart['yAxis'][] = array();
|
1215
|
$this->chart['yAxis'][$i]['labels'] = array();
|
1216
|
$this->chart['yAxis'][$i]['offset'] = 70;
|
1217
|
//$this->chart['yAxis'][$i]['labels']['formatter'] = 'simple';
|
1218
|
$this->chart['yAxis'][$i]['title'] = array();
|
1219
|
$this->chart['yAxis'][$i]['title']['text'] = $this->data['fields'][$i]['fld'];
|
1220
|
if($i>0){
|
1221
|
$this->chart['yAxis'][$i]['opposite'] = true;
|
1222
|
$this->chart['yAxis'][$i]['gridLineWidth'] = 0;
|
1223
|
}
|
1224
|
|
1225
|
//$this->chart['series'][] = array();
|
1226
|
//$this->chart['series'][$i]['name'] = $this->data['fields'][$i]['fld'];
|
1227
|
|
1228
|
//if($i>0) {
|
1229
|
// $this->chart['series'][$i]['yAxis'] = $i;
|
1230
|
//}
|
1231
|
//$this->chart['series'][$i]['data'] = array();
|
1232
|
//$seriesData[$i] = array();
|
1233
|
}
|
1234
|
|
1235
|
$res = $this->queryResult['data'];
|
1236
|
//gia kathe diaforetiki timi tou pediou 2, kainourgio category an exoume chart
|
1237
|
//gia kathe diaforetiki timi tou pediou 3, kainourgio series me onoma tin timi tou pediou 3
|
1238
|
//oso eisai sto idio series, apla prosthese ta data
|
1239
|
//an allakseis ftiakse kainourgio
|
1240
|
for($line=0;$line<count($this->queryResult['data']);$line++){
|
1241
|
//list with x axis categories
|
1242
|
if($givenType == 'chart'){
|
1243
|
if(!in_array($res[$line][$xaxisIndex],$this->chart['xAxis']['categories'])){
|
1244
|
$this->chart['xAxis']['categories'][] = $res[$line][$xaxisIndex];
|
1245
|
}
|
1246
|
}
|
1247
|
//new series?
|
1248
|
if($res[$line][$groupindex] != $currentSeries){
|
1249
|
$currentSeries = $res[$line][$groupindex];
|
1250
|
$this->chart['series'][] = array();
|
1251
|
$seriesCnt++;
|
1252
|
$this->chart['series'][$seriesCnt]['name'] = $currentSeries;
|
1253
|
$this->chart['series'][$seriesCnt]['data'] = array();
|
1254
|
}
|
1255
|
$this->chart['series'][$seriesCnt]['data'][] = $res[$line][$fStartindex];
|
1256
|
}
|
1257
|
|
1258
|
if(count($this->chart['xAxis']['categories']) > 15){
|
1259
|
$this->chart['xAxis']['labels']['formatter'] = 'trim';
|
1260
|
$this->chart['xAxis']['labels']['rotation'] = 45;
|
1261
|
}
|
1262
|
|
1263
|
}
|
1264
|
*/
|
1265
|
?>
|