Example #1
0
 /**
  * @param string   $sid
  * @param string   $nid
  * @param DateTime $start
  * @param DateTime $end
  * @param int      $resultResolution
  * @param int      $resultAggregation
  * @param bool     $padding
  * @param int      $nodeResolution
  * @param int      $singleNodeAggregation
  * @param int      $combinedNodesAggregation
  * @param bool     $evaluateAsFormula
  * @param int      $formulaResolution
  *
  * @return array
  */
 public function createMultiAction($sid, $nid, DateTime $start, DateTime $end, $resultResolution = Resolution::FIFTEEEN_MINUTES, $resultAggregation = Aggregation::SUM, $padding = false, $nodeResolution = Resolution::FIFTEEEN_MINUTES, $singleNodeAggregation = Aggregation::SUM, $combinedNodesAggregation = Aggregation::SUM, $evaluateAsFormula = false, $formulaResolution = Resolution::FIFTEEEN_MINUTES)
 {
     $start = clone $start;
     $end = clone $end;
     DateTimeHelper::normalizeTimeRange($start, $end, $resultResolution);
     if (is_array($nid) and count($nid) == 1) {
         $nid = $nid[0];
     }
     $sequence = [];
     if (is_array($nid)) {
         $nidSequence = [];
         foreach ($nid as $aNid) {
             $singleNidSequence = [];
             if ($evaluateAsFormula) {
                 $singleNidSequence[] = $this->createFormulaAction($sid, $aNid, $start, $end, $formulaResolution, $padding);
             } else {
                 $singleNidSequence[] = new Find($this->conn, $sid, $aNid, $start, $end);
             }
             $singleNidSequence[] = new RollupTime($nodeResolution, $singleNodeAggregation, $padding);
             $singleNidSequence[] = new Pad($nodeResolution, $start, $end, $padding);
             $nidSequence[] = $singleNidSequence;
         }
         $sequence[] = $nidSequence;
         $sequence[] = new RollupSpace($combinedNodesAggregation, $padding);
     } else {
         if ($evaluateAsFormula) {
             $sequence[] = $this->createFormulaAction($sid, $nid, $start, $end, $formulaResolution, $padding);
         } else {
             $sequence[] = new Find($this->conn, $sid, $nid, $start, $end);
         }
     }
     $sequence[] = new RollupTime($resultResolution, $resultAggregation, $padding);
     $sequence[] = new Pad($resultResolution, $start, $end, $padding);
     return $sequence;
 }
Example #2
0
 /**
  * @param $start      DateTime
  * @param $end        DateTime
  * @param $resolution int
  *
  * Clamps the datetimes down to the nearest resolution step.
  * Also move the end datetime to the next step, so that
  * the entire step is included in the result.
  *
  * @throws InvalidArgumentException
  */
 public static function normalizeTimeRange(&$start, &$end, $resolution)
 {
     if ($resolution == Resolution::MINUTE) {
         $start = DateTimeHelper::clampToMinute($start);
         $end = DateTimeHelper::clampToMinute($end);
         $end->add(DateInterval::createFromDateString('1 minute'));
     } else {
         if ($resolution == Resolution::FIVE_MINUTES) {
             $start = DateTimeHelper::clampToFiveMin($start);
             $end = DateTimeHelper::clampToFiveMin($end);
             $end->add(DateInterval::createFromDateString('5 minutes'));
         } else {
             if ($resolution == Resolution::FIFTEEEN_MINUTES) {
                 $start = DateTimeHelper::clampToFifteenMin($start);
                 $end = DateTimeHelper::clampToFifteenMin($end);
                 $end->add(DateInterval::createFromDateString('15 minutes'));
             } else {
                 if ($resolution == Resolution::HOUR) {
                     $start = DateTimeHelper::clampToHour($start);
                     $end = DateTimeHelper::clampToHour($end);
                     $end->add(DateInterval::createFromDateString('1 hour'));
                 } else {
                     if ($resolution == Resolution::DAY) {
                         $start = DateTimeHelper::clampToDay($start);
                         $end = DateTimeHelper::clampToDay($end);
                         $end->add(DateInterval::createFromDateString('1 day'));
                     } else {
                         throw new InvalidArgumentException('Invalid resolution given');
                     }
                 }
             }
         }
     }
 }
Example #3
0
if (isset($_GET['singleNodeAggregation'])) {
    $singleNodeAggregation = aggregationStrToEnum($_GET['singleNodeAggregation']);
}
if (isset($_GET['combinedNodeAggregation'])) {
    $combinedNodeAggregation = aggregationStrToEnum($_GET['combinedNodeAggregation']);
}
if (isset($_GET['nodeResolution'])) {
    $nodeResolution = resolutionStrToEnum($_GET['nodeResolution']);
}
if (isset($_GET['formulaResolution'])) {
    $formulaResolution = resolutionStrToEnum($_GET['formulaResolution']);
}
$flotData = array();
$start = new DateTime($start);
$end = new DateTime($end);
DateTimeHelper::normalizeTimeRange($start, $end, $resolution);
foreach ($sids as $sid) {
    $sequence = $pipelineFactory->createMultiAction($sid, $nids, $start, $end, $resolution, $aggregation, false, $nodeResolution, $singleNodeAggregation, $combinedNodeAggregation, $asFormula, $formulaResolution);
    $sequence[] = new ConvertToFlotFormat();
    $data = $pipeline->run($sequence);
    $flotData[] = array('data' => $data, 'label' => 'Sensor ' . $sid, 'xaxis' => 1, 'yaxis' => 1);
}
$sequence = $pipelineFactory->createAnomalyAction($start, $end, $nids, $sids, 0, count($nids) * count($nids));
$sequence[] = new AddAnomalyState($start, $end, $resolution);
$res = $pipeline->run($sequence);
$anomalyStates = [];
$anomalies = array();
foreach ($res as $row) {
    $anomalies = array_merge($anomalies, $row['anomalies']);
    foreach ($row['state'] as $timestamp => $state) {
        $anomalyStates[$timestamp] = $state;