Example #1
0
 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];
 }
Example #2
0
 function CreateInterval(REQUEST $req = NULL, $cache_timewindow = false)
 {
     $ivls = array();
     if ($cache_timewindow) {
         if ($req) {
             $iinfo = $req->GetIntervalInfo();
         } else {
             $iinfo = NULL;
         }
         //array();
         //	if (!$req) $req = new DATARequest($args = array());
         foreach ($this as $cachewrap) {
             $cache = $cachewrap->GetCache();
             $ivl = new INTERVAL($iinfo);
             $ivl->ApplyCache($cache);
             $cache->LimitInterval($ivl);
             array_push($ivls, $ivl);
         }
     } else {
         if ($req) {
             $iinfo = $req->GetIntervalInfo();
         } else {
             $iinfo = NULL;
         }
         //array();
         foreach ($this as $cachewrap) {
             $cache = $cachewrap->GetCache();
             array_push($ivls, $cache->CreateInterval($iinfo));
         }
     }
     $ivl = new INTERVAL($iinfo);
     $ivl->ApplyIntervals($ivls);
     return $ivl;
 }
Example #3
0
 function __construct(CACHEDB $cache, MASK $mask, INTERVAL $ivl, $type, $amount, $limit, $resolution, $flags = 0)
 {
     $this->cache =& $cache;
     $this->ids = sizeof($mask->ids);
     $this->ivl =& $ivl;
     $this->mask =& $mask;
     $this->type = $type;
     $this->limit = $limit;
     $this->amount = $amount;
     if ($resolution === false) {
         $this->resolution = $cache->resolution->Get($this->ivl, $this->amount);
     } else {
         $this->resolution = $resolution;
     }
     $this->operation_info = array();
     $this->options = array();
     $this->flags = $flags;
     $resolution = $cache->resolution->GetWindowSize($this->resolution);
     $size = $ivl->GetWindowSize();
     if ($limit) {
         $mingap = $size / $limit;
         if ($resolution) {
             $mingap = ceil($mingap / $resolution) * $resolution;
         }
     } else {
         if ($resolution) {
             $mingap = $resolution;
         } else {
             $mingap = 0;
         }
     }
     $this->expected_gap = $mingap;
     if ($mingap && ($this->flags & CACHE::REPORT_EMPTY || $this->flags & CACHE::MISSING_INFO)) {
         $res = $cache->resolution->Minimal();
         $this->allowed_gap = $cache->resolution->GetWindowSize($res);
     } else {
         $this->allowed_gap = false;
     }
     /*    
         echo $amount . " , " . $limit . "\n";
         echo $mingap . "\n";
         exit;
     */
 }
Example #4
0
 function GetList($search_data, $module, $opts)
 {
     try {
         $ivl = INTERVAL::ParseInterval($search_data);
     } catch (ADEIException $ae) {
         return false;
     }
     list($from, $to) = explode("-", $ivl);
     $title = date("M j, Y H:i:s", $from) . " - " . date("M j, Y H:i:s", $to);
     return array(array('title' => $title, 'props' => array('window' => $ivl), 'description' => false, 'certain' => true));
 }
Example #5
0
 function CreateInterval(LOGGROUP $grp = NULL, array &$iinfo = NULL, $flags = 0)
 {
     $grp = $this->CheckGroup($grp, $flags);
     if (!$iinfo) {
         if ($this->req instanceof DATARequest) {
             $iinfo = $this->req->GetIntervalInfo();
         }
     }
     if ($grp->gid < 0) {
         if (!strcmp($grp->gid, VIRTUALReader::COMPLEX_ID) || !strcmp($grp->gid, VIRTUALReader::SRCTREE_ID)) {
             $req = $this->srctree->GetRequests();
             $ivls = array();
             foreach ($req as $greq) {
                 $rdr = $this->CreateReader($greq);
                 $group = $greq->CreateGroup();
                 array_push($ivls, $rdr->CreateInterval($group, $iinfo));
                 unset($reader);
             }
             $ivl = new INTERVAL($iinfo);
             $ivl->ApplyIntervals($ivls);
             return $ivl;
         }
     }
     $req = $this->srctree->GetGroupRequest($grp, $mask);
     $rdr = $this->CreateReader($req);
     $group = $rdr->CreateGroup();
     $ivl = $rdr->CreateInterval($group, $iinfo);
     $this->req->LimitInterval($ivl, $group);
     return $ivl;
 }
