Beispiel #1
0
 function End($flags = 0)
 {
     try {
         $req = new DATARequest();
         $draw = $req->CreatePlotter();
         $draw->Create();
         $id = $draw->Save();
     } catch (ADEIException $e) {
         $error = $e->getInfo();
         try {
             if (!$draw) {
                 if (!$req) {
                     $req = new REQUEST();
                 }
                 $draw = $req->CreateTextPlotter();
             }
             //	    $draw->CreateMessage("Error", "No Data");
             $draw->CreateMessage("Error", $error);
             $id = $draw->Save();
             $error = false;
         } catch (ADEIException $ex) {
             $ex->logInfo(NULL, $draw);
         }
     }
     $res = DRAW::Display($id);
     $this->h->Write($res);
 }
Beispiel #2
0
 function listSensors($opts)
 {
     $req = new DATARequest($opts);
     $reader = $req->CreateReader();
     $groups = $reader->GetGroups();
     $grouplist = $reader->GetGroupList();
     $mask = new MASK($opts);
     $i = 0;
     foreach ($grouplist as $group => $details) {
         $itemlist[$det['gid']] = $reader->GetItemList($groups[$i], $mask);
         $i++;
     }
     foreach ($itemlist as $gid => $items) {
         if (!is_numeric($gid)) {
             foreach ($items as $key => $item) {
                 $details['groups'][$gid][$key] = array("id" => "{$item['id']}", "name" => "{$item['name']}");
             }
         }
     }
     return $details;
 }
Beispiel #3
0
function TryPlot(DATARequest $req, &$draw, &$no_data)
{
    try {
        $draw = $req->CreatePlotter();
        $draw->Create();
    } catch (ADEIException $ae) {
        $recovered = false;
        switch ($ae->getCode()) {
            case ADEIException::PLOTTER_WINDOW_TOO_SMALL:
                if (!$req->GetProp('hide_axes')) {
                    $ae->logInfo(NULL, $draw ? $draw : $req);
                    $req->SetProp('hide_axes', 'Y');
                    TryPlot($req, $draw, $no_data);
                    return translate("To many Y-axes, hidden");
                }
                break;
            case ADEIException::NO_DATA:
            case ADEIException::NO_CACHE:
            case ADEIException::INVALID_REQUEST:
                if ($draw) {
                    try {
                        $error = $ae->getInfo();
                        $draw->CreateMessage("Error", $error);
                        $no_data = true;
                        return 0;
                    } catch (ADEIException $ex) {
                        $ex->logInfo(NULL, $draw);
                        throw $ae;
                    }
                }
                break;
        }
        throw $ae;
    }
    return 0;
}
Beispiel #4
0
<?php

$_POST['props'] = "{\"db_server\": \"precmm0\", \"db_name\": \"PrecMagnet\", \"db_group\": \"NorthRing\"}";
$curdir = getcwd();
if (preg_match("/(.*)cache.php\$/", $_SERVER['SCRIPT_FILENAME'], $m)) {
    @chdir($m[1]);
}
require "../adei.php";
try {
    $req = new DATARequest();
    $cache = $req->CreateCache();
    $postfix = $cache->GetCachePostfix();
    $cache->Drop($postfix, "1424344528");
} catch (ADEIException $ae) {
    throw $ae;
}
Beispiel #5
0
 function GetCacheImg($download)
 {
     $filename = $this->downloads_path . "/images/{$download}.png";
     try {
         $req = new DATARequest();
         $req->SetProp("width", "512");
         $req->SetProp("height", "384");
         $draw = $req->CreatePlotter();
         $draw->Create();
         $draw->Save($filename);
     } catch (ADEIException $ex) {
         $ex->logInfo(NULL, $draw);
     }
 }
Beispiel #6
0
<?php

require "../../adei.php";
$_POST['props'] = "{\"db_server\": \"autogen\", \"db_name\": \"minutely\", \"db_group\": \"default\", \"db_mask\": \"\", \"experiment\": \"0-0\", \"window\": \"-1\", \"format\": \"csv\"}";
try {
    $req = new DATARequest();
    $rdr = $req->CreateReader();
    $group = $rdr->CreateGroup();
    $group = $rdr->CreateGroup();
    $caches = $rdr->CreateCacheSet($group);
    $ivl = $caches->CreateInterval();
    $cfg = array("type" => CACHE::TYPE_AUTO, "limit" => $limit, "amount" => $limit, "precision" => $precision);
    foreach ($caches as $key => $cachewrap) {
        $cache = $cachewrap->GetCache();
        $size = $cachewrap->GetWidth();
    }
    $data = $cache->reader->GetFilteredData();
    foreach ($data as $time => $vector) {
        echo "{$time}";
        foreach ($vector as $v) {
            echo ", {$v}";
        }
        echo "\n";
    }
} catch (ADEIException $e) {
    echo "ERROR: " . $e->getInfo();
}
Beispiel #7
0
function adeiCreateExporter(STREAMHandler &$h = NULL)
{
    $req = new DATARequest();
    return $req->CreateExporter($h);
}
Beispiel #8
0
<?php

