Example #1
0
 public function execute($_options = null)
 {
     switch ($this->getType()) {
         case 'info':
             if ($this->getConfiguration('virtualAction', 0) == '0') {
                 $calcul = cmd::cmdToValue($this->getConfiguration('calcul'));
                 $test = new evaluate();
                 $result = $test->Evaluer($calcul);
                 if ($this->getSubType() == 'binary') {
                     if ($result) {
                         return 1;
                     } else {
                         return 0;
                     }
                 }
                 if (is_numeric($result)) {
                     return number_format($result, 2);
                 } else {
                     return $result;
                 }
             } else {
                 return $this->getConfiguration('value');
             }
             break;
         case 'action':
             $virtualCmd = virtualCmd::byId($this->getConfiguration('infoId'));
             if (!is_object($virtualCmd)) {
                 throw new Exception('Virtual info commande non trouvé, verifier ID');
             }
             if ($virtualCmd->getEqLogic()->getEqType_name() != 'virtual') {
                 throw new Exception('La cible de la commande virtuel n\'est pas un équipement de type virtuel');
             }
             if ($this->getSubType() == 'slider') {
                 $value = $_options['slider'];
             } else {
                 if ($this->getSubType() == 'color') {
                     $value = $_options['color'];
                 } else {
                     $value = $this->getConfiguration('value');
                 }
             }
             $virtualCmd->setConfiguration('value', $value);
             $virtualCmd->save();
             $virtualCmd->event($value);
             break;
     }
 }
 public function event($_value, $_loop = 1)
 {
     if ($this->getLogicalId() == 'nbimpulsionminute') {
         try {
             $calcul = $this->getConfiguration('calcul');
             $calcul = preg_replace("/#brut#/", $_value, $calcul);
             $calcul = scenarioExpression::setTags($calcul);
             $test = new evaluate();
             $result = $test->Evaluer($calcul);
             parent::event($result, $_loop);
         } catch (Exception $e) {
             $EqLogic = $this->getEqLogic();
             log::add('ipx800', 'error', $EqLogic->getName() . " error in " . $this->getConfiguration('calcul') . " : " . $e->getMessage());
             return scenarioExpression::setTags(str_replace('"', '', cmd::cmdToValue($this->getConfiguration('calcul'))));
         }
     } else {
         parent::event($_value, $_loop);
     }
 }