Example #6
0
    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;
    }
Example #7
0
 function GetNeighbors(MASK $mask = NULL, $x, $amount = false, $flags = 0)
 {
     if (!$mask) {
         $mask = $this->CreateMask();
     }
     if ($this->base_mask) {
         $mask = $this->base_mask->Superpose($mask);
     }
     $ivl = new INTERVAL();
     $ivl->SetupWindow(INTERVAL::WINDOW_LEFT, $x);
     $left = array();
     $d = new RAWPoint($this, $mask, $ivl, $amount === false ? 1 : $amount);
     foreach ($d as $tm => $val) {
         $left[$tm] = $val;
     }
     $ivl->SetupWindow(INTERVAL::WINDOW_RIGHT, $x);
     $right = array();
     $d = new RAWPoint($this, $mask, $ivl, $amount === false ? 1 : $amount);
     foreach ($d as $tm => $val) {
         $right[$tm] = $val;
     }
     return array('left' => &$left, 'right' => &$right);
 }
Example #8
0
 function CreateCacheInterval($postfix = false, array &$iinfo = NULL, $flags = 0)
 {
     if (!is_array($iinfo)) {
         if ($this->req instanceof DATARequest) {
             $iinfo = $this->req->GetIntervalInfo();
         }
     }
     $ivl = new INTERVAL($iinfo, NULL, NULL, $flags);
     $ivl->ApplyCache($this);
     return $ivl;
 }
Example #9
0
<?php

require "../../adei.php";
$unit_tests = array("2005" => "1104537600-1136073600", "2005-2007" => "1104537600-1199145600", "Dec, 2007" => "1196467200-1199145600", "Oct-november, 2007" => "1191196800-1196467200", "Nov. 25, 2007" => "1195948800-1196035200", "February 23 - 24, 2005" => "1109116800-1109289600", "21 Feb., 2003" => "1045785600-1045872000", "21 -24 Feb, 2003" => "1045785600-1046131200", "25 Feb, 2003" => "1046131200-1046217600", "2003, Feb - March" => "1044057600-1049155200", "2003, Feb." => "1044057600-1046476800", "2003, Feb. 24-25" => "1046044800-1046217600", "Feb 23, 2008  15:00 - 17:00" => "1203778800-1203786000", "Feb 23, 2008.  15 - 17" => "1203778800-1203786000", "Feb 23, 2008.  15 - 17" => "1203778800-1203786000", "2008, Feb 23;  15 - 17" => "1203778800-1203786000", "17:00:00 - 19:05:01 25 Feb, 2003" => "1046192400-1046199901", "Feb 23, 2008 + 1d" => "1203724800-1203811200", "Feb 23, 2008 + 30 min" => "1203724800-1203726600", "1203724800-1203726600" => "1203724800-1203726600", "1203724800.1-1203726600.3" => "1203724800.1-1203726600.3", "20080103T200000-20080503T203000" => "1199390400-1209846600", "Feb 23, 2008 - Mar 25, 2009" => "1203724800-1237939200");
#date_default_timezone_set("GMT");
foreach ($unit_tests as $var => $res) {
    $ivl = INTERVAL::ParseInterval($var);
    if (strcmp($ivl, $res)) {
        echo "Failed: {$var} => {$res}\n";
        echo "Got: {$ivl}\n";
        exit;
    }
}
echo "All tests passed\n";
exit;
$var = "February 23 - 24, 2005";
#$a = new DateInterval($var);
$a = new DateTime($var);
$ts = $a->format("U.u");
echo date("c", $ts);
Example #10
0
 public function __construct($value)
 {
     parent::__construct(INTERVAL::ParseInterval($value));
 }
