コード例 #1
0
ファイル: testreader.php プロジェクト: nicolaisi/adei
 public function __construct(TESTReader &$reader, OPTIONS &$opts, &$items, INTERVAL &$ivl, $resample)
 {
     $period = $opts->Get('period');
     $this->multiplier = $reader->GetFractionalMultiplier($period);
     $this->period = $this->multiplier * $period;
     $this->resample = $this->multiplier * $resample;
     $from = $this->multiplier * $ivl->GetWindowStart();
     $ifrom = ceil($from);
     $rem = $ifrom % $this->period;
     if ($rem) {
         $this->from = $ifrom + ($this->period - $rem);
     } else {
         $this->from = $ifrom;
     }
     $this->to = $this->multiplier * $ivl->GetWindowEnd();
     $limit = $ivl->GetItemLimit();
     if ($limit) {
         if ($limit > 0) {
             $to = $this->from + $this->period * $limit;
             if ($to < $this->to) {
                 $this->to = $to;
             }
         } else {
             $from = $this->to + $this->period * $limit;
             if ($from > $this->from) {
                 $this->from = $from;
             }
         }
     }
     $this->items =& $items;
     $limit = $opts->GetDateLimit(TESTData::DEFAULT_START, time());
     $this->start = $limit[0];
 }
コード例 #2
0
ファイル: draw.php プロジェクト: nicolaisi/adei-cube
    function LegendSlow(array &$spec, INTERVAL $iv, MASK $mask = NULL, INTERVAL $ivl = NULL)
    {
        $x = $spec['x'];
        $y = $spec['y'];
        $xmin = $spec['xmin'];
        $xmax = $spec['xmax'];
        list($axes, $data, $data_spec) = $this->PrepareData($this->reader, $mask, $ivl, true);
        $axes->Enumerate();
        $from = $iv->GetWindowStart();
        $to = $iv->GetWindowEnd();
        $result = array();
        $itempositions = array_fill(0, $axes->GetAxesNumber(), 0);
        // counters by axis
        $itempos = array();
        // itemid in group => itemid in axis
        foreach ($data as $gid => &$info) {
            foreach ($info['time'] as $first => $tm) {
                if ($tm > $from) {
                    break;
                }
            }
            if ($tm > $from) {
                for ($last = $first; isset($info['time'][$last]) && $info['time'][$last] < $to; $last++) {
                }
                $size = $last - $first;
            } else {
                $first = false;
            }
            if ($first !== false && $size > 0) {
                $point_mode = true;
            } else {
                $point_mode = false;
                $approximation_mode = false;
                if ($first > 0) {
                    $x1 = $info['time'][$first - 1];
                    $x2 = $info['time'][$first];
                    $check1 = true;
                    if (!$this->interpolate_gaps) {
                        $distance = max(dsMathPreciseSubstract($x, $x1), dsMathPreciseSubstract($x2, $x));
                        if ($this->allowed_gap && $distance > $this->allowed_gap) {
                            $check1 = false;
                        }
                        if ($info['resolution'] && $distance > 2 * $info['resolution']) {
                            $check1 = false;
                        }
                    }
                    if ($check1 && dsMathPreciseCompare($x1, $xmin) >= 0 && dsMathPreciseCompare($x2, $xmax) <= 0) {
                        $coef = dsMathPreciseSubstract($x, $x1) / dsMathPreciseSubstract($x2, $x1);
                        $approximation_mode = true;
                    }
                }
            }
            if ($info['aggregation'] == CACHE::TYPE_MINMAX) {
                $value_type = "value";
            } else {
                $value_type = "mean";
            }
            $group_result = array();
            foreach ($info['values'] as $cid => &$channel) {
                $axis = $axes->GetAxis($info['axis'][$cid]);
                $axispos = $axis->GetPosition();
                $itempos[$i] = $itempositions[$axispos]++;
                list($min, $max) = $this->GetLegendSpecYInterval($spec, $axispos);
                #	    echo max($channel) . "\n";
                if ($point_mode) {
                    $slice = array_slice($channel, $first, $size);
                    $slice = array_filter($slice, create_function('$val', '
		    if (is_numeric($val)) return true;
		    return false;
		'));
                    if ($slice) {
                        $have_data = true;
                        $vmin = min($slice);
                        $vmax = max($slice);
                    } else {
                        $have_data = false;
                    }
                    if ($have_data && ($vmax < $min || $vmin > $max) == false) {
                        array_push($group_result, array("id" => $info['items'][$cid]['id'], "name" => $info['items'][$cid]['name'], "mode" => "interval", "interval" => array("from" => $iv->GetWindowStart(), "to" => $iv->GetWindowEnd(), "resolution" => $info['resolution']), $value_type => array("min" => $this->ValueFormat($vmin, abs($vmax)), "max" => $this->ValueFormat($vmax, abs($vmin))), "color" => $axis->GetChannelColor($itempos[$i])));
                    }
                } else {
                    if ($approximation_mode) {
                        // approximation
                        list($min, $max) = $this->GetLegendSpecYInterval($spec, $axispos);
                        $y1 = $channel[$first - 1];
                        $y2 = $channel[$first];
                        $y = $y1 + $coef * ($y2 - $y1);
                        //DS.Precision
                        if ($y > $min && $y < $max) {
                            array_push($group_result, array("id" => $info['items'][$cid]['id'], "name" => $info['items'][$cid]['name'], "mode" => "approximation", "approximation" => array("x1" => $x1, "y1" => $this->ValueFormat($y1, $y2), "x2" => $x2, "y2" => $this->ValueFormat($y2, $y1)), "color" => $axis->GetChannelColor($itempos[$i])));
                        }
                    }
                }
            }
            if ($group_result) {
                array_push($result, array("title" => $info['name'], "results" => $group_result));
            }
        }
        return $result;
    }
コード例 #3
0
ファイル: zeus.php プロジェクト: nicolaisi/adei
 function GetRawAlarms(LOGGROUP $grp = NULL, $from = false, $to = false, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     if ($this->server['driver'] == "mysql" || $this->sqldrv['driver'] == "mysql") {
         // the subrequest should be formulated differently.
         //throw new ADEIException(translate("Alarms are not supported in MySQL version yet"));
     }
     // If interval is not specified we are looking for the alarms in the
     // interval where the data of current group is present
     //The group is optional and not needed in this reader
     /*
         try {
     	$grp = $this->CheckGroup($grp);
         } catch (ADEIException $ae) {
     	$grp = false;
         }
     */
     if (!$from || !$to) {
         if ($grp) {
             $ivl = $this->CreateInterval($grp);
         } else {
             $ivl = new INTERVAL($this->req->props);
         }
         $ivl->Limit($from, $to);
         $from = $ivl->GetWindowStart(false);
         $to = $ivl->GetWindowEnd(false);
     }
     if ($filter) {
         $limit = $filter->GetVectorsLimit();
         $mode = $filter->GetProperty("alarm_list_mode");
         $severity = $filter->GetProperty("alarm_severity");
         $mask = $filter->GetItemMask();
         if (isset($filter_data)) {
             if ($mask) {
                 $filter_data['masked'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $limit = 0;
         $mode = 0;
         $severity = 0;
         $mask = NULL;
     }
     $masktest = "";
     if ($mask) {
         $ids = $mask->GetIDs();
         if ($ids) {
             $lastid = array_pop($ids);
             foreach ($ids as $id) {
                 $masktest .= "(messageid = {$id}) OR ";
             }
             $masktest .= "(messageid = {$lastid})";
         }
     }
     switch ($mode) {
         case READER::ALARM_MODE_ACTIVE_LIST:
             $cond = "mtype >= {$severity} AND go = 0";
             if ($masktest) {
                 $cond .= " AND ({$masktest})";
             }
             $columns = array("messageid", "mtype", "name", "cond", "come");
             $selopts = array("condition" => $cond, "order" => "mtype DESC, come DESC");
             $query = $this->db->SelectRequest("messagelog", $columns, $selopts);
             break;
         case READER::ALARM_MODE_FULL_LIST:
             if ($from !== false) {
                 $from = $this->ImportUnixTime($from);
             }
             if ($to !== false) {
                 $to = $this->ImportUnixTime($to);
             }
             if ($from === false && $to === false) {
                 $test = false;
             } else {
                 if ($from === false) {
                     $test = "(come < {$to})";
                 } else {
                     if ($to === false) {
                         $test = "((go = 0) OR (go > {$from}))";
                     } else {
                         $test = "(come BETWEEN {$from} and {$to}) OR ((come < {$from}) AND ((go = 0) OR (go > {$from})))";
                     }
                 }
             }
             if ($test) {
                 $cond = "(mtype >= {$severity}) AND ({$test})";
             } else {
                 $cond = "(mtype >= {$severity})";
             }
             if ($masktest) {
                 $cond .= " AND ({$masktest})";
             }
             $columns = array("messageid", "mtype", "name", "cond", "come", "go");
             $selopts = array("condition" => $cond, "order" => "mtype DESC, come DESC");
             if ($limit) {
                 $selopts['limit'] = abs($limit);
                 if ($limit > 0) {
                     $selopts['order'] = "come ASC";
                 } else {
                     $selopts['order'] = "come DESC";
                 }
             } else {
                 $selopts['order'] = "come ASC";
             }
             $query = $this->db->SelectRequest("messagelog", $columns, $selopts);
             break;
         default:
             if ($from !== false) {
                 $from = $this->ImportUnixTime($from);
             }
             if ($to !== false) {
                 $to = $this->ImportUnixTime($to);
             }
             if ($from === false && $to === false) {
                 $test = false;
             } else {
                 if ($from === false) {
                     $test = "(come < {$to})";
                 } else {
                     if ($to === false) {
                         $test = "((go = 0) OR (go > {$from}))";
                     } else {
                         $test = "(come BETWEEN {$from} and {$to}) OR ((come < {$from}) AND ((go = 0) OR (go > {$from})))";
                     }
                 }
             }
             if ($test) {
                 $cond = "(mtype >= {$severity}) AND ({$test})";
             } else {
                 $cond = "(mtype >= {$severity})";
             }
             if ($masktest) {
                 $cond .= " AND ({$masktest})";
             }
             $columns = "messageid, MAX(mtype) AS mtype, MIN(come) AS come, MAX(go) AS go, COUNT(lid) AS count, MIN(go) AS notactive";
             $selopts = array("condition" => $cond, "group" => "messageid");
             $subquery = $this->db->SelectRequest("messagelog", $columns, $selopts);
             $columns = "result.*, messages.name";
             $selopts = array("condition" => "messages.messageid = result.messageid", "order" => "mtype DESC, come ASC");
             $query = $this->db->SelectRequest("({$subquery}) AS result, messages", $columns, $selopts);
     }
     //    echo $query . "\n\n\n";
     //    exit;
     $stmt = $this->db->Prepare($query);
     return new ZEUSAlarms($this, $stmt);
 }
コード例 #4
0
ファイル: reader.php プロジェクト: nicolaisi/adei
 protected function ExportData(DATAHandler $h = NULL, LOGGROUP $grp, MASK $mask, INTERVAL $ivl = NULL, $resample = 0, array &$names, $opts = 0, $dmcb = NULL)
 {
     global $DEFAULT_MISSING_VALUE;
     $dm = new DOWNLOADMANAGER();
     if (!$h) {
         $h = new CSVHandler();
     }
     $filter = $this->CreateDataFilter($grp, $mask, $resample, $ivl->GetItemLimit());
     if (!$h->nullwriter) {
         $filter->AddFilter(new NULLCorrector($this->GetGroupOption($grp, "null_value", $DEFAULT_MISSING_VALUE)));
     }
     $data = $this->GetFilteredData($grp, $ivl->GetWindowStart(), $ivl->GetWindowEnd(), $filter);
     $columns = sizeof($names);
     $h->Start($columns);
     $h->DataHeaders($names);
     if ($dmcb != NULL) {
         $action = "start";
         $current_time = $ivl->GetWindowStart();
         $onepercent = ($ivl->GetWindowEnd() - $ivl->GetWindowStart()) / 100;
         $download = call_user_func_array($dmcb, array($action, ""));
     }
     foreach ($data as $time => $row) {
         $h->DataVector($time, $row);
         if ($dmcb != NULL) {
             $action = "progress";
             $thisupdate = time();
             $updateinterval = $thisupdate - $lastupdate;
             if ($time >= $current_time + $onepercent && $updateinterval >= 2) {
                 $current_time = $time;
                 $lastupdate = time();
                 $prog = round(($time - $ivl->GetWindowStart()) / $onepercent, 0);
                 if (!call_user_func_array($dmcb, array($action, $prog, $download))) {
                     $action = "finish";
                     call_user_func_array($dmcb, array($action, "cancelled"));
                     unset($dmcb);
                     break;
                 }
             }
         }
     }
     if ($dmcb != NULL) {
         $action = "finish";
         call_user_func_array($dmcb, array($action, "", $download));
     }
     $h->End();
 }
コード例 #5
0
ファイル: rrdreader.php プロジェクト: nicolaisi/adei
 public function __construct(RRDReader &$reader, OPTIONS &$opts, &$items, INTERVAL &$ivl, $resample)
 {
     parent::__construct($props);
     $data_start = $opts->Get('data_start');
     $data_start = date("F j, Y", $data_start);
     $this->period = $opts->Get('step');
     $this->file = $reader->rrd_folder . "/" . $reader->rrd_prefix . $opts->Get('file') . ".rrd";
     $this->info = $reader::GetRRDInfo($opts->Get('file'), $reader);
     //get information on the rrd and its archives
     $this->resample = $resample;
     $from = $ivl->GetWindowStart();
     $ifrom = ceil($from);
     //get start point as integer
     $rem = $ifrom % $this->period;
     //checks whether start point as integer is a multiple of period
     if ($rem) {
         $this->from = $ifrom + ($this->period - $rem);
     } else {
         $this->from = $ifrom;
     }
     //if yes, from is ifrom
     $this->pos = $this->from;
     $this->to = $ivl->GetWindowEnd();
     $limit = $ivl->GetItemLimit();
     //get interval's item limit, if any (defines how many datapoints to show and adjusts to or from based on that?)
     if ($limit) {
         if ($limit > 0) {
             $to = $this->from + $this->period * $limit;
             if ($to < $this->to) {
                 $this->to = $to;
             }
         } else {
             $from = $this->to + $this->period * $limit;
             if ($from > $this->from) {
                 $this->from = $from;
             }
         }
     }
     $this->items =& $items;
     //items to show (rra:s in this case)
     //this sets the caching starting point based on the longest rra:s datapoints
     $limit = $opts->GetDateLimit($data_start, time());
     //$limit = $opts->GetDateLimit($this::DEFAULT_START, time());//gets the window limits (as in, the first and last possible timestamp values)
     $this->start = $limit[0];
 }