3
require_once($ADEI_ROOTDIR . "/classes/jpgraph.php");
3
require_once($ADEI_ROOTDIR . "/classes/views/basehistogramview.php");
5
class histogramview extends VIEW {
5
class histogramview extends BASEHistogramView {
6
6
var $title = "Histogram";
8
8
function __construct(REQUEST $req = NULL, $opts) {
9
9
//$this->shelldisplay = false;
10
10
parent::__construct($req, $opts);
11
$this->object = $this->req->GetProp("view_object", false);
14
$this->max_points = $this->GetOption('max_points', 500);
16
$this->max_points = $this->GetOption('max_points', 5000);
18
$this->min_width = $this->GetOption('min_width', 300);
19
$this->min_height = $this->GetOption('min_height', 300);
21
$this->num_bins = $this->GetOption('bins', array(0));
24
function GetOption($opt, $default = false) {
25
if (isset($this->options[$opt])) return $this->options[$opt];
29
13
function GetOptions() {
30
$req = $this->req->CreateGroupRequest();
31
$x = $req->GetProp("view_x", false);
32
if ($x) list($x_gid, $x_id) = explode(":", $x);
33
else list($x_gid, $x_id) = array(0, 0);
35
$rdr = $req->CreateReader();
36
$group = $rdr->CreateGroup();
37
$caches = $rdr->CreateCacheSet($group, $mask);
41
foreach ($caches as $key => $cachewrap) {
42
array_push($result, array("label" => $cachewrap->GetGroupTitle(), "disabled" => 1));
45
$list = $cachewrap->GetItemList();
46
foreach ($list as $id => $info) {
47
$title = $info['name'];
48
array_push($result, array("value" => "$gid:$id", "label" => " $title"));
55
foreach ($this->num_bins as $bin) {
56
array_push($bins, array("value" => $bin, "label" => ($bin?$bin:"Auto")));
59
$checkboxNorm = array("label" => _("Normalize"), "id" => "hist_norm");
60
if ($req->GetProp("view_hist_norm", 0)) $checkboxNorm["checked"] = "checked";
62
$checkboxGFit = array("label" => _("Gaussian Fit"), "id" => "hist_fit");
63
if ($req->GetProp("view_hist_fit", 0)) $checkboxGFit["checked"] = "checked";
66
array("select" => array("id" => "x", "label" => _("x"), "options" => $result)),
67
array("xml"=>"<br/>"),
68
array("select" => array("id" => "bins" , "label" => _("Bins"), "options" => $bins)),
69
array("xml"=>"<br/>"),
70
array("checkbox" => $checkboxNorm),
71
array("checkbox" => $checkboxGFit)
14
$data = $this->GetDataOptions("x");
15
$hist = $this->GetHistOptions();
17
return array_merge($data, $hist);
75
20
function GetView() {
78
$req = $this->req->CreateDataRequest();
79
$x = $req->GetProp("view_x", false);
81
if (!$x) throw new ADEIException(translate("Parameter view_x is not set"));
83
list($x_gid, $x_id) = explode(":", $x);
86
$width = $req->GetProp($this->object . "_width", $this->min_width + 20) - 20;
87
if ($width < $this->min_width) $width = $this->min_width;
88
$height = $width - 40;//$req->GetProp($this->object . "_height", $this->min_height);
90
$width = $req->GetProp("page_width", $this->min_width + 5) - 5;
91
$height = $req->GetProp("page_height", $this->min_height);
92
if ($width < $this->min_width) $width = $this->min_width;
93
if ($height < $this->min_height) $height = $this->min_height;
97
$rdr = $req->CreateReader();
98
$group = $rdr->CreateGroup();
99
$caches = $rdr->CreateCacheSet($group, $mask);
102
$myreq = $this->req->CreateDataRequest();
103
$iv = $caches->CreateInterval($req, true);
104
$window_size = $iv->GetWindowSize();
105
$window_start = $iv->GetWindowStart();
106
$window_end = $iv->GetWindowEnd();
109
'limit' => $this->max_points,
21
$res = $this->GetData("x");
23
array("title"=>_("From"), "value" => date('c', $this->ivl->GetWindowStart())),
24
array("title"=>_("To"), "value" => date('c', $this->ivl->GetWindowEnd())),
25
array("title"=>_("Resolution"), "value" => $res['info'][0]['resolution']),
116
foreach ($caches as $key => $cachewrap) {
117
if (($gid != $x_gid)) {
122
$resolution = $cachewrap->GetResolution();
123
$r = $resolution->Get($iv, $width);
125
$size = $resolution->GetWindowSize($r);
126
if (($size > 0)&&(($window_size / $size) > $this->max_points)) {
127
$new_r = $resolution->Larger($r);
128
if ($new_r !== false) $r = $new_r;
129
$size = $resolution->GetWindowSize($r);
132
$rescfg['resolution'] = $r;
134
$points = $cachewrap->GetIntervals($iv, $rescfg, CACHE::TRUNCATE_INTERVALS);
135
$operation_info = $points->GetOperationInfo();
137
if ($gid == $x_gid) $res_x = $size;
140
foreach($points as $t => $v) {
141
/* if (($t < $window_start)||(($t + $size) > $window_end)) {
144
if (($gid == $x_gid)&&(is_numeric($v['mean'.$x_id]))) {
145
if (!is_array($res[$t])) $res[$t] = array();
146
$res[$t]['x'] = $v['mean'.$x_id];
156
foreach ($res as $val) {
157
if (isset($val['x'])) array_push($x, $val['x']);
161
throw new ADEIException(translate("No data found"));
164
$bins = $req->GetProp("view_bins", 0);
165
if (!$bins) $bins = ceil(sqrt(sizeof($x)));
167
$norm = $req->GetProp("view_hist_norm", 0);
168
$fit = $req->GetProp("view_hist_fit", 0);
173
$step = ($max - $min) / $bins;
175
$coef = $norm?(1/($step * sizeof($x))):1;
177
$h = array_fill(0, $bins, 0);
178
foreach ($x as $val) {
179
$idx = ($val - $min)/$step;
180
if ($idx == $bins) $idx--;
184
for($i = 0 ; $i < $bins ; $i++)
185
array_push($t, sprintf("%3.1e", $min + $i*$step));
187
$tmp_file = ADEI::GetTmpFile();
189
$graph = new Graph($width,$height);
190
/* $title = "Resolution: $res_x";
192
$graph->title->SetFont(FF_ARIAL,FS_BOLD,10);
193
$graph->title->Set($title);*/
194
$graph->SetTickDensity(TICKD_SPARSE, TICKD_SPARSE);
195
$graph->img->SetMargin(55,5,10,20);
197
$graph->SetScale("textlin");
198
$graph->xaxis->SetPos("min");
199
$graph->yaxis->SetPos("min");
200
// $graph->xaxis->SetLabelFormat('%3.1e');
201
// if (abs(max($h))<9999 && (abs(min($h))>0.01)) $graph->yaxis->SetLabelFormat('%01.2f');
202
// else $graph->yaxis->SetLabelFormat('%3.1e');
203
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
204
$graph->yaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
205
// $graph->yaxis->HideFirstTickLabel();
207
$graph->xaxis->title->SetFont(FF_ARIAL,FS_BOLD);
208
$graph->yaxis->title->SetFont(FF_ARIAL,FS_BOLD);
210
//$graph->xaxis->title->Set($arr[0]['select']['options'][$x_idg]['label']);
211
if($bins > 8) $graph->xaxis->SetTextLabelInterval(ceil(($bins / 6)));
212
$graph->xaxis->SetTickLabels($t);
214
$bplot = new BarPlot($h);
219
$graph->yaxis->scale->SetGrace(14);
221
$mean = array_sum($x)/sizeof($x);
222
$stddev = stats_standard_deviation($x);
223
$var = stats_variance($x);
225
$re = 100 * $sigma/$mean;
229
$median = $x[(sizeof($x) - 1)/2];
231
$median = ($x[sizeof($x)/2 - 1] + $x[sizeof($x)/2])/2;
238
if ($norm) $coef = (1/(sqrt(2 * pi() * $var)));
239
else $coef = ((sizeof($x)*$step)/(sqrt(2 * pi() * $var)));
242
for($i = 0; $i <= $bins; $i++) {
243
$offset = $i * $step;
244
$y = $coef * exp(-pow($min + $offset - $mean, 2)/(2*$var));
245
array_push($xdata, $i);
246
array_push($ydata, $y);
247
$xi2 += (pow($y - $h[$i], 2)) / $y;
251
$lineplot = new LinePlot($ydata , $xdata);
252
$graph->Add($lineplot);
255
$char_sigma = SymChar::Get('sigma', false);
259
$txt->SetFont(FF_ARIAL,FS_BOLD,10);
260
if( $req->GetProp("view_GFit", false) == "true")
261
$txt->Set("m=$mean\n$char_sigma=$sigma\nRE=$RE%\nx^2=$xi2");//\ns=$stdDev
263
$txt->Set("m=$mean\n$char_sigma=$sigma\nRE=$RE%");//\ns=$stdDev
264
$txt->ParagraphAlign('right');
265
$txt->SetPos(0.96,0.1,'right');
266
//$txt->SetBox('white');
270
$graph->Stroke("$TMP_PATH/$tmp_file");
274
array("img" => array("id" => $tmp_file)),
275
array("info" => array(
276
array("title"=>_("From"), "value" => date('c', $iv->GetWindowStart())),
277
array("title"=>_("To"), "value" => date('c', $iv->GetWindowEnd())),
278
array("title"=>_("Resolution"), "value" => $res_x),
279
array("title"=>_("Bins"), "value" => $bins),
280
array("title"=>_("First Bin"), "value" => $min),
281
array("title"=>_("Last Bin"), "value" => $min + $bins * $step),
282
array("title"=>_("Mean"), "value" => $mean),
283
array("title"=>_("Median"), "value" => $median),
284
array("title"=>_("StdDev"), "value" => $stddev),
285
array("title"=>_("Sigma"), "value" => $sigma),
286
array("title"=>_("RE"), "value" => ($re . "%")),
290
array_push($res[1]["info"], array("title"=>_("xi2"), "value" => $xi2));
295
"img" => array("id" => $tmp_file)
29
foreach ($res['data'] as $val) {
30
if (isset($val[0])) array_push($x, $val[0]);
33
$view = $this->GetHistView($x);
34
$this->MergeViewInfo($view, $info, VIEW::MERGE_START);