Example #11
0
 static function ParseInterval($str)
 {
     $month = "(Jan(uary|\\.)?|Feb(ruary|\\.)?|Mar(ch|\\.)?|Apr(il|\\.)?|May(\\.)?|Jun(e|\\.)?|Jul(y|\\.)?|Aug(ust|\\.)?|Sep(tember|\\.)?|Oct(ober|\\.)?|Nov(ember|\\.)?|Dec(ember|\\.)?)";
     $year = "(\\d{4})";
     $day = "(\\b\\d{1,2}\\b)";
     $plus = "\\+\\s*(?<plus_value>\\d+)\\s*(?<plus_units>(s|sec|second|seconds|m|min|minute|minutes|h|hour|hours|d|day|days)\\.?)?";
     $timesep = ":";
     $time = "\\d{1,2}({$timesep}\\d{1,2}({$timesep}\\d{1,2})?)?";
     $timestamp = "[\\d.]+";
     $space = "\\s*";
     $dash = "{$space}-{$space}";
     $hcomma = "[\\s,;.T]+";
     $ycomma = "[\\s,;]+";
     $dcomma = "[\\s,;]+";
     if (preg_match("/^{$space}(?<year>{$year}){$space}\$/", $str, $m)) {
         // 2008
         list($from, $to, $duration) = INTERVAL::PICalc($str, $m['year']);
     } else {
         if (preg_match("/^{$space}(?<year1>{$year}){$dash}(?<year2>{$year}){$space}\$/", $str, $m)) {
             // 2006 - 2008
             list($from, $to, $duration) = INTERVAL::PICalc($str, $m['year1'], $m['year2']);
         } else {
             if (preg_match("/^{$space}(?<from>{$timestamp}){$space}-{$space}(?<to>{$timestamp}){$space}\$/", $str, $m)) {
                 if (!is_numeric($m['from']) || !is_numeric($m['to'])) {
                     throw new ADEIException(translate("Invalid interval (%s) is specified", $str));
                 }
                 if ($m['from'] > $m['to']) {
                     throw new ADEIException(translate("Invalid interval (%s) is specified: Start is above the end", $str));
                 }
                 return "{$m['from']}-{$m['to']}";
             } else {
                 if (preg_match("/^{$space}(?<month>{$month})({$ycomma}(?<year>{$year}))?{$space}\$/i", $str, $m)) {
                     // Feb., 2008
                     list($from, $to, $duration) = INTERVAL::PICalc($str, $m['year'], false, $m['month']);
                 } else {
                     if (preg_match("/^{$space}(?<month1>{$month}){$dash}(?<month2>{$month})({$ycomma}(?<year>{$year}))?{$space}\$/i", $str, $m)) {
                         // Feb. - Mar. 2008
                         list($from, $to, $duration) = INTERVAL::PICalc($str, $m['year'], false, $m['month1'], $m['month2']);
                     } else {
                         if (preg_match("/^{$space}(?<month>{$month}){$dcomma}(?<day>{$day})({$ycomma}(?<year>{$year}))?({$hcomma}(?<time1>{$time}){$space}-{$space}(?<time2>{$time}))?{$space}\$/i", $str, $m)) {
                             // Feb 21, 2008 15:00 - 17:00
                             list($from, $to, $duration) = INTERVAL::PICalc($str, $m['year'], false, $m['month'], false, $m['day'], false, $m['time1'], $m['time2']);
                         } else {
                             if (preg_match("/^{$space}(?<month>{$month}){$dcomma}(?<day1>{$day}){$dash}(?<day2>{$day})({$ycomma}(?<year>{$year}))?{$space}\$/i", $str, $m)) {
                                 // Feb 21 - 23, 2008
                                 list($from, $to, $duration) = INTERVAL::PICalc($str, $m['year'], false, $m['month'], false, $m['day1'], $m['day2']);
                             } else {
                                 if (preg_match("/^{$space}((?<time1>{$time}){$space}-{$space}(?<time2>{$time}){$hcomma})?(?<day1>{$day})({$dash}(?<day2>{$day}))?{$dcomma}(?<month>{$month})({$ycomma}(?<year>{$year}))?{$space}\$/i", $str, $m)) {
                                     // 21 - 23 Feb 2008 , 21 Feb 2008, 15:00:00 - 16:00:01 21 Feb 2008
                                     list($from, $to, $duration) = INTERVAL::PICalc($str, $m['year'], false, $m['month'], false, $m['day1'], $m['day2'], $m['time1'], $m['time2']);
                                 } else {
                                     if (preg_match("/^{$space}((?<year>{$year}){$ycomma})?(?<month1>{$month})({$dash}(?<month2>{$month}))?{$space}\$/i", $str, $m)) {
                                         // 2008, Feb. - Mar.
                                         list($from, $to, $duration) = INTERVAL::PICalc($str, $m['year'], false, $m['month1'], $m['month2']);
                                     } else {
                                         if (preg_match("/^{$space}((?<year>{$year}){$ycomma})?(?<month>{$month}){$dcomma}(?<day1>{$day})(({$dash}(?<day2>{$day}))|({$hcomma}(?<time1>{$time}){$space}-{$space}(?<time2>{$time})))?{$space}\$/i", $str, $m)) {
                                             // 2008, Feb 21 - 23     2008, Feb 21 15:00 - 17:00
                                             list($from, $to, $duration) = INTERVAL::PICalc($str, $m['year'], false, $m['month'], false, $m['day1'], $m['day2'], $m['time1'], $m['time2']);
                                         } else {
                                             if (preg_match("/^{$space}(?<from>.*){$plus}?{$space}\$/i", $str, $m)) {
                                                 // <date> +<duration>
                                                 $from = $m['from'];
                                                 $duration = $m['plus_value'];
                                                 switch (strtolower(substr($m['plus_units'], 0, 1))) {
                                                     case "m":
                                                         $duration *= 60;
                                                         break;
                                                     case "h":
                                                         $duration *= 3600;
                                                         break;
                                                     case "d":
                                                         $duration *= 86400;
                                                         break;
                                                 }
                                             } else {
                                                 if (substr_count($str, "-") == 1) {
                                                     $divider = "-";
                                                 } else {
                                                     if (preg_match_all("/\\s-\\s/", $str, $m) == 1) {
                                                         $divider = "\\s+-\\s+";
                                                     } else {
                                                         throw new ADEIException(translate("Unreckognized interval (%s) is specified", $str));
                                                     }
                                                 }
                                                 list($from, $to) = preg_split("/{$divider}/", $str);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     #    echo "$from - $to + $duration\n";
     try {
         $fdate = new DateTime($from);
         if ($to) {
             $tdate = new DateTime($to);
         } else {
             $tdate = new DateTime($from);
         }
     } catch (Exception $e) {
         throw new ADEIException(translate("Unreckognized interval (%s) is specified", $str));
     }
     $from = $fdate->format("U");
     $to = $tdate->format("U") + $duration;
     if ($from > $to) {
         throw new ADEIException(translate("Invalid interval (%s) is specified: Start is above the end", $str));
     }
     return "{$from}-{$to}";
 }
Example #12
0
 function LimitInterval(INTERVAL $ivl, LOGGROUP $grp = NULL)
 {
     $opts = $this->GetGroupOptions($grp);
     $limits = $opts->GetDateLimit();
     $ivl->Limit($limits[0], $limits[1]);
 }
Example #13
0
 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();
 }
Example #14
0
 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);
 }
Example #15
0
 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];
 }
Example #16
0
 function GetName(READER $rdr = NULL, LOGGROUP $grp = NULL, MASK $msk = NULL, INTERVAL $ivl = NULL)
 {
     $name = "";
     if (!$this->multirdr && $rdr) {
         $name .= $rdr->srvid . "__" . $rdr->dbname;
     }
     if (!$this->multigroup && $grp) {
         $name .= ($name ? "__" : "") . $grp->gid;
     }
     if (!$this->multimask && $msk) {
         $name .= ($name ? "__" : "") . $msk->name;
     }
     if (!$this->multiivl) {
         if (!$ivl || $ivl->IsEmpty()) {
             $ivl = $this->req->CreateInterval();
         }
         $name .= ($name ? "__" : "") . $ivl->GetName(NAME_FORMAT_ISO8601);
     }
     if ($name) {
         return $name;
     }
     return "adei_data";
 }