Revision 38202
Added by Eri Katsari over 9 years ago
modules/uoa-stats/branches/beta/statsServer/backupCache.php | ||
---|---|---|
62 | 62 |
{ |
63 | 63 |
$query = $this->cache->hget($keys[$x],'query'); |
64 | 64 |
$persistent= $this->cache->hget($keys[$x],'persistent'); |
65 |
if(($query!=null)&&($persistent))
|
|
65 |
if($query!=null)
|
|
66 | 66 |
{ $this->log->info("going tobackup the results for query ".$query ); |
67 | 67 |
$fetchMode = $this->cache->hget($keys[$x], 'fetchMode'); |
68 | 68 |
if($fetchMode==null){ $fetchMode=3; } |
modules/uoa-stats/branches/beta/statsServer/promoteCharts.php | ||
---|---|---|
57 | 57 |
{ |
58 | 58 |
$query = $this->cache->hget($keys[$x],'query'); |
59 | 59 |
$persistent= $this->cache->hget($keys[$x],'persistent'); |
60 |
if(($query!=null)&&($persistent)) |
|
61 |
|
|
62 |
{ $this->log->info("going to replace the results for key: ".$keys[$x]." : \n ".$query."\n"); |
|
60 |
if($query!=null) |
|
61 |
{ $this->log->info("going to replace the results for key: ".$keys[$x]." : \n ".$query."\n"); |
|
63 | 62 |
$fetchMode = $this->cache->hget($keys[$x], 'fetchMode'); |
64 | 63 |
$shadowResults = $this->cache->hget($keys[$x],'shadow'); |
65 | 64 |
$result = $this->cache->hget($keys[$x], 'results'); |
modules/uoa-stats/branches/beta/statsServer/datasource.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
//#ob_start("ob_gzhandler"); |
|
4 |
|
|
5 |
require_once('controller.php'); |
|
6 |
require_once("./js/gdatasource/vistable.php"); |
|
7 |
|
|
8 |
$tqx = isset($_GET['tqx']) ? $_GET['tqx'] : ""; |
|
9 |
$tq = isset($_GET['tq']) ? $_GET['tq'] : ""; |
|
10 |
$tqrt = isset($_GET['tqrt']) ? $_GET['tqrt'] : ""; |
|
11 |
$tz = isset($_GET['tz']) ? $_GET['tz'] : "PDT"; |
|
12 |
$locale = isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) ? $_SERVER["HTTP_ACCEPT_LANGUAGE"] : "en_US"; |
|
13 |
|
|
14 |
if (isset($_GET['locale'])) { |
|
15 |
$locale = $_GET['locale']; |
|
16 |
} |
|
17 |
|
|
18 |
$extra = array(); |
|
19 |
if (isset($_GET['debug']) && $_GET['debug']) { |
|
20 |
header('Content-type: text/plain; charset="UTF-8"'); |
|
21 |
$extra['debug'] = 1; |
|
22 |
} |
|
23 |
|
|
24 |
$controller = new Controller(false); |
|
25 |
|
|
26 |
if(isset($_GET['com'])) { |
|
27 |
//analoga me to command kalei tin katallili synanrtisi |
|
28 |
if($_GET['com'] == "query") { |
|
29 |
$selectedData = json_decode($_GET['data'],true); |
|
30 |
$resp = $controller->makeQuery('table'); |
|
31 |
$resp = json_decode($resp,true); |
|
32 |
//make the header row |
|
33 |
$header = array(); |
|
34 |
if($selectedData['xaxistitle'] && $selectedData['xaxistitle'] !='') |
|
35 |
$header[] = $selectedData['xaxistitle']; |
|
36 |
else{ |
|
37 |
$temp = explode("-",$selectedData['xaxis']['name']); |
|
38 |
$header[] = $temp[count($temp)-1]; |
|
39 |
} |
|
40 |
|
|
41 |
for($i=0;$i<count($selectedData['fields']);$i++){ |
|
42 |
if(isset($selectedData['fieldsheaders']) && isset($selectedData['fieldsheaders'][$i]) && $selectedData['fieldsheaders'][$i]!=''){ |
|
43 |
$header[] = $selectedData['fieldsheaders'][$i]; |
|
44 |
} |
|
45 |
else{ |
|
46 |
$temp = explode("-",$selectedData['fields'][$i]['fld']); |
|
47 |
if($selectedData['fields'][$i]['agg'] != '') |
|
48 |
$header[] = $selectedData['fields'][$i]['agg']." of ".$temp[count($temp)-1]; |
|
49 |
else |
|
50 |
$header[] = $temp[count($temp)-1]; |
|
51 |
} |
|
52 |
} |
|
53 |
if($selectedData['group']!='' && $selectedData['group'] !='no'){ |
|
54 |
$temp = explode("-",$selectedData['group']); |
|
55 |
$header[] = $temp[count($temp)-1]; |
|
56 |
} |
|
57 |
|
|
58 |
for($i=0;$i<count($header);$i++){ |
|
59 |
//print_r($resp['data'][0][$i]); |
|
60 |
if(is_numeric($resp['data'][0][$i])) |
|
61 |
$header[$i] .= " as number"; |
|
62 |
} |
|
63 |
|
|
64 |
$tempdata = array(); |
|
65 |
$tempdata[] = implode(",",$header); |
|
66 |
for($l=1;$l<count($resp['data']);$l++){ |
|
67 |
$tempdata[] = implode(",",$resp['data'][$l]); |
|
68 |
} |
|
69 |
$data = implode("\n",$tempdata); |
|
70 |
//echo $data; |
|
71 |
/*$file = '../data/data.csv'; |
|
72 |
$data = file_get_contents($file); |
|
73 |
if ($file === FALSE) { |
|
74 |
die("Couldnt read `$file'"); |
|
75 |
}*/ |
|
76 |
|
|
77 |
|
|
78 |
$vt = new csv_vistable($tqx, $tq, $tqrt,$tz,$locale,$extra); |
|
79 |
|
|
80 |
$vt->setup_table($data); |
|
81 |
|
|
82 |
$result = $vt->execute(); |
|
83 |
|
|
84 |
echo $result; |
|
85 |
} |
|
86 |
else{ |
|
87 |
die("unknown command code"); |
|
88 |
} |
|
89 |
} |
|
90 |
else { |
|
91 |
//oops error |
|
92 |
die("no command given"); |
|
93 |
} |
|
94 |
//#ob_end_flush(); |
|
95 |
?> |
|
1 |
<?php |
|
2 |
|
|
3 |
//#ob_start("ob_gzhandler"); |
|
4 |
|
|
5 |
require_once('controller.php'); |
|
6 |
require_once("./js/gdatasource/vistable.php"); |
|
7 |
|
|
8 |
$tqx = isset($_GET['tqx']) ? $_GET['tqx'] : ""; |
|
9 |
$tq = isset($_GET['tq']) ? $_GET['tq'] : ""; |
|
10 |
$tqrt = isset($_GET['tqrt']) ? $_GET['tqrt'] : ""; |
|
11 |
$tz = isset($_GET['tz']) ? $_GET['tz'] : "PDT"; |
|
12 |
$locale = isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) ? $_SERVER["HTTP_ACCEPT_LANGUAGE"] : "en_US"; |
|
13 |
|
|
14 |
if (isset($_GET['locale'])) { |
|
15 |
$locale = $_GET['locale']; |
|
16 |
} |
|
17 |
|
|
18 |
$extra = array(); |
|
19 |
if (isset($_GET['debug']) && $_GET['debug']) { |
|
20 |
header('Content-type: text/plain; charset="UTF-8"'); |
|
21 |
$extra['debug'] = 1; |
|
22 |
} |
|
23 |
|
|
24 |
$controller = new Controller(false); |
|
25 |
$persistent="true"; |
|
26 |
|
|
27 |
if(isset($_GET['com'])) { |
|
28 |
//analoga me to command kalei tin katallili synanrtisi |
|
29 |
if($_GET['com'] == "query") { |
|
30 |
$selectedData = json_decode($_GET['data'],true); |
|
31 |
|
|
32 |
if(!isset($_GET['persistent'])) |
|
33 |
{ $persistent="true"; |
|
34 |
}else{$persistent="false";} |
|
35 |
|
|
36 |
|
|
37 |
$resp = $controller->makeQuery('table',$persistent); |
|
38 |
$resp = json_decode($resp,true); |
|
39 |
//make the header row |
|
40 |
$header = array(); |
|
41 |
if($selectedData['xaxistitle'] && $selectedData['xaxistitle'] !='') |
|
42 |
$header[] = $selectedData['xaxistitle']; |
|
43 |
else{ |
|
44 |
$temp = explode("-",$selectedData['xaxis']['name']); |
|
45 |
$header[] = $temp[count($temp)-1]; |
|
46 |
} |
|
47 |
|
|
48 |
for($i=0;$i<count($selectedData['fields']);$i++){ |
|
49 |
if(isset($selectedData['fieldsheaders']) && isset($selectedData['fieldsheaders'][$i]) && $selectedData['fieldsheaders'][$i]!=''){ |
|
50 |
$header[] = $selectedData['fieldsheaders'][$i]; |
|
51 |
} |
|
52 |
else{ |
|
53 |
$temp = explode("-",$selectedData['fields'][$i]['fld']); |
|
54 |
if($selectedData['fields'][$i]['agg'] != '') |
|
55 |
$header[] = $selectedData['fields'][$i]['agg']." of ".$temp[count($temp)-1]; |
|
56 |
else |
|
57 |
$header[] = $temp[count($temp)-1]; |
|
58 |
} |
|
59 |
} |
|
60 |
if($selectedData['group']!='' && $selectedData['group'] !='no'){ |
|
61 |
$temp = explode("-",$selectedData['group']); |
|
62 |
$header[] = $temp[count($temp)-1]; |
|
63 |
} |
|
64 |
|
|
65 |
for($i=0;$i<count($header);$i++){ |
|
66 |
//print_r($resp['data'][0][$i]); |
|
67 |
if(is_numeric($resp['data'][0][$i])) |
|
68 |
$header[$i] .= " as number"; |
|
69 |
} |
|
70 |
|
|
71 |
$tempdata = array(); |
|
72 |
$tempdata[] = implode(",",$header); |
|
73 |
for($l=1;$l<count($resp['data']);$l++){ |
|
74 |
$tempdata[] = implode(",",$resp['data'][$l]); |
|
75 |
} |
|
76 |
$data = implode("\n",$tempdata); |
|
77 |
//echo $data; |
|
78 |
/*$file = '../data/data.csv'; |
|
79 |
$data = file_get_contents($file); |
|
80 |
if ($file === FALSE) { |
|
81 |
die("Couldnt read `$file'"); |
|
82 |
}*/ |
|
83 |
|
|
84 |
|
|
85 |
$vt = new csv_vistable($tqx, $tq, $tqrt,$tz,$locale,$extra); |
|
86 |
|
|
87 |
$vt->setup_table($data); |
|
88 |
|
|
89 |
$result = $vt->execute(); |
|
90 |
|
|
91 |
echo $result; |
|
92 |
} |
|
93 |
else{ |
|
94 |
die("unknown command code"); |
|
95 |
} |
|
96 |
} |
|
97 |
else { |
|
98 |
//oops error |
|
99 |
die("no command given"); |
|
100 |
} |
|
101 |
//#ob_end_flush(); |
|
102 |
?> |
modules/uoa-stats/branches/beta/statsServer/MYDB.php | ||
---|---|---|
30 | 30 |
global $redis_host; |
31 | 31 |
global $redis_port; |
32 | 32 |
global $redis_scheme; |
33 |
|
|
34 |
//error_reporting(E_ERROR | E_WARNING | E_PARSE);
|
|
33 |
|
|
34 |
// this creates a logger named "MYDB"
|
|
35 | 35 |
$this->log = Logger::getLogger(__CLASS__); |
36 | 36 |
|
37 | 37 |
if(class_exists("Predis\Client")){ |
... | ... | |
131 | 131 |
|
132 | 132 |
//TODO here predis cache is checked and the query is submitted to the DB |
133 | 133 |
|
134 |
function doQuery($query, $fetchMode=PDO::FETCH_BOTH){ |
|
134 |
function doQuery($query, $fetchMode=PDO::FETCH_BOTH,$persistent){
|
|
135 | 135 |
|
136 | 136 |
if($this->cache != null){ |
137 | 137 |
//TODO md5($query) -> REDIS hash set keys |
... | ... | |
149 | 149 |
$results = $this->doQueryNoCache($query, $fetchMode); |
150 | 150 |
$this->log->info("adding in cache. key: ".$myKey); |
151 | 151 |
|
152 |
if(isset($_GET['persistent'])) |
|
153 |
$persistent = $_GET['persistent']; |
|
154 |
else |
|
155 |
$persistent = true; //default value is true if not provided |
|
156 |
|
|
152 |
if($persistent==null||$persistent=='1') |
|
153 |
{$persistent = "true";} |
|
157 | 154 |
if(($this->cache->hmset($myKey, array("query" => $query, "results" => json_encode($results), "persistent" => $persistent, "fetchMode" => $fetchMode))) == false) { |
158 | 155 |
$this->log->info("adding key ".$myKey." in cache failed."); //predis |
159 | 156 |
} else |
... | ... | |
214 | 211 |
} |
215 | 212 |
|
216 | 213 |
public function getFacts() { |
217 |
$list = $this->doQuery("select tableName from defaults order by tableorder"); |
|
214 |
$list = $this->doQuery("select tableName from defaults order by tableorder","false");
|
|
218 | 215 |
if($list != null){ |
219 | 216 |
$sorted = array(); |
220 | 217 |
if(isset($this->facts)) { |
... | ... | |
455 | 452 |
//if there is a meas with the same name |
456 | 453 |
foreach($this->facts as $table) |
457 | 454 |
if($table['name'] == $fact) |
458 |
foreach($table['meas'] as $meas) { |
|
459 |
if($meas['name'] == $meas_name){ |
|
460 |
return true; |
|
455 |
foreach($table['meas'] as $meas) { |
|
456 |
|
|
457 |
if($meas== $meas_name) |
|
458 |
{ return true; |
|
461 | 459 |
} |
462 | 460 |
} |
463 | 461 |
return false; |
... | ... | |
633 | 631 |
$query = 'select * from "defaults" where tableorder=(select min(tableorder) from "defaults")'; |
634 | 632 |
} |
635 | 633 |
$this->log->info("DefaultData -> query created: ".$query); |
636 |
$res = $this->doQuery($query); |
|
634 |
$res = $this->doQuery($query,"false");
|
|
637 | 635 |
if($res == null) |
638 | 636 |
return "empty"; |
639 | 637 |
|
... | ... | |
686 | 684 |
ok group by: to xaxis kai ola ta series opws akribws kai sto select |
687 | 685 |
ok order by: to xaxis |
688 | 686 |
*/ |
689 |
function makeQueryGroup($sel){//print_r($sel); |
|
687 |
function makeQueryGroup($sel,$persistent){//print_r($sel);
|
|
690 | 688 |
$this->log->info("makeQueryGroup"); |
691 | 689 |
/* |
692 | 690 |
select agg(field), xaxisfield, groupfield |
... | ... | |
823 | 821 |
} |
824 | 822 |
$query .= " order by ".$groupfield.", ".$xaxisfield; |
825 | 823 |
$this->log->info("generated query: ".$query); |
826 |
$res = $this->doQuery($query, PDO::FETCH_NUM); |
|
824 |
$res = $this->doQuery($query, PDO::FETCH_NUM,$persistent);
|
|
827 | 825 |
if($isMeas) $returnType = 'scatter'; |
828 | 826 |
else $returnType = 'chart'; |
829 | 827 |
return array('type'=>$returnType,'data'=>$res,'accomDims'=>$dimsList['fields']); |
830 | 828 |
} |
831 | 829 |
|
832 |
function getData($sel){ |
|
830 |
function getData($sel,$persistent){
|
|
833 | 831 |
$this->log->info("getting data"); |
834 | 832 |
$xaxislist = explode("-",$sel['xaxis']['name']); |
835 | 833 |
$groups = array(); |
836 | 834 |
$brsels = array(); $queries = array(); |
837 | 835 |
$breakflag = false; |
838 |
//check if we need to break the query to many (if there are filters that apply to only one field) |
|
836 |
|
|
837 |
|
|
838 |
|
|
839 |
//check if we need to break the query to many (if there are filters that apply to only one field) |
|
839 | 840 |
if(count($sel['fields']) > 1){ |
840 | 841 |
for($i=0;$i<count($sel['filters']);$i++) |
841 | 842 |
if(isset($sel['filters'][$i]['to']) && $sel['filters'][$i]['to'] != -1){ |
... | ... | |
857 | 858 |
if($this->checkMeas($sel['table'], $xaxislist[count($xaxislist)-1])) |
858 | 859 |
$queries[] = $this->scatterData($brsels[0],false); |
859 | 860 |
else |
860 |
$queries[] = $this->chartData($brsels[0],false); |
|
861 |
$queries[] = $this->chartData($brsels[0],false,$persistent);
|
|
861 | 862 |
for($i=0;$i<count($groups);$i++){ |
862 | 863 |
$brsels[] = $this->clearselections($sel,$groups,$groups[$i],$i+1); |
863 | 864 |
|
864 | 865 |
if($this->checkMeas($sel['table'], $xaxislist[count($xaxislist)-1])) |
865 | 866 |
$queries[] = $this->scatterData($brsels[$i+1],false); |
866 | 867 |
else |
867 |
$queries[] = $this->chartData($brsels[$i+1],false); |
|
868 |
$queries[] = $this->chartData($brsels[$i+1],false,$persistent);
|
|
868 | 869 |
} |
869 | 870 |
|
870 | 871 |
$this->log->info("selections: ".print_r($brsels,true)); |
... | ... | |
872 | 873 |
$this->log->info("queries: ".print_r($queries,true)); |
873 | 874 |
//get all the queries and combine them to one |
874 | 875 |
if($this->checkMeas($sel['table'], $xaxislist[count($xaxislist)-1])) |
875 |
return $this->makeSuperQuery($queries,$sel,"scatter"); |
|
876 |
return $this->makeSuperQuery($queries,$sel,"scatter",$persistent);
|
|
876 | 877 |
else |
877 |
return $this->makeSuperQuery($queries,$sel,"chart"); |
|
878 |
return $this->makeSuperQuery($queries,$sel,"chart",$persistent);
|
|
878 | 879 |
} |
879 | 880 |
else{ |
880 | 881 |
$this->log->info("NO NEED TO BREAK!"); |
881 | 882 |
if($this->checkMeas($sel['table'], $xaxislist[count($xaxislist)-1])) |
882 |
return $this->scatterData($sel); |
|
883 |
return $this->scatterData($sel,$persistent);
|
|
883 | 884 |
else |
884 |
return $this->chartData($sel); |
|
885 |
return $this->chartData($sel,true,$persistent);
|
|
885 | 886 |
} |
886 | 887 |
} |
887 | 888 |
|
888 |
private function makeSuperQuery($queries,$sel,$type){ |
|
889 |
private function makeSuperQuery($queries,$sel,$type,$persistent){
|
|
889 | 890 |
$superquerySelects = "SELECT "; |
890 | 891 |
$superquerySelecte = " "; |
891 | 892 |
$superqueryFrom = " FROM "; |
... | ... | |
941 | 942 |
|
942 | 943 |
$superQuery = $superquerySelects.$superquerySelecte.$superqueryFrom.$superquerySort." LIMIT ".$sel['size']; |
943 | 944 |
$this->log->info("superquery: ".$superQuery); |
944 |
$res = $this->doQuery($superQuery, PDO::FETCH_NUM); |
|
945 |
$res = $this->doQuery($superQuery, PDO::FETCH_NUM,$persistent);
|
|
945 | 946 |
return $this->combineData($res,count($queries),count($sel['fields']),$type); |
946 | 947 |
} |
947 | 948 |
|
... | ... | |
1032 | 1033 |
return $newsel; |
1033 | 1034 |
} |
1034 | 1035 |
|
1035 |
function chartData($sel, $doquery=true){ |
|
1036 |
function chartData($sel, $doquery=true,$persistent){
|
|
1036 | 1037 |
if($sel['group']!='' && $sel['group'] != 'no'){ //group |
1037 | 1038 |
return $this->chartDataGroup($sel, $doquery); |
1038 | 1039 |
} |
... | ... | |
1043 | 1044 |
$tree->updateXAxis($sel['xaxis']['name']); |
1044 | 1045 |
$tree->updateYAxis($sel['fields']); |
1045 | 1046 |
$tree->updateFilters($sel['filters']); |
1046 |
if (isset($sel['sort'])) { |
|
1047 |
$tree->updateOrderBy($sel['sort']);} |
|
1048 |
|
|
1049 |
if(isset($sel['order'])){$tree->updateOrder($sel['order']);} |
|
1047 |
if (isset($sel['sort'])) {$tree->updateOrderBy($sel['sort']);} |
|
1048 |
if(isset($sel['order'])){$tree->updateOrder($sel['order']);} |
|
1050 | 1049 |
if(isset($sel['size'])){$tree->updateLimit($sel['size']);} |
1051 |
if(isset($sel['nulls'])){ $tree->excludeNulls($sel['nulls']);}
|
|
1050 |
if(isset($sel['nulls'])){$tree->excludeNulls($sel['nulls']);} |
|
1052 | 1051 |
|
1053 |
//$this->log->info("tree: ".print_r($tree->tree, true));
|
|
1052 |
$this->log->info("tree: ".print_r($tree->tree, true)); |
|
1054 | 1053 |
|
1055 | 1054 |
$query = $tree->getQuery(); |
1056 | 1055 |
|
1057 | 1056 |
if(!$doquery){ |
1058 |
// $this->log->info('chartData generated query:'.$query);
|
|
1059 |
// $this->log->info('will not execute it');
|
|
1057 |
$this->log->info('chartData generated query:'.$query); |
|
1058 |
$this->log->info('will not execute it'); |
|
1060 | 1059 |
return $query; |
1061 | 1060 |
} |
1062 | 1061 |
|
1063 |
// $this->log->info('chartData generated tree: '.print_r($tree->getTree(), true));
|
|
1064 |
// $this->log->info('chartData generated query: '.$query);
|
|
1065 |
$res = $this->doQuery($query, PDO::FETCH_NUM); |
|
1066 |
// $this->log->info("result: ".print_r($res,true));
|
|
1062 |
$this->log->info('chartData generated tree: '.print_r($tree->getTree(), true)); |
|
1063 |
$this->log->info('chartData generated query: '.$query); |
|
1064 |
$res = $this->doQuery($query, PDO::FETCH_NUM,$persistent);
|
|
1065 |
$this->log->info("result: ".print_r($res,true)); |
|
1067 | 1066 |
return array('type'=>'chart','data'=>$res); |
1068 | 1067 |
} |
1069 | 1068 |
|
1070 | 1069 |
} |
1071 | 1070 |
|
1072 |
function chartDataGroup($sel, $doquery=true){ |
|
1071 |
function chartDataGroup($sel, $doquery=true,$persistent){
|
|
1073 | 1072 |
//exoume dyo dims, ena tou xaxis kai ena tou group |
1074 | 1073 |
//kanoume tin idia diadikasia kai gia ta dyo |
1075 | 1074 |
$xfield = ''; |
... | ... | |
1274 | 1273 |
$query.= " LIMIT ".$sel['size']; |
1275 | 1274 |
//echo $query; |
1276 | 1275 |
$this->log->info('chartDataGroup generated query:'.$query); |
1277 |
$res = $this->doQuery($query, PDO::FETCH_NUM); |
|
1276 |
$res = $this->doQuery($query, PDO::FETCH_NUM,$persistent);
|
|
1278 | 1277 |
$this->log->info("result: ".print_r($res,true)); |
1279 | 1278 |
return array('type'=>'chart','data'=>$res); |
1280 | 1279 |
|
1281 | 1280 |
} |
1282 | 1281 |
|
1283 |
function scatterData($sel, $doquery=true){ |
|
1282 |
function scatterData($sel, $doquery=true,$persistent){
|
|
1284 | 1283 |
//group, color, or nothing |
1285 | 1284 |
//many fields or one |
1286 | 1285 |
if($sel['group']!='' && $sel['group'] != 'no'){ //group |
... | ... | |
1417 | 1416 |
} |
1418 | 1417 |
$this->log->info('scatterData generated query:'.$query); |
1419 | 1418 |
//echo "scatterplot, simple case:"; echo $query; |
1420 |
$res = $this->doQuery($query, PDO::FETCH_NUM); |
|
1419 |
$res = $this->doQuery($query, PDO::FETCH_NUM,$persistent);
|
|
1421 | 1420 |
|
1422 | 1421 |
$this->log->info("result: ".print_r($res,true)); |
1423 | 1422 |
return array('type'=>'scatter','data'=>$res); |
1424 | 1423 |
} |
1425 | 1424 |
} |
1426 | 1425 |
|
1427 |
function scatterDataColor($sel, $doquery=true){ |
|
1426 |
function scatterDataColor($sel, $doquery=true,$persistent){
|
|
1428 | 1427 |
//one dim, the one for the color |
1429 | 1428 |
//TODO: get all other dims to show in tooltip |
1430 | 1429 |
$dimfield = ''; |
... | ... | |
1568 | 1567 |
$query .= " ORDER BY ".$dimfield; |
1569 | 1568 |
//echo "scatterplot, case color:"; echo $query; |
1570 | 1569 |
$this->log->info('scatterDataColor generated query:'.$query); |
1571 |
$res = $this->doQuery($query, PDO::FETCH_NUM); |
|
1570 |
$res = $this->doQuery($query, PDO::FETCH_NUM,$persistent);
|
|
1572 | 1571 |
|
1573 | 1572 |
$this->log->info("result: ".print_r($res,true)); |
1574 | 1573 |
return array('type'=>'scatter','data'=>$res); |
1575 | 1574 |
} |
1576 | 1575 |
|
1577 |
function scatterDataGroup($sel, $doquery=true){ |
|
1576 |
function scatterDataGroup($sel, $doquery=true,$persistent){
|
|
1578 | 1577 |
//one dim, the one for the group |
1579 | 1578 |
//aggrs for all fields |
1580 | 1579 |
//TODO: get all other dims to show in tooltip |
... | ... | |
1722 | 1721 |
return array('type'=>'scatter','data'=>$res); |
1723 | 1722 |
} |
1724 | 1723 |
|
1725 |
function performQuery($query){ |
|
1724 |
function performQuery($query,$persistent){
|
|
1726 | 1725 |
$this->log->info("perfoming query"); |
1727 |
$res = $this->doQuery($query, PDO::FETCH_NUM); |
|
1726 |
$res = $this->doQuery($query, PDO::FETCH_NUM,$persistent);
|
|
1728 | 1727 |
|
1729 | 1728 |
$this->log->info("result: ".print_r($res,true)); |
1730 | 1729 |
return $res; |
... | ... | |
1844 | 1843 |
$query .= " order by ".$orderby; |
1845 | 1844 |
//echo "NOT GROUP"; echo $query; |
1846 | 1845 |
$this->log->info("generated query: ".$query); |
1847 |
$res = $this->doQuery($query, PDO::FETCH_NUM); |
|
1846 |
$res = $this->doQuery($query, PDO::FETCH_NUM,$persistent);
|
|
1848 | 1847 |
//print_r($res); |
1849 | 1848 |
//$this->log->info('result set:'.json_encode($res)); |
1850 | 1849 |
if($isMeas) $returnType = 'scatter'; |
modules/uoa-stats/branches/beta/statsServer/treemap.php | ||
---|---|---|
1 |
<!DOCTYPE html |
|
2 |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
|
3 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
4 |
<html> |
|
5 |
<?php |
|
6 |
require_once('controller.php'); |
|
7 |
$controller = new Controller(false); |
|
8 |
|
|
9 |
if(isset($_GET['com'])) { |
|
10 |
if($_GET['com'] == "query") { |
|
11 |
$selectedData = json_encode($_GET['data'],JSON_NUMERIC_CHECK); |
|
12 |
$resp = $controller->makeQuery('table'); |
|
13 |
} |
|
14 |
else{ |
|
15 |
echo "unknown command code"; |
|
16 |
} |
|
17 |
} |
|
18 |
else { |
|
19 |
//oops error |
|
20 |
echo "no command given"; |
|
21 |
} |
|
22 |
|
|
23 |
?> |
|
24 |
<head> |
|
25 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|
26 |
<title>treemap</title> |
|
27 |
|
|
28 |
<!-- Include JQuery Core--> |
|
29 |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> |
|
30 |
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> |
|
31 |
<script type="text/javascript" src="./js/themes9.js"></script> |
|
32 |
<style type="text/css"> |
|
33 |
h1{ |
|
34 |
text-align: center; |
|
35 |
font-family: "YanoneKaffeesatzLight","Lucida Grande","Lucida Sans Unicode",Verdana,Arial,Helvetica,sans-serif; |
|
36 |
font-weight: normal; |
|
37 |
font-size:26px; |
|
38 |
color: #2B54B8; |
|
39 |
line-height: 30px; |
|
40 |
} |
|
41 |
|
|
42 |
h2{ |
|
43 |
text-align: center; |
|
44 |
color: #2d72d6; |
|
45 |
font-family: "Lucida Grande","Lucida Sans Unicode",Verdana,Arial,Helvetica,sans-serif; |
|
46 |
font-weight: bold; |
|
47 |
font-size:medium; |
|
48 |
} |
|
49 |
|
|
50 |
#credits { |
|
51 |
color: #909090; |
|
52 |
//cursor: pointer; |
|
53 |
fill: #909090; |
|
54 |
font-family: "Lucida Grande","Lucida Sans Unicode",Verdana,Arial,Helvetica,sans-serif; |
|
55 |
font-size: 10px; |
|
56 |
float:right; |
|
57 |
margin-right:10%; |
|
58 |
} |
|
59 |
|
|
60 |
</style> |
|
61 |
<script type='text/javascript' src='https://www.google.com/jsapi'></script> |
|
62 |
<script type='text/javascript'> |
|
63 |
|
|
64 |
function isNumber (o) { |
|
65 |
return ! isNaN (o-0) && o !== null && o !== "" && o !== false; |
|
66 |
} |
|
67 |
|
|
68 |
var chart; |
|
69 |
var tableData; |
|
70 |
var selectedData; |
|
71 |
var headers; |
|
72 |
|
|
73 |
tableData = <?php echo $resp ?>; |
|
74 |
|
|
75 |
tableData['data'].sort(function(a,b) { |
|
76 |
return parseInt(b[1],10)-parseInt(a[1],10); |
|
77 |
}); |
|
78 |
|
|
79 |
selectedData = $.parseJSON(<?php echo $selectedData;?>); |
|
80 |
|
|
81 |
google.load("visualization", "1", {packages:["treemap"]}); |
|
82 |
google.setOnLoadCallback(draw); |
|
83 |
|
|
84 |
function draw() { |
|
85 |
drawTable(); |
|
86 |
drawToolbar(); |
|
87 |
credits(); |
|
88 |
} |
|
89 |
|
|
90 |
function drawTable(){ |
|
91 |
$('h1').html(selectedData['title']); |
|
92 |
$('h2').html(selectedData['subtitle']); |
|
93 |
////////////////////////////////////////////////// |
|
94 |
var rows = new Array(); |
|
95 |
var headerrow = new Array(); |
|
96 |
var data = new google.visualization.DataTable(); |
|
97 |
if(selectedData['xaxistitle'] && selectedData['xaxistitle']!=''){ |
|
98 |
headerrow.push(selectedData['xaxistitle']); |
|
99 |
} |
|
100 |
else{ |
|
101 |
var fld = selectedData['xaxis']['name'].split('-'); |
|
102 |
if(selectedData['xaxis']['agg']!='') |
|
103 |
headerrow.push(selectedData['xaxis']['agg']+" of "+fld[fld.length-1]); |
|
104 |
else |
|
105 |
headerrow.push(fld[fld.length-1]); |
|
106 |
} |
|
107 |
headerrow.push("Parent"); |
|
108 |
|
|
109 |
for(var i=0;i<selectedData['fields'].length && i<2;i++){ |
|
110 |
if(selectedData['fieldsheaders'] && selectedData['fieldsheaders'][i] && selectedData['fieldsheaders'][i]!=''){ |
|
111 |
headerrow.push(selectedData['fieldsheaders'][i]); |
|
112 |
} |
|
113 |
else{ |
|
114 |
fld = selectedData['fields'][i]['fld'].split('-'); |
|
115 |
if(selectedData['fields'][i]['agg']!='') |
|
116 |
headerrow.push(selectedData['fields'][i]['agg']+" of "+fld[fld.length-1]); |
|
117 |
else |
|
118 |
headerrow.push(fld[fld.length-1]); |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
rows.push(headerrow); |
|
123 |
rows.push(new Array("All",null,0)); |
|
124 |
for(var i in tableData['data']){ |
|
125 |
var row = new Array(); |
|
126 |
for(var j=0;j<tableData['data'][i].length && j<2;j++){ |
|
127 |
if(j==0){ |
|
128 |
if(isNumber(tableData['data'][i][j])) |
|
129 |
row.push(tableData['data'][i][j].toString()); |
|
130 |
else |
|
131 |
row.push(tableData['data'][i][j]); |
|
132 |
row.push("All"); |
|
133 |
} |
|
134 |
else |
|
135 |
row.push(tableData['data'][i][j]); |
|
136 |
} |
|
137 |
rows.push(row);//alert(JSON.stringify(tableData['data'][i])); |
|
138 |
//alert(JSON.stringify(row)); |
|
139 |
} |
|
140 |
data = google.visualization.arrayToDataTable(rows); |
|
141 |
////////////////////////////////////////////// |
|
142 |
var tree = new google.visualization.TreeMap(document.getElementById('tree_div')); |
|
143 |
tree.draw(data, { |
|
144 |
minColor: '#086A87', |
|
145 |
midColor: '#086A87', |
|
146 |
maxColor: '#086A87', |
|
147 |
headerHeight: 15, |
|
148 |
fontColor: 'black', |
|
149 |
showScale: false}); |
|
150 |
|
|
151 |
} |
|
152 |
|
|
153 |
function drawToolbar() { |
|
154 |
var components = [ |
|
155 |
{type: 'html', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>}, |
|
156 |
{type: 'csv', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>}, |
|
157 |
{type: 'htmlcode', datasource: '<?php echo $stats_server ?>/datasource.php?com=query&data='+<?php echo $selectedData;?>, |
|
158 |
style: 'width: 800px; height: 700px; border: 3px solid purple;'} |
|
159 |
]; |
|
160 |
|
|
161 |
var container = document.getElementById('toolbar'); |
|
162 |
google.visualization.drawToolbar(container, components); |
|
163 |
}; |
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
function numberWithCommas(num){ |
|
168 |
if(typeof num == "string") |
|
169 |
var array = num; |
|
170 |
else |
|
171 |
var array = num.toString().split(''); |
|
172 |
var index = -3; |
|
173 |
var len = array.length; |
|
174 |
while(len + index > 0){ |
|
175 |
array.splice(index, 0 , ','); |
|
176 |
index -= 4; |
|
177 |
} |
|
178 |
return array.join(''); |
|
179 |
} |
|
180 |
|
|
181 |
function credits(){ |
|
182 |
var cr = document.getElementById("credits"); |
|
183 |
var str = signature; |
|
184 |
if(addDate){ |
|
185 |
var today = new Date(); |
|
186 |
var dd = today.getDate(); |
|
187 |
var mm = today.getMonth()+1; //January is 0! |
|
188 |
var yyyy = today.getFullYear(); |
|
189 |
str += " (" + datetext + dd + "/" + mm + "/" + yyyy +")"; |
|
190 |
} |
|
191 |
cr.innerHTML = str; |
|
192 |
} |
|
193 |
</script> |
|
194 |
</head> |
|
195 |
|
|
196 |
<body> |
|
197 |
<h1 id='title'></h1> |
|
198 |
<h2 id='subtitle'></h2> |
|
199 |
|
|
200 |
<div id='tree_div' style="height:450px;width:736px;margin:auto"></div> |
|
201 |
<div id='toolbar' style="width:218px;margin:auto;"></div> |
|
202 |
<div id="credits"></div> |
|
203 |
</body> |
|
204 |
</html> |
|
1 |
<!DOCTYPE html |
|
2 |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
|
3 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
4 |
<html> |
|
5 |
<?php |
|
6 |
require_once('controller.php'); |
|
7 |
$controller = new Controller(false); |
|
8 |
|
|
9 |
if(isset($_GET['com'])) { |
|
10 |
if($_GET['com'] == "query") { |
|
11 |
$selectedData = json_encode($_GET['data'],JSON_NUMERIC_CHECK); |
|
12 |
$resp = $controller->makeQuery('table'); |
|
13 |
} |
|
14 |
else{ |
|
15 |
echo "unknown command code"; |
|
16 |
} |
|
17 |
} |
|
18 |
else { |
|
19 |
//oops error |
|
20 |
echo "no command given"; |
|
21 |
} |
|
22 |
|
|
23 |
?> |
|
24 |
<head> |
|
25 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|
26 |
<title>treemap</title> |
|
27 |
|
|
28 |
<!-- Include JQuery Core--> |
|
29 |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> |
|
30 |
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> |
|
31 |
<script type="text/javascript" src="./js/themes9.js"></script> |
|
32 |
<style type="text/css"> |
|
33 |
h1{ |
|
34 |
text-align: center; |
|
35 |
font-family: "YanoneKaffeesatzLight","Lucida Grande","Lucida Sans Unicode",Verdana,Arial,Helvetica,sans-serif; |
|
36 |
font-weight: normal; |
|
37 |
font-size:26px; |
|
38 |
color: #2B54B8; |
|
39 |
line-height: 30px; |
|
40 |
} |
|
41 |
|
|
42 |
h2{ |
|
43 |
text-align: center; |
|
44 |
color: #2d72d6; |
|
45 |
font-family: "Lucida Grande","Lucida Sans Unicode",Verdana,Arial,Helvetica,sans-serif; |
|
46 |
font-weight: bold; |
|
47 |
font-size:medium; |
|
48 |
} |
|
49 |
|
|
50 |
#credits { |
|
51 |
color: #909090; |
|
52 |
//cursor: pointer; |
|
53 |
fill: #909090; |
|
54 |
font-family: "Lucida Grande","Lucida Sans Unicode",Verdana,Arial,Helvetica,sans-serif; |
|
55 |
font-size: 10px; |
|
56 |
float:right; |
|
57 |
margin-right:10%; |
|
58 |
} |
|
59 |
|
|
60 |
</style> |
|
61 |
<script type='text/javascript' src='https://www.google.com/jsapi'></script> |
|
62 |
<script type='text/javascript'> |
|
63 |
|
|
64 |
function isNumber (o) { |
|
65 |
return ! isNaN (o-0) && o !== null && o !== "" && o !== false; |
|
66 |
} |
|
67 |
|
|
68 |
var chart; |
|
69 |
var tableData; |
|
70 |
var selectedData; |
|
71 |
var headers; |
|
72 |
|
|
73 |
tableData = <?php echo $resp ?>; |
|
74 |
|
|
75 |
tableData['data'].sort(function(a,b) { |
|
76 |
return parseInt(b[1],10)-parseInt(a[1],10); |
|
77 |
}); |
|
78 |
|
|
79 |
selectedData = $.parseJSON(<?php echo $selectedData;?>); |
|
80 |
|
|
81 |
google.load("visualization", "1", {packages:["treemap"]}); |
|
82 |
google.setOnLoadCallback(draw); |
|
83 |
|
|
84 |
function draw() { |
|
85 |
drawTable(); |
|
86 |
drawToolbar(); |
|
87 |
credits(); |
|
88 |
} |
|
89 |
|
|
90 |
function drawTable(){ |
|
91 |
$('h1').html(selectedData['title']); |
|
92 |
$('h2').html(selectedData['subtitle']); |
|
93 |
////////////////////////////////////////////////// |
|
94 |
var rows = new Array(); |
|
95 |
var headerrow = new Array(); |
|
96 |
var data = new google.visualization.DataTable(); |
|
97 |
if(selectedData['xaxistitle'] && selectedData['xaxistitle']!=''){ |
|
98 |
headerrow.push(selectedData['xaxistitle']); |
|
99 |
} |
|
100 |
else{ |
|
101 |
var fld = selectedData['xaxis']['name'].split('-'); |
|
102 |
if(selectedData['xaxis']['agg']!='') |
|
103 |
headerrow.push(selectedData['xaxis']['agg']+" of "+fld[fld.length-1]); |
|
104 |
else |
|
105 |
headerrow.push(fld[fld.length-1]); |
|
106 |
} |
|
107 |
headerrow.push("Parent"); |
|
108 |
|
|
109 |
for(var i=0;i<selectedData['fields'].length && i<2;i++){ |
|
110 |
if(selectedData['fieldsheaders'] && selectedData['fieldsheaders'][i] && selectedData['fieldsheaders'][i]!=''){ |
|
111 |
headerrow.push(selectedData['fieldsheaders'][i]); |
|
112 |
} |
|
113 |
else{ |
|
114 |
fld = selectedData['fields'][i]['fld'].split('-'); |
|
115 |
if(selectedData['fields'][i]['agg']!='') |
|
116 |
headerrow.push(selectedData['fields'][i]['agg']+" of "+fld[fld.length-1]); |
|
117 |
else |
|
118 |
headerrow.push(fld[fld.length-1]); |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
rows.push(headerrow); |
|
123 |
rows.push(new Array("All",null,0)); |
|
124 |
for(var i in tableData['data']){ |
|
125 |
var row = new Array(); |
|
126 |
for(var j=0;j<tableData['data'][i].length && j<2;j++){ |
|
127 |
if(j==0){ |
|
128 |
if(isNumber(tableData['data'][i][j])) |
|
129 |
row.push(tableData['data'][i][j].toString()); |
|
130 |
else |
|
131 |
row.push(tableData['data'][i][j]); |
|
132 |
row.push("All"); |
|
133 |
} |
|
134 |
else |
|
135 |
row.push(tableData['data'][i][j]); |
|
136 |
} |
|
137 |
rows.push(row);//alert(JSON.stringify(tableData['data'][i])); |
|
138 |
//alert(JSON.stringify(row)); |
|
139 |
} |
|
140 |
data = google.visualization.arrayToDataTable(rows); |
|
141 |
////////////////////////////////////////////// |
|
142 |
var tree = new google.visualization.TreeMap(document.getElementById('tree_div')); |
|
143 |
tree.draw(data, { |
|
144 |
minColor: '#086A87', |
|
145 |
midColor: '#086A87', |
|
146 |
maxColor: '#086A87', |
|
147 |
headerHeight: 15, |
|
148 |
fontColor: 'black', |
|
149 |
showScale: false}); |
|
150 |
|
|
151 |
} |
|
152 |
|
|
153 |
function drawToolbar() { |
|
154 |
var components = [ |
|
155 |
{type: 'html', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>}, |
|
156 |
{type: 'csv', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>}, |
|
157 |
{type: 'htmlcode', datasource: '<?php echo $stats_server ?>/datasource.php?com=query&data='+<?php echo $selectedData;?>, |
|
158 |
style: 'width: 800px; height: 700px; border: 3px solid purple;'} |
|
159 |
]; |
|
160 |
|
|
161 |
var container = document.getElementById('toolbar'); |
|
162 |
google.visualization.drawToolbar(container, components); |
|
163 |
}; |
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
function numberWithCommas(num){ |
|
168 |
if(typeof num == "string") |
|
169 |
var array = num; |
|
170 |
else |
|
171 |
var array = num.toString().split(''); |
|
172 |
var index = -3; |
|
173 |
var len = array.length; |
|
174 |
while(len + index > 0){ |
|
175 |
array.splice(index, 0 , ','); |
|
176 |
index -= 4; |
|
177 |
} |
|
178 |
return array.join(''); |
|
179 |
} |
|
180 |
|
|
181 |
function credits(){ |
|
182 |
var cr = document.getElementById("credits"); |
|
183 |
var str = signature; |
|
184 |
if(addDate){ |
|
185 |
var today = new Date(); |
|
186 |
var dd = today.getDate(); |
|
187 |
var mm = today.getMonth()+1; //January is 0! |
|
188 |
var yyyy = today.getFullYear(); |
|
189 |
str += " (" + datetext + dd + "/" + mm + "/" + yyyy +")"; |
|
190 |
} |
|
191 |
cr.innerHTML = str; |
|
192 |
} |
|
193 |
</script> |
|
194 |
</head> |
|
195 |
|
|
196 |
<body> |
|
197 |
<h1 id='title'></h1> |
|
198 |
<h2 id='subtitle'></h2> |
|
199 |
|
|
200 |
<div id='tree_div' style="height:450px;width:736px;margin:auto"></div> |
|
201 |
<div id='toolbar' style="width:218px;margin:auto;"></div> |
|
202 |
<div id="credits"></div> |
|
203 |
</body> |
|
204 |
</html> |
modules/uoa-stats/branches/beta/statsServer/gtable.php | ||
---|---|---|
1 |
<!DOCTYPE html |
|
2 |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
|
3 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
4 |
<html> |
|
5 |
<?php |
|
6 |
require_once('controller.php'); |
|
7 |
$controller = new Controller(false); |
|
8 |
|
|
9 |
if(isset($_GET['com'])) { |
|
10 |
if($_GET['com'] == "query") { |
|
11 |
$selectedData = json_encode($_GET['data']); |
|
12 |
$resp = $controller->makeQuery('table'); |
|
13 |
} |
|
14 |
else{ |
|
15 |
echo "unknown command code"; |
|
16 |
} |
|
17 |
} |
|
18 |
else { |
|
19 |
//oops error |
|
20 |
echo "no command given"; |
|
21 |
} |
|
22 |
|
|
23 |
?> |
|
24 |
<head> |
|
25 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|
26 |
<title>google table</title> |
|
27 |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> |
|
28 |
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> |
|
29 |
|
|
30 |
<link type="text/css" href="js/googlecharts.css" rel="stylesheet" /> |
|
31 |
|
|
32 |
<script type='text/javascript' src='//www.google.com/jsapi'></script> |
|
33 |
<script type='text/javascript'> |
|
34 |
|
|
35 |
function isNumber (o) { |
|
36 |
return ! isNaN (o-0) && o !== null && o !== "" && o !== false; |
|
37 |
} |
|
38 |
|
|
39 |
var chart; |
|
40 |
var tableData; |
|
41 |
var selectedData; |
|
42 |
var headers; |
|
43 |
|
|
44 |
var wflag = <?php |
|
45 |
if(isset($_GET['w']) && $_GET['w']!='' && $_GET['w'][strlen($_GET['w'])-1] == '%'){ |
|
46 |
echo "true"; |
|
47 |
} |
|
48 |
else{ |
|
49 |
echo "false"; |
|
50 |
} |
|
51 |
?> |
|
52 |
|
|
53 |
var mywidth = <?php if(isset($_GET['w']) && $_GET['w']!=''){ |
|
54 |
if($_GET['w'][strlen($_GET['w'])-1] == '%'){ |
|
55 |
echo substr($_GET['w'],0,strlen($_GET['w'])-1); |
|
56 |
|
|
57 |
} |
|
58 |
else{ |
|
59 |
if($_GET['w'][strlen($_GET['w'])-1] == 'x'){ |
|
60 |
echo substr($_GET['w'],0,strlen($_GET['w'])-2); |
|
61 |
} |
|
62 |
else |
|
63 |
echo $_GET['w']; |
|
64 |
} |
|
65 |
} |
|
66 |
else echo '556'; ?>; |
|
67 |
|
|
68 |
var hflag = <?php |
|
69 |
if(isset($_GET['h']) && $_GET['h']!='' && $_GET['h'][strlen($_GET['h'])-1] == '%'){ |
|
70 |
echo "true"; |
|
71 |
} |
|
72 |
else{ |
|
73 |
echo "false"; |
|
74 |
} |
|
75 |
?> |
|
76 |
|
|
77 |
|
|
78 |
var myheight = <?php if(isset($_GET['h']) && $_GET['h']!=''){ |
|
79 |
if($_GET['h'][strlen($_GET['h'])-1] == '%'){ |
|
80 |
echo substr($_GET['h'],0,strlen($_GET['h'])-1); |
|
81 |
|
|
82 |
} |
|
83 |
else{ |
|
84 |
if($_GET['w'][strlen($_GET['h'])-1] == 'x'){ |
|
85 |
echo substr($_GET['h'],0,strlen($_GET['h'])-2); |
|
86 |
} |
|
87 |
else |
|
88 |
echo $_GET['h']; |
|
89 |
} |
|
90 |
} |
|
91 |
else echo '347'; ?>; |
|
92 |
|
|
93 |
if(wflag) |
|
94 |
mywidth = mywidth * window.innerWidth / 100; |
|
95 |
if(hflag) |
|
96 |
myheight = myheight * window.innerHeight / 100; |
|
97 |
|
|
98 |
tableData = <?php echo $resp ?>; |
|
99 |
|
|
100 |
/*tableData['data'].sort(function(a,b) { |
|
101 |
return parseInt(b[1],10)-parseInt(a[1],10); |
|
102 |
});*/ |
|
103 |
|
|
104 |
selectedData = $.parseJSON(<?php echo $selectedData;?>); |
|
105 |
|
|
106 |
google.load('visualization', '1', {packages:['table']}); |
|
107 |
google.setOnLoadCallback(draw); |
|
108 |
|
|
109 |
function draw() { |
|
110 |
drawTable(); |
|
111 |
drawToolbar(); |
|
112 |
credits(); |
|
113 |
document.getElementById("credits").style.width = (mywidth/2)+"px"; |
|
114 |
} |
|
115 |
|
|
116 |
function drawTable(){ |
|
117 |
$('h1').html(selectedData['title']); |
|
118 |
$('h2').html(selectedData['subtitle']); |
|
119 |
|
|
120 |
var data = new google.visualization.DataTable(); |
|
121 |
var xtype; |
|
122 |
|
|
123 |
if(isNumber(tableData['data'][0][0])){ |
|
124 |
xtype = "number"; |
|
125 |
} |
|
126 |
else{ |
|
127 |
xtype = "string"; |
|
128 |
} |
|
129 |
|
|
130 |
|
|
131 |
if(selectedData['xaxistitle'] && selectedData['xaxistitle']!=''){ |
|
132 |
data.addColumn(xtype, selectedData['xaxistitle']); |
|
133 |
} |
|
134 |
else{ |
|
135 |
var fld = selectedData['xaxis']['name'].split('-'); |
|
136 |
if(selectedData['xaxis']['agg']!='') |
|
137 |
data.addColumn(xtype, selectedData['xaxis']['agg']+" of "+fld[fld.length-1]); |
|
138 |
else |
|
139 |
data.addColumn(xtype, fld[fld.length-1]); |
|
140 |
} |
|
141 |
for(var i=0;i<selectedData['fields'].length;i++){ |
|
142 |
var ftype = ''; |
|
143 |
if(isNumber(tableData['data'][0][i+1])) |
|
144 |
ftype= 'number'; |
|
145 |
else |
|
146 |
ftype = 'string'; |
|
147 |
|
|
148 |
if(selectedData['fieldsheaders'] && selectedData['fieldsheaders'][i] && selectedData['fieldsheaders'][i]!=''){ |
|
149 |
data.addColumn(ftype, selectedData['fieldsheaders'][i]); |
|
150 |
} |
|
151 |
else{ |
|
152 |
fld = selectedData['fields'][i]['fld'].split('-'); |
|
153 |
if(selectedData['fields'][i]['agg']!='') |
|
154 |
data.addColumn(ftype, selectedData['fields'][i]['agg']+" of "+fld[fld.length-1]); |
|
155 |
else |
|
156 |
data.addColumn(ftype, fld[fld.length-1]); |
|
157 |
} |
|
158 |
} |
|
159 |
if(selectedData['group'] != '' && selectedData['group'] != 'no'){ |
|
160 |
fld = selectedData['group'].split('-'); |
|
161 |
data.addColumn('string', fld[fld.length-1]); |
|
162 |
} |
|
163 |
else if(selectedData['color'] != '' && selectedData['color'] != 'no'){ |
|
164 |
fld = selectedData['color'].split('-'); |
|
165 |
data.addColumn('string', fld[fld.length-1]); |
|
166 |
} |
|
167 |
|
|
168 |
var rows = new Array(); |
|
169 |
for(var i in tableData['data']){ |
|
170 |
if(xtype=="string" && isNumber(tableData['data'][i][0])) |
|
171 |
|
|
172 |
// if(xtype=="string") |
|
173 |
continue; |
|
174 |
var row = new Array(); |
|
175 |
var len=tableData['data'][i].length; |
|
176 |
|
|
177 |
for(var j=0;j<len;j++){ |
|
178 |
row.push(tableData['data'][i][j]); |
|
179 |
} |
|
180 |
rows.push(row); |
|
181 |
} |
|
182 |
data.addRows(rows); |
|
183 |
//data.setProperty(0,0,'style','max-width:200px'); |
|
184 |
var table = new google.visualization.Table(document.getElementById('table_div')); |
|
185 |
table.draw(data, {showRowNumber: true,page:"enable",pageSize:30}); |
|
186 |
} |
|
187 |
|
|
188 |
function drawToolbar() { |
|
189 |
var components = [ |
|
190 |
{type: 'html', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>}, |
|
191 |
{type: 'csv', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>}, |
|
192 |
{type: 'htmlcode', datasource: '<?php echo $stats_server ?>/datasource.php?com=query&data='+<?php echo $selectedData;?>, |
|
193 |
style: 'width: 800px; height: 700px; border: 3px solid purple;'} |
|
194 |
]; |
|
195 |
|
|
196 |
var container = document.getElementById('toolbar'); |
|
197 |
google.visualization.drawToolbar(container, components); |
|
198 |
}; |
|
199 |
|
|
200 |
function credits(){ |
|
201 |
var today = new Date(); |
|
202 |
var dd = today.getDate(); |
|
203 |
var mm = today.getMonth()+1; //January is 0! |
|
204 |
var yyyy = today.getFullYear(); |
|
205 |
|
|
206 |
var cr = document.getElementById("credits"); |
|
207 |
cr.innerHTML = "from OpenAIRE via Google Charts (date: " + dd + "/" + mm + "/" + yyyy +")"; |
|
208 |
} |
|
209 |
|
|
210 |
</script> |
|
211 |
</head> |
|
212 |
|
|
213 |
<body> |
|
214 |
<h1 id='title'></h1> |
|
215 |
<h2 id='subtitle'></h2> |
|
216 |
|
|
217 |
<div id='table_div' style="margin:auto;width:80%;height:95%"></div> |
|
218 |
<div id="toolbar-outer" style="width:85%;"><div id='toolbar' style="margin:auto;width:218px;padding-top:40px;"></div></div> |
|
219 |
<div id="credits"></div> |
|
220 |
</body> |
|
221 |
</html> |
|
1 |
<!DOCTYPE html |
|
2 |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
|
3 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
4 |
<html> |
|
5 |
<?php |
|
6 |
require_once('controller.php'); |
|
7 |
$controller = new Controller(false); |
|
8 |
|
|
9 |
if(isset($_GET['com'])) { |
|
10 |
if($_GET['com'] == "query") { |
|
11 |
$selectedData = json_encode($_GET['data']); |
|
12 |
|
|
13 |
|
|
14 |
//make the query |
|
15 |
if(!isset($_GET['persistent'])){ |
|
16 |
|
|
17 |
$persistent="true"; |
|
18 |
} |
|
19 |
else |
|
20 |
{ |
|
21 |
$persistent="false"; |
|
22 |
} |
|
23 |
$resp = $controller->makeQuery('table',$persistent); |
|
24 |
} |
|
25 |
else{ |
|
26 |
echo "unknown command code"; |
|
27 |
} |
|
28 |
} |
|
29 |
else { |
|
30 |
//oops error |
|
31 |
echo "no command given"; |
|
32 |
} |
|
33 |
|
|
34 |
?> |
|
35 |
<head> |
|
36 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|
37 |
<title>google table</title> |
|
38 |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> |
|
39 |
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> |
|
40 |
|
|
41 |
<link type="text/css" href="js/googlecharts.css" rel="stylesheet" /> |
|
42 |
|
|
43 |
<script type='text/javascript' src='//www.google.com/jsapi'></script> |
|
44 |
<script type='text/javascript'> |
|
45 |
|
|
46 |
function isNumber (o) { |
|
47 |
return ! isNaN (o-0) && o !== null && o !== "" && o !== false; |
|
48 |
} |
|
49 |
|
|
50 |
var chart; |
|
51 |
var tableData; |
|
52 |
var selectedData; |
|
53 |
var headers; |
|
54 |
|
|
55 |
var wflag = <?php |
|
56 |
if(isset($_GET['w']) && $_GET['w']!='' && $_GET['w'][strlen($_GET['w'])-1] == '%'){ |
|
57 |
echo "true"; |
|
58 |
} |
|
59 |
else{ |
|
60 |
echo "false"; |
|
61 |
} |
|
62 |
?> |
|
63 |
|
|
64 |
var mywidth = <?php if(isset($_GET['w']) && $_GET['w']!=''){ |
|
65 |
if($_GET['w'][strlen($_GET['w'])-1] == '%'){ |
|
66 |
echo substr($_GET['w'],0,strlen($_GET['w'])-1); |
|
67 |
|
|
68 |
} |
|
69 |
else{ |
|
70 |
if($_GET['w'][strlen($_GET['w'])-1] == 'x'){ |
|
71 |
echo substr($_GET['w'],0,strlen($_GET['w'])-2); |
|
72 |
} |
|
73 |
else |
|
74 |
echo $_GET['w']; |
|
75 |
} |
|
76 |
} |
|
77 |
else echo '556'; ?>; |
|
78 |
|
|
79 |
var hflag = <?php |
|
80 |
if(isset($_GET['h']) && $_GET['h']!='' && $_GET['h'][strlen($_GET['h'])-1] == '%'){ |
|
81 |
echo "true"; |
|
82 |
} |
|
83 |
else{ |
|
84 |
echo "false"; |
|
85 |
} |
|
86 |
?> |
|
87 |
|
|
88 |
|
|
89 |
var myheight = <?php if(isset($_GET['h']) && $_GET['h']!=''){ |
|
90 |
if($_GET['h'][strlen($_GET['h'])-1] == '%'){ |
|
91 |
echo substr($_GET['h'],0,strlen($_GET['h'])-1); |
|
92 |
|
|
93 |
} |
|
94 |
else{ |
|
95 |
if($_GET['w'][strlen($_GET['h'])-1] == 'x'){ |
|
96 |
echo substr($_GET['h'],0,strlen($_GET['h'])-2); |
|
97 |
} |
|
98 |
else |
|
99 |
echo $_GET['h']; |
|
100 |
} |
|
101 |
} |
|
102 |
else echo '347'; ?>; |
|
103 |
|
|
104 |
if(wflag) |
|
105 |
mywidth = mywidth * window.innerWidth / 100; |
|
106 |
if(hflag) |
|
107 |
myheight = myheight * window.innerHeight / 100; |
|
108 |
|
|
109 |
tableData = <?php echo $resp ?>; |
|
110 |
|
|
111 |
/*tableData['data'].sort(function(a,b) { |
|
112 |
return parseInt(b[1],10)-parseInt(a[1],10); |
|
113 |
});*/ |
|
114 |
|
|
115 |
selectedData = $.parseJSON(<?php echo $selectedData;?>); |
|
116 |
|
|
117 |
google.load('visualization', '1', {packages:['table']}); |
|
118 |
google.setOnLoadCallback(draw); |
|
119 |
|
|
120 |
function draw() { |
|
121 |
drawTable(); |
|
122 |
drawToolbar(); |
|
123 |
credits(); |
|
124 |
document.getElementById("credits").style.width = (mywidth/2)+"px"; |
|
125 |
} |
|
126 |
|
|
127 |
function drawTable(){ |
|
128 |
$('h1').html(selectedData['title']); |
|
129 |
$('h2').html(selectedData['subtitle']); |
|
130 |
|
|
131 |
var data = new google.visualization.DataTable(); |
|
132 |
var xtype; |
|
133 |
if(isNumber(tableData['data'][0][0])){ |
|
134 |
xtype = "number"; |
|
135 |
} |
|
136 |
else{ |
|
137 |
xtype = "string"; |
|
138 |
} |
|
139 |
|
|
140 |
|
|
141 |
if(selectedData['xaxistitle'] && selectedData['xaxistitle']!=''){ |
|
142 |
data.addColumn(xtype, selectedData['xaxistitle']); |
|
143 |
} |
|
144 |
else{ |
|
145 |
var fld = selectedData['xaxis']['name'].split('-'); |
|
146 |
if(selectedData['xaxis']['agg']!='') |
|
147 |
data.addColumn(xtype, selectedData['xaxis']['agg']+" of "+fld[fld.length-1]); |
|
148 |
else |
|
149 |
data.addColumn(xtype, fld[fld.length-1]); |
|
150 |
} |
|
151 |
for(var i=0;i<selectedData['fields'].length;i++){ |
|
152 |
var ftype = ''; |
|
153 |
if(isNumber(tableData['data'][0][i+1])) |
|
154 |
ftype= 'number'; |
|
155 |
else |
|
156 |
ftype = 'string'; |
|
157 |
|
|
158 |
if(selectedData['fieldsheaders'] && selectedData['fieldsheaders'][i] && selectedData['fieldsheaders'][i]!=''){ |
|
159 |
data.addColumn(ftype, selectedData['fieldsheaders'][i]); |
|
160 |
} |
|
161 |
else{ |
|
162 |
fld = selectedData['fields'][i]['fld'].split('-'); |
|
163 |
if(selectedData['fields'][i]['agg']!='') |
|
164 |
data.addColumn(ftype, selectedData['fields'][i]['agg']+" of "+fld[fld.length-1]); |
|
165 |
else |
|
166 |
data.addColumn(ftype, fld[fld.length-1]); |
|
167 |
} |
|
168 |
} |
|
169 |
if(selectedData['group'] != '' && selectedData['group'] != 'no'){ |
|
170 |
fld = selectedData['group'].split('-'); |
|
171 |
data.addColumn('string', fld[fld.length-1]); |
|
172 |
} |
|
173 |
else if(selectedData['color'] != '' && selectedData['color'] != 'no'){ |
|
174 |
fld = selectedData['color'].split('-'); |
|
175 |
data.addColumn('string', fld[fld.length-1]); |
|
176 |
} |
|
177 |
|
|
178 |
var rows = new Array(); |
|
179 |
for(var i in tableData['data']){ |
|
180 |
if(xtype=="string" && isNumber(tableData['data'][i][0])) |
|
181 |
continue; |
|
182 |
var row = new Array(); |
|
183 |
var len=tableData['data'][i].length; |
|
184 |
|
|
185 |
for(var j=0;j<len;j++){ |
|
186 |
row.push(tableData['data'][i][j]); |
|
187 |
} |
|
188 |
rows.push(row); |
|
189 |
} |
|
190 |
data.addRows(rows); |
|
191 |
//data.setProperty(0,0,'style','max-width:200px'); |
|
192 |
var table = new google.visualization.Table(document.getElementById('table_div')); |
|
193 |
table.draw(data, {showRowNumber: true,page:"enable",pageSize:30}); |
|
194 |
} |
|
195 |
|
|
196 |
function drawToolbar() { |
|
197 |
var components = [ |
|
198 |
{type: 'html', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>}, |
|
199 |
{type: 'csv', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>}, |
|
200 |
{type: 'htmlcode', datasource: '<?php echo $stats_server ?>/datasource.php?com=query&data='+<?php echo $selectedData;?>, |
|
201 |
style: 'width: 800px; height: 700px; border: 3px solid purple;'} |
|
202 |
]; |
|
203 |
|
|
204 |
var container = document.getElementById('toolbar'); |
|
205 |
google.visualization.drawToolbar(container, components); |
|
206 |
}; |
|
207 |
|
|
208 |
function credits(){ |
|
209 |
var today = new Date(); |
|
210 |
var dd = today.getDate(); |
|
211 |
var mm = today.getMonth()+1; //January is 0! |
|
212 |
var yyyy = today.getFullYear(); |
|
213 |
|
|
214 |
var cr = document.getElementById("credits"); |
|
215 |
cr.innerHTML = "from OpenAIRE via Google Charts (date: " + dd + "/" + mm + "/" + yyyy +")"; |
|
216 |
} |
|
217 |
|
|
218 |
</script> |
|
219 |
</head> |
|
220 |
|
|
221 |
<body> |
|
222 |
<h1 id='title'></h1> |
|
223 |
<h2 id='subtitle'></h2> |
|
224 |
|
|
225 |
<div id='table_div' style="margin:auto;width:80%;height:95%"></div> |
|
226 |
<div id="toolbar-outer" style="width:85%;"><div id='toolbar' style="margin:auto;width:218px;padding-top:40px;"></div></div> |
|
227 |
<div id="credits"></div> |
|
228 |
</body> |
|
229 |
</html> |
modules/uoa-stats/branches/beta/statsServer/chart.php | ||
---|---|---|
1 |
<!DOCTYPE html |
|
2 |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
|
3 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
4 |
<html> |
|
5 |
<?php |
|
6 |
|
|
7 |
require_once('controller.php'); |
|
8 |
$controller = new Controller(false); |
|
9 |
|
|
10 |
if(!isset($_GET['com'])) { |
|
11 |
echo "no command given"; |
|
12 |
return; |
|
13 |
} |
|
14 |
if($_GET['com'] != "query"){ |
|
15 |
echo "unknown command code"; |
|
16 |
return; |
|
17 |
} |
|
18 |
|
|
19 |
//make the query |
|
20 |
$selectedData = json_encode($_GET['data']); |
|
21 |
$resp = $controller->makeQuery('chart'); |
|
22 |
|
|
23 |
//echo "selected ".json_encode($_GET['data'],JSON_NUMERIC_CHECK); |
|
24 |
//each filter to be included get its data and build the json object for the javascript |
|
25 |
//echo "will include ".count($_GET['data']['incfilters'])." filters"; |
|
26 |
|
|
27 |
$myData = json_decode($_GET['data']); |
|
28 |
if(isset($myData->incfilters)) |
|
29 |
$myfilters = $myData->incfilters; |
|
30 |
else |
|
31 |
$myfilters = array(); |
|
32 |
|
|
33 |
|
|
34 |
for($i=0;$i<count($myfilters);$i++){ |
|
35 |
if(isset($myfilters[$i]->values) && $myfilters[$i]->values=='all'){ |
|
36 |
$temp = $controller->getFilterData($myData->table,$myfilters[$i]->name); |
|
37 |
if(!is_array($temp)){ |
|
38 |
$temp = json_decode($temp); |
|
39 |
} |
|
40 |
//print_r($temp->data); |
|
41 |
$myfilters[$i]->values = $temp->data; |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
?> |
|
46 |
<head> |
|
47 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|
48 |
<title>chart</title> |
|
49 |
<!-- Include JQuery Core--> |
|
50 |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> |
|
51 |
<script type="text/javascript" src="./js/jquery-ui-1.9.1.custom/js/jquery-ui-1.9.1.custom.js"></script> |
|
52 |
|
|
53 |
<!-- HighCharts --> |
|
54 |
<script src="./js/Highcharts-4.0.1/js/highcharts.js" type="text/javascript"></script> |
|
55 |
<script src="./js/Highcharts-4.0.1/js/modules/exporting.js" type="text/javascript"></script> |
|
56 |
|
|
57 |
<script src="./js/themes9.js" type="text/javascript"></script> |
|
58 |
<!--Styles--> |
|
59 |
<link rel="stylesheet" href="//code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" /> |
|
60 |
<link type="text/css" href="./js/jquery/css/start/jquery-ui-1.8.20.custom.css" /> |
|
61 |
<link type="text/css" href="./js/highcharts.css" rel="stylesheet" /> |
|
62 |
<link rel="stylesheet" href="js/filters.css" /> |
|
63 |
|
|
64 |
|
|
65 |
<script type='text/javascript'> |
|
66 |
var chart; |
|
67 |
var chart2; |
|
68 |
var chartData; |
|
69 |
var chartData2; |
|
70 |
var chartDataFromServer; |
|
71 |
var selectedData; |
|
72 |
var filterData; |
|
73 |
var myFilter; |
|
74 |
//----------------- inits --------------------// |
|
75 |
var wflag = <?php if(isset($_GET['w']) && $_GET['w']!='' && $_GET['w'][strlen($_GET['w'])-1] == '%'){ echo "true"; } |
|
76 |
else{ echo "false"; }?> |
|
77 |
|
|
78 |
var mywidth = <?php if(isset($_GET['w']) && $_GET['w']!=''){ |
|
79 |
if($_GET['w'][strlen($_GET['w'])-1] == '%'){ |
|
80 |
echo substr($_GET['w'],0,strlen($_GET['w'])-1); |
|
81 |
|
|
82 |
}else{ |
|
83 |
if($_GET['w'][strlen($_GET['w'])-1] == 'x'){ |
|
84 |
echo substr($_GET['w'],0,strlen($_GET['w'])-2); |
|
85 |
}else echo $_GET['w']; |
|
86 |
} |
|
87 |
}else echo '700'; ?>; |
|
88 |
|
|
89 |
var hflag = <?php if(isset($_GET['h']) && $_GET['h']!='' && $_GET['h'][strlen($_GET['h'])-1] == '%'){ echo "true"; } |
|
90 |
else{ echo "false"; }?> |
|
91 |
|
|
92 |
var myheight = <?php if(isset($_GET['h']) && $_GET['h']!=''){ |
|
93 |
if($_GET['h'][strlen($_GET['h'])-1] == '%'){ |
|
94 |
echo substr($_GET['h'],0,strlen($_GET['h'])-1); |
|
95 |
}else{ |
|
96 |
if($_GET['w'][strlen($_GET['h'])-1] == 'x'){ |
|
97 |
echo substr($_GET['h'],0,strlen($_GET['h'])-2); |
|
98 |
} else echo $_GET['h']; |
|
99 |
} |
|
100 |
}else echo '400'; ?>; |
|
101 |
|
|
102 |
//----------------- document ready --------------------// |
|
103 |
$('document').ready(function(){ |
|
104 |
chartDataFromServer = <?php echo $resp ?>; |
|
105 |
selectedData = $.parseJSON(<?php echo $selectedData;?>); |
|
106 |
filterData = <?php echo json_encode($myfilters);?>; |
|
107 |
|
|
108 |
renderChart(); |
|
109 |
renderfilters(); |
|
110 |
controlsforfilters(); |
|
111 |
}); |
|
112 |
|
|
113 |
function renderChart(){ |
|
114 |
|
Also available in: Unified diff
latest changes in beta