ADEI::RequireClass("draw");
header("Content-type: image/png");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
if (isset($_GET["id"])) {
    $id = $_GET["id"];
} else {
    try {
        $req = new DATARequest();
        $draw = $req->CreatePlotter();
        $draw->Create();
        $id = $draw->Save();
    } catch (ADEIException $e) {
        $error = $e->getInfo();
        try {
            if (!$draw) {
                if (!$req) {
                    $req = new REQUEST();
                }
                $draw = $req->CreateTextPlotter();
            }
            //	    $draw->CreateMessage("Error", "No Data");
            $draw->CreateMessage("Error", $error);
            $id = $draw->Save();
            $error = false;
        } catch (ADEIException $ex) {
            $ex->logInfo(NULL, $draw);
        }
    }
Beispiel #9
0
<?php

require "../../adei.php";
$_POST['props'] = "{\"db_server\": \"fastgen\", \"db_name\": \"10hz\", \"db_group\": \"0\", \"window\": \"1226546847-1226546848\", \"format\": \"csv\"}";
try {
    $req = new DATARequest();
    $export = $req->CreateExporter();
    //    $export->SetCacheMode();
    $export->Export();
} catch (ADEIException $e) {
    echo "ERROR: " . $e->getInfo();
}
Beispiel #10
0
 function GetView()
 {
     global $ADEI_ID_DELIMITER;
     global $TMP_PATH;
     $req = $this->req->CreateDataRequest();
     $mapping_group = $req->GetProp("view_mapping_group", false);
     if (!$mapping_group) {
         throw new ADEIException(translate("Parameter view_mapping_group is not set"));
     }
     if ($mapping_group != "all") {
         list($server_db, $name_db, $group_db) = explode($ADEI_ID_DELIMITER, $mapping_group);
         $props_to_replace = array("db_server" => $server_db, "db_name" => $name_db, "db_group" => $group_db, "db_mask" => "");
         $req = new DATARequest(array_merge($req->props, $props_to_replace));
     }
     if ($this->object) {
         $width = $req->GetProp($this->object . "_width", $this->min_width + 20) - 20;
         if ($width < $this->min_width) {
             $width = $this->min_width;
         }
         $height = $width - 40;
     } else {
         $width = $req->GetProp("page_width", $this->min_width + 5) - 5;
         $height = $req->GetProp("page_height", $this->min_height);
         if ($width < $this->min_width) {
             $width = $this->min_width;
         }
         if ($height < $this->min_height) {
             $height = $this->min_height;
         }
     }
     $rdr = $req->CreateReader();
     $group = $rdr->CreateGroup();
     $caches = $rdr->CreateCacheSet($group, $mask);
     $myreq = $this->req->CreateDataRequest();
     $iv = $caches->CreateInterval($req, true);
     $window_size = $iv->GetWindowSize();
     $window_start = $iv->GetWindowStart();
     $window_end = $iv->GetWindowEnd();
     $rescfg = array('limit' => 1, 'resolution' => $res);
     $norm_hist_max = $req->GetProp("view_hist_norm_max", false);
     $norm_hist_srf = $req->GetProp("view_hist_norm_srf", false);
     $scale_log = $req->GetProp("view_log_scale", false);
     $mode_of_draw = $req->GetProp("view_draw_mode", false);
     $bin_from = $req->GetProp("view_bin_from", false);
     $bin_to = $req->GetProp("view_bin_to", false);
     $max_of_y = $req->GetProp("view_y_max", false);
     if (!$bin_from || $bin_from <= 0 || $bin_from == "false") {
         $bin_from = 1;
     }
     if (!isset($max_of_y) || $max_of_y < 0) {
         $max_of_y = 0;
     }
     $x_bin = array();
     $x_bin_min = array();
     $x_bin_max = array();
     $x_bin_sum = array();
     $x_axis_tick_labels = array();
     foreach ($caches as $key => $cachewrap) {
         $resolution = $cachewrap->GetResolution();
         if (!$bin_to || $bin_to <= 0 || $bin_to == "false") {
             $bin_to = $cachewrap->GetWidth();
         }
         $bins_n = $bin_to - $bin_from + 1;
         $r = $resolution->Get($iv, $width);
         $size = $resolution->GetWindowSize($r);
         if ($size > 0 && $window_size / $size > $this->max_points) {
             $new_r = $resolution->Larger($r);
             if ($new_r !== false) {
                 $r = $new_r;
             }
             $size = $resolution->GetWindowSize($r);
         }
         $rescfg['resolution'] = $r;
         $points = $cachewrap->GetIntervals($iv, $rescfg, CACHE::TRUNCATE_INTERVALS);
         $operation_info = $points->GetOperationInfo();
         $res_x = $size;
         $sum_of_vars = 0;
         $sum_of_vars_min = 0;
         $sum_of_vars_max = 0;
         $number_of_events = 0;
         $number_of_events_min = 0;
         $number_of_events_max = 0;
         foreach ($points as $t => $v) {
             for ($i = $bin_from - 1; $i < $bin_to; $i++) {
                 $bin_height = $v['mean' . $i];
                 if ($mode_of_draw == "hist_sum") {
                     $bin_height *= $v['items'];
                 }
                 $x_bin[$i - $bin_from + 1] += $bin_height;
                 $sum_of_vars += ($i + 1) * $bin_height;
                 $number_of_events += $bin_height;
                 if ($mode_of_draw == "hist_minmax") {
                     $x_bin_min[$i - $bin_from + 1] += $v['min' . $i];
                     $x_bin_max[$i - $bin_from + 1] += $v['max' . $i];
                 }
                 array_push($x_axis_tick_labels, sprintf("%d", $i + 1));
             }
         }
         if (!$x_bin) {
             throw new ADEIException(translate("No data found"));
         }
         $mean = $sum_of_vars / $number_of_events;
         $var_std = 0;
         $var_sum = 0;
         $var_bin = 0;
         $half_number_of_events = $number_of_events / 2;
         for ($i = $bin_from; $i <= $bin_to; $i++) {
             $var_std += ($i - $mean) * ($i - $mean) * $x_bin[$i - $bin_from];
             if ($var_sum < $half_number_of_events) {
                 $var_sum += $x_bin[$i - $bin_from];
                 $var_bin = $i - $bin_from;
             }
         }
         $stddev = sqrt($var_std / $number_of_events);
         $median = $var_bin + ($half_number_of_events - $var_sum + $x_bin[$var_bin + 1]) / $x_bin[$var_bin + 1];
     }
     $tmp_file = ADEI::GetTmpFile();
     $graph = new Graph($width, $height);
     $graph->SetTickDensity(TICKD_SPARSE, TICKD_SPARSE);
     $graph->img->SetMargin(55, 5, 10, 20);
     if (!$scale_log) {
         $graph->SetScale("textlin", 0, $max_of_y);
     } else {
         if (min($x_bin) >= 0) {
             $graph->SetScale("textlog");
         } else {
             throw new ADEIException(translate("The selected data contains negative values which can't be visualized on the log scale"));
         }
     }
     $graph->xaxis->SetPos("min");
     $graph->yaxis->SetPos("min");
     $graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
     $graph->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
     $graph->xaxis->title->SetFont(FF_ARIAL, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_ARIAL, FS_BOLD);
     if ($bins_n > 16) {
         $graph->xaxis->SetTextLabelInterval(ceil($bins_n / ceil($width / 25)));
     }
     $graph->xaxis->SetTickLabels($x_axis_tick_labels);
     $bplot = new BarPlot($x_bin);
     $bplot->SetWidth(1);
     if ($mode_of_draw == "hist_sum") {
         $bplot->SetLegend("Sum Mode");
     } else {
         $bplot->SetLegend("AVG Mode");
     }
     if ($mode_of_draw == "hist_minmax") {
         $bplot_min = new BarPlot($x_bin_min);
         $bplot_min->SetWidth(1);
         $bplot_min->SetLegend("Minimum");
         $bplot_min->SetFillColor('deepskyblue');
         $bplot_max = new BarPlot($x_bin_max);
         $bplot_max->SetWidth(1);
         $bplot_max->SetLegend("Maximum");
         $bplot_max->SetFillColor('indianred1');
     }
     if ($mode_of_draw == "hist_minmax") {
         $graph->Add($bplot_max);
     }
     $graph->Add($bplot);
     if ($mode_of_draw == "hist_minmax") {
         $graph->Add($bplot_min);
     }
     $graph->yaxis->scale->SetGrace(14);
     $graph->Stroke("{$TMP_PATH}/{$tmp_file}");
     if ($this->object) {
         $res = array(array("img" => array("id" => $tmp_file)), array("info" => array(array("title" => _("Number of Bins"), "value" => round($bins_n, 3)), array("title" => _("Mode"), "value" => array_search(max($x_bin), $x_bin) + $bin_from), array("title" => _("Mean"), "value" => round($mean, 3)), array("title" => _("Median"), "value" => round($median, 3)), array("title" => _("Value of Mode"), "value" => round(max($x_bin), 3)), array("title" => _("Integral of Hist"), "value" => round($number_of_events, 3)), array("title" => _("StdDev"), "value" => round($stddev, 3)), array("title" => _("RE"), "value" => round($stddev / $mean * 100 . "%", 3) . "%"), array("title" => _("From"), "value" => date('c', $iv->GetWindowStart())), array("title" => _("To"), "value" => date('c', $iv->GetWindowEnd())), array("title" => _("Resolution"), "value" => round($res_x, 3)))));
         return $res;
     } else {
         return array("img" => array("id" => $tmp_file));
     }
 }