Example #1
0
 protected function getPayload(Interpreter $interpreter, $tuple)
 {
     try {
         $this->openController();
         $result = false;
         // prevent div by zero
         if (!isset($interpreter->calculated_ts) || $tuple[0] > $interpreter->calculated_ts) {
             $result = $interpreter->convertRawTuple($tuple);
         }
         // 1st calculated value is invalid due to interpreter logic
         if (!isset($interpreter->calculated_ts)) {
             $result = false;
         }
         $interpreter->calculated_ts = $tuple[0];
     } catch (\Exception $e) {
         // make sure EntityManager is re-initialized on error
         $this->openController(true);
         return false;
     }
     return $result;
 }
 protected function convertRawTuple(Interpreter\Interpreter $interpreter, $tuple)
 {
     try {
         $this->openController();
         $result = false;
         // convert raw reading to converted value
         if (!isset($interpreter->push_ts)) {
             // skip first conversion result
             $interpreter->convertRawTuple($tuple);
         } elseif ($tuple[0] > $interpreter->push_ts) {
             // AccumulatorInterpreter special handling- suppress duplicate counter values
             if ($interpreter instanceof Interpreter\AccumulatorInterpreter) {
                 if (isset($interpreter->push_raw_value) && $interpreter->push_raw_value == $tuple[1]) {
                     return false;
                 }
             }
             $result = $interpreter->convertRawTuple($tuple);
         }
         // indicate that tuple conversion has already happened once
         $interpreter->push_ts = $tuple[0];
         $interpreter->push_raw_value = $tuple[1];
     } catch (\Exception $e) {
         // make sure EntityManager is re-initialized on error
         $this->openController(true);
         return false;
     }
     return $result;
 }