Example #3
0
 public function getData($_startDate = null, $_endDate = null)
 {
     $nowtime = floatval(strtotime(date('Y-m-d H:i:s') . " UTC"));
     $now = strtotime(date('Y-m-d H:i:s'));
     $archiveTime = (config::byKey('historyArchiveTime') + 1) * 3600;
     $packetTime = config::byKey('historyArchivePackage') * 3600;
     $return = array('history' => array('power' => array(), 'consumption' => null), 'stats' => array('minPower' => null, 'maxPower' => null), 'real' => array('power' => 0, 'consumption' => 0));
     $cmd_histories = array();
     preg_match_all("/#([0-9]*)#/", $this->getPower(), $matches);
     foreach ($matches[1] as $cmd_id) {
         if (is_numeric($cmd_id)) {
             $cmd = cmd::byId($cmd_id);
             if (is_object($cmd) && $cmd->getIsHistorized() == 1) {
                 $prevDatetime = null;
                 $prevValue = 0;
                 foreach ($cmd->getHistory($_startDate, $_endDate) as $history) {
                     if (!isset($cmd_histories[$history->getDatetime()])) {
                         $cmd_histories[$history->getDatetime()] = array();
                     }
                     if (!isset($cmd_histories[$history->getDatetime()]['#' . $cmd_id . '#'])) {
                         if ($prevDatetime != null) {
                             $datetime = strtotime($history->getDatetime());
                             while ($now - strtotime($prevDatetime) > $archiveTime && strtotime($prevDatetime) < $datetime) {
                                 $prevDatetime = date('Y-m-d H:00:00', strtotime($prevDatetime) + $packetTime);
                                 $cmd_histories[$prevDatetime]['#' . $cmd_id . '#'] = 0;
                             }
                             while ($now - strtotime($prevDatetime) > 300 && strtotime($prevDatetime) < $datetime) {
                                 $prevDatetime = date('Y-m-d H:i:00', strtotime($prevDatetime) + 300);
                                 $cmd_histories[$prevDatetime]['#' . $cmd_id . '#'] = $prevValue;
                             }
                         }
                         if (strtotime($history->getDatetime()) <= $now) {
                             $cmd_histories[$history->getDatetime()]['#' . $cmd_id . '#'] = $history->getValue();
                         }
                     }
                     $prevDatetime = $history->getDatetime();
                     $prevValue = $history->getValue();
                 }
             }
         }
     }
     foreach ($cmd_histories as $datetime => $cmd_history) {
         $datetime = floatval(strtotime($datetime . " UTC"));
         $calcul = template_replace($cmd_history, $this->getPower());
         try {
             if ($datetime <= $nowtime) {
                 $test = new evaluate();
                 $result = floatval($test->Evaluer($calcul));
                 if ($this->getConsumption() == '' && count($return['history']['power']) > 0) {
                     $last_datetime = end(array_keys($return['history']['power']));
                     if ($datetime - $last_datetime > 0) {
                         $last_value = end($return['history']['power']);
                         $return['history']['consumption'][$datetime] = array($datetime, $last_value[1] * (($datetime - $last_datetime) / 1000) / 3600);
                         $return['real']['consumption'] += $return['history']['consumption'][$datetime][1];
                     }
                 }
                 $return['history']['power'][$datetime] = array($datetime * 1000, $result);
                 if ($return['stats']['minPower'] === null || $return['stats']['minPower'] > $result) {
                     $return['stats']['minPower'] = $result;
                 }
                 if ($return['stats']['maxPower'] === null || $return['stats']['maxPower'] < $result) {
                     $return['stats']['maxPower'] = $result;
                 }
             }
         } catch (Exception $e) {
         }
     }
     if ($this->getConsumption() == '' && count($return['history']['power']) > 0) {
         $last_datetime = end(array_keys($return['history']['power']));
         $last_value = end($return['history']['power']);
         if ($datetime - $last_datetime > 0) {
             $return['history']['consumption'][$datetime] = array($datetime * 1000, $last_value[1] * (($nowtime - $last_datetime) / 1000) / 3600);
             $return['real']['consumption'] += $return['history']['consumption'][$datetime][1];
         }
     }
     $calcul = cmd::cmdToValue($this->getPower());
     try {
         $test = new evaluate();
         $result = floatval($test->Evaluer($calcul));
         $return['real']['power'] = $result;
         $return['history']['power'][$nowtime] = array($nowtime * 1000, $result);
     } catch (Exception $e) {
     }
     if ($this->getConsumption() != '') {
         $cmd_histories = array();
         preg_match_all("/#([0-9]*)#/", $this->getConsumption(), $matches);
         foreach ($matches[1] as $cmd_id) {
             if (is_numeric($cmd_id)) {
                 $cmd = cmd::byId($cmd_id);
                 if (is_object($cmd) && $cmd->getIsHistorized() == 1) {
                     $prevDatetime = null;
                     foreach ($cmd->getHistory($_startDate, $_endDate) as $history) {
                         if (!isset($cmd_histories[$history->getDatetime()])) {
                             $cmd_histories[$history->getDatetime()] = array();
                         }
                         if (!isset($cmd_histories[$history->getDatetime()]['#' . $cmd_id . '#'])) {
                             if ($prevDatetime != null) {
                                 $datetime = strtotime($history->getDatetime());
                                 while ($now - strtotime($prevDatetime) > $archiveTime && strtotime($prevDatetime) < $datetime) {
                                     $prevDatetime = date('Y-m-d H:00:00', strtotime($prevDatetime) + $packetTime);
                                     $cmd_histories[$prevDatetime]['#' . $cmd_id . '#'] = 0;
                                 }
                                 while ($now - strtotime($prevDatetime) < 300 && strtotime($prevDatetime) < $datetime) {
                                     $prevDatetime = date('Y-m-d H:00:00', strtotime($prevDatetime) + 300);
                                     $cmd_histories[$prevDatetime]['#' . $cmd_id . '#'] = $prevValue;
                                 }
                             }
                             if (strtotime($history->getDatetime()) <= $now) {
                                 $cmd_histories[$history->getDatetime()]['#' . $cmd_id . '#'] = $history->getValue();
                             }
                         }
                         $prevDatetime = $history->getDatetime();
                         $prevValue = $history->getValue();
                     }
                 }
             }
         }
         foreach ($cmd_histories as $datetime => $cmd_history) {
             $datetime = floatval(strtotime($datetime . " UTC"));
             $calcul = template_replace($cmd_history, $this->getConsumption());
             try {
                 if ($datetime <= $nowtime) {
                     $test = new evaluate();
                     $result = floatval($test->Evaluer($calcul));
                     $return['history']['consumption'][$datetime] = array($datetime * 1000, $result);
                 }
             } catch (Exception $e) {
             }
         }
         $calcul = cmd::cmdToValue($this->getConsumption());
         try {
             $test = new evaluate();
             $result = floatval($test->Evaluer($calcul));
             $return['real']['consumption'] = $result;
             $return['history']['consumption'][$nowtime] = array($nowtime * 1000, $result);
         } catch (Exception $e) {
         }
     }
     if (is_array($return['history']['consumption'])) {
         ksort($return['history']['consumption']);
     }
     if (is_array($return['history']['power'])) {
         ksort($return['history']['power']);
     }
     return $return;
 }
Example #4
0
 public function execute($_options = null)
 {
     $jeenode = $this->getEqLogic();
     $jeenodeReal = $jeenode->getEqReal();
     $mode = $this->getConfiguration('mode');
     $typeCmd = $this->getConfiguration('type');
     $port = $jeenode->getLogicalId();
     if ($jeenode->getLogicalId() == 'I2C') {
         if ($typeCmd == 'c' && $_options != null) {
             $rgb = self::hex2rgb($_options['color']);
             $request = new com_http($jeenodeReal->getHttpHeader() . '&t=' . $typeCmd . '&m=' . $mode . '&p=5&v=' . $rgb[0] . '&v1=' . $rgb[1] . '&v2=' . $rgb[2]);
             return $request->exec();
         }
     } else {
         $value = '';
         if ($typeCmd == 'p' && $_options != null) {
             $value = $_options['slider'] / 100 * 255;
         }
         if ($_options === null && $this->getConfiguration('value') != '') {
             $value = $this->getConfiguration('value');
         }
         $request = new com_http($jeenodeReal->getHttpHeader() . '&t=' . $typeCmd . '&m=' . $mode . '&p=' . $port . '&v=' . $value);
         $result = $request->exec();
         if ($result == 'NR') {
             throw new Exception('Erreur lors de la recuperation d\'information ' . $jeenode->getName() . ' (' . $jeenodeReal->getName() . '). Retour jeenode : ' . $result);
         }
         if ($this->getType() == 'info' && $this->getConfiguration('calcul') != '') {
             $returnValue = intval($result);
             $calcul = str_replace('#V#', $returnValue, $this->getConfiguration('calcul'));
             $test = new evaluate();
             $result = $test->Evaluer($calcul);
         }
         $jeenodeReal->updateLastCommunication();
         if ($this->getType() == 'action' && $_options != null && $result != $value) {
             throw new Exception('Erreur lors de l\'éxécution de l\'action sur ' . $jeenode->getName() . ' (' . $jeenodeReal->getName() . '). Retour jeenode : ' . $result);
         }
         return $result;
     }
 }
Example #5
0
    if (!$it) {
        api::response(500, "test history not found");
        die;
    }
    if ($type_is_student) {
        $t = reset($tests);
        $tests = array($t);
        break;
    }
} while (!is_null($testid));
if ($type_is_student) {
    $e = evaluate::student($tests, $ot, THRES_STUDENT, array(3, 2));
    $ot->set_alphalist();
    $data = $ot->results_student($e);
} else {
    $e = evaluate::teacher($tests, $ot, THRES_TEACHER);
    $ot->set_alphalist();
    $data = $ot->results_teacher($e);
}
if ((int) $save != 1) {
    api::response(200, "OK", $data);
} else {
    $systime = time();
    $timestamp = date('YmdHis', $systime);
    $basename = $user . "_" . date('Ymd_H_i_s', $systime) . "_result_" . $type;
    $xmlname = $basename . ".xml";
    $data->save(DIR_TMP . "/" . $xmlname);
    $dom = new DomDocument('1.0', 'UTF-8');
    $dom->appendChild($dom->createElement('data', $basename));
    api::response(200, "OK", $dom);
}