Пример #1
0
 public static function getInstance()
 {
     if (!self::$WQDStackDataStore) {
         self::$WQDStackDataStore = new WQDStackDataStore();
         return self::$WQDStackDataStore;
     }
     return self::$WQDStackDataStore;
 }
 public function Save(HighValueRule $highValueRule)
 {
     try {
         $SQL = self::$INSERT;
         if ($highValueRule->getSeq() != null && $highValueRule->getSeq() != "" && $highValueRule->getSeq() > 0) {
             $SQL = self::$UPDATE;
         }
         $conn = self::$db->getConnection();
         $stmt = $conn->prepare($SQL);
         $stmt->bindValue(':folderseq', $highValueRule->getFolderSeq());
         $stmt->bindValue(':email', $highValueRule->getEmail());
         $stmt->bindValue(':mobile', $highValueRule->getMobile());
         $stmt->bindValue(':parameterchannelno', $highValueRule->getParameter());
         $stmt->bindValue(':highvalue', $highValueRule->getHighValue());
         $stmt->bindValue(':frequency', $highValueRule->getFrequency());
         $isActive = 0;
         if ($highValueRule->getIsActive() == "true" || $highValueRule->getIsActive() == 1) {
             $isActive = 1;
         }
         $stmt->bindValue(':isactive', $isActive);
         $stmt->bindValue(':rulehits', $highValueRule->getRuleHits());
         $type = $highValueRule->getStationType();
         $maxSeq = $highValueRule->getLastRuleHitFileDataSeq();
         $seq = $highValueRule->getSeq();
         if (empty($seq)) {
             if ($type == "stack" || $type == "effluent") {
                 $wqdsds = WQDStackDataStore::getInstance();
                 $maxSeq = $wqdsds->getMaxSeq();
             } else {
                 $WQDDS = WQDDataDataStore::getInstance();
                 $maxSeq = $WQDDS->getMaxSeq();
             }
         }
         $highValueRule->setLastRuleHitFileDataSeq($maxSeq);
         //$stmt->bindValue(':lastrulehitwqdfiledataseq',$maxSeq);
         $stmt->bindValue(':lastrulehitwqdfiledataseq', $highValueRule->getLastRuleHitFileDataSeq());
         if ($SQL == self::$UPDATE) {
             $stmt->bindValue(':seq', $highValueRule->getSeq());
         } else {
             $stmt->bindValue(':rulestartwqdfiledataseq', $maxSeq);
         }
         $stmt->execute();
         $error = $stmt->errorInfo();
         if ($error[2] != "") {
             throw new Exception($error[2]);
         }
     } catch (Exception $e) {
         $logger = Logger::getLogger($ConstantsArray["logger"]);
         $logger->error("Error During Save High Value Rule : - " . $e->getMessage());
     }
 }
 private function getDataJSON($fromDate, $toDate, $folSeq, $timeInterval, $channelNoArr, $periodType, $exemptions, $stationType)
 {
     if (strpos($timeInterval, 'hours') !== false) {
         $timeInterval = "1hour";
     }
     $CCDS = ChannelConfigurationDataStore::getInstance();
     $ChannelsInfo = $CCDS->FindByFolderAndChannelNos($folSeq, $channelNoArr);
     $chArr = new ArrayObject();
     $chNumbersArr = array();
     foreach ($ChannelsInfo as $channel) {
         $channelUnit = $channel->getChannelUnit();
         $channelName = $channel->getChannelName();
         if (ConvertorUtils::getPrescribedUnit($channelName) != null) {
             $channelUnit = ConvertorUtils::getPrescribedUnit($channelName);
         }
         $channelUnit = mb_check_encoding($channelUnit, 'UTF-8') ? $channelUnit : utf8_encode($channelUnit);
         $chArr[$channelName] = $channelUnit;
         array_push($chNumbersArr, $channel->getChannelNumber());
     }
     $jsonData['channels'] = $chArr;
     $WQDS = WQDDataDataStore::getInstance();
     $WQDStackDS = WQDStackDataStore::getInstance();
     $allDatesData = array();
     $dataArray = null;
     //make special stack call here to the different datastore with same api structure
     $dataArray = null;
     if ($stationType == "stack" || $stationType == "effluent") {
         $dataArray = $WQDStackDS->getChannels($fromDate, $toDate, $folSeq, $channelNoArr, $timeInterval);
     } else {
         $dataArray = $WQDS->getChannels($fromDate, $toDate, $folSeq, $channelNoArr, $timeInterval);
     }
     foreach ($dataArray as $data) {
         $channelData = array();
         $dated = $data['wqdfiledatadated'];
         $chValues = array();
         $chStatuses = array();
         $cnt = (count($data) - 2) / 4;
         // divided by 2 becos array produces both channelname and int values
         for ($i = 0; $i < $cnt; $i++) {
             $vl = (double) $data["ch" . $channelNoArr[$i] . "value"];
             if ($vl < 0 || $vl == NULL) {
                 $vl = "n.o";
             }
             $isDateExempted = false;
             foreach ($exemptions as $exem) {
                 $exemption = new Exemption();
                 $exemption = $exem;
                 $isDateExempted = DateUtils::isDateInBetween($exemption->getFromDateRange(), $exemption->getToDateRange(), $dated);
                 if ($isDateExempted) {
                     $chNo = $channelNoArr[$i];
                     $exemptedChannelsNos = $exemption->getChannelNumbers();
                     if (in_array($chNo, $exemptedChannelsNos)) {
                         $vl = StringUtils::$exemptedString;
                     }
                 }
             }
             array_push($chValues, $vl);
             array_push($chStatuses, (double) $data["ch" . $channelNoArr[$i] . "status"]);
         }
         //$channelData['values'] = $chValues;
         $allDatesData[strtotime($dated)]['channelValue'] = $chValues;
         $allDatesData[strtotime($dated)]['channelStatuses'] = $chStatuses;
         //array_push($allDatesData,$channelData);
     }
     $jsonData['data'] = $allDatesData;
     return $jsonData;
 }
Пример #4
0
require_once $ConstantsArray['dbServerUrl'] . "/Utils/DropDownUtils.php";
require_once $ConstantsArray['dbServerUrl'] . "/DataStoreMgr/LocationDataStore.php";
require_once $ConstantsArray['dbServerUrl'] . "/BusinessObjects/Folder.php";
require_once $ConstantsArray['dbServerUrl'] . "/DataStoreMgr/ChannelConfigurationDataStore.php";
require_once $ConstantsArray['dbServerUrl'] . "/DataStoreMgr/WQDStackDataStore.php";
require_once $ConstantsArray['dbServerUrl'] . "/DataStoreMgr/WQDFileDataStore.php";
//$configuration = new Configuration();
Session_start();
$managerSession = $_SESSION["managerSession"];
$userDataStore = UserDataStore::getInstance();
$userSeq = $managerSession['seq'];
$locSeq = $managerSession['locSeq'];
$FDS = FolderDataStore::getInstance();
$CDS = ChannelConfigurationDataStore::getInstance();
$LDS = LocationDataStore::getInstance();
$WSDS = WQDStackDataStore::getInstance();
$WFDS = WQDFileDataStore::getInstance();
$locationSeqs = $LDS->FindLocationsByUser($userSeq);
if (!in_array($locSeq, $locationSeqs)) {
    array_push($locationSeqs, $locSeq);
}
$folders = $FDS->FindByLocation(implode(",", $locationSeqs));
$isdataExist = false;
$folder = new Folder();
$channlConfigs = array();
$selSeq = 0;
$errMsg = "";
$msg = "";
$disabledChNo = "disabled";
if ($_POST["call"] == "delete") {
    $seq = $_POST["delSeq"];
 public function SaveSyncedWQDStackData($jsonString, $folderSeqs, $lastSynchDates)
 {
     $arr = json_decode($jsonString);
     $fileDataObjArr = array();
     $WQDSDS = WQDStackDataStore::getInstance();
     $FDS = FolderDataStore::getInstance();
     $message = "";
     $onlineStations = array_fill_keys(array_values($folderSeqs), 0);
     foreach ($arr as $key => $value) {
         $stationCode = $value->siteCode;
         $folderSeq = $folderSeqs[$stationCode];
         try {
             $onlineStations[$folderSeq] = 1;
             echo "<br/><br/>Station Code :- " . $stationCode;
             var_dump($value);
             $channels = $value->parameters;
             $data = $value->data;
             $lastSyncDb = $lastSynchDates[$folderSeq];
             $count = count($data);
             echo " Rows found :- " . $count;
             if ($count == 1) {
                 $now = $this->getPast90MinTime();
                 $sdate = DateTime::createFromFormat('d-m-Y H:i:s', $lastSyncDb);
                 if ($lastSyncDb == $data[0]->Key && $sdate < $now) {
                     $this->updateLastSyncedOnWithAdd90Min($lastSyncDb, $folderSeq);
                     continue;
                 }
             }
             $chNoArr = $this->getChannelNumbers($value, $folderSeq);
             $syncDate = "";
             $fileDataObjArr = array();
             foreach ($data as $key => $val) {
                 $valueArr = $val->Value;
                 $syncdate = $val->Key;
                 $fileDataObj = $this->getFileDataObj($syncdate, $folderSeq);
                 $chValueStatusArr = array();
                 $i = 0;
                 foreach ($channels as $ch) {
                     $index = $chNoArr[$ch];
                     $chValueStatusArr[$index] = $valueArr[$i];
                     $i++;
                 }
                 $fileDataObj->setChannels($chValueStatusArr);
                 array_push($fileDataObjArr, $fileDataObj);
             }
             $WQDSDS->saveSyncedData($fileDataObjArr, true);
         } catch (Exception $e) {
             $message .= "Error During M2MSynchronizer for SiteCode " . $stationCode . " : -" . $e->getMessage() . "<br/>";
             $logger = Logger::getLogger("myDBLogger");
             $logger->error($message);
             $FDS->updateIsEnable($folderSeq, 0);
         }
     }
     if (!empty($message)) {
         MailerUtils::sendError($message, "Error During M2MSynchronizer");
     }
     $M2MDs = M2MSynchronizerDataStore::getInstance();
     foreach ($onlineStations as $folderSeq => $isOnline) {
         $FDS->updateIsOnline($folderSeq, $isOnline);
         $lastSyncDate = $lastSynchDates[$folderSeq];
         $sdate = DateTime::createFromFormat('d-m-Y H:i:s', $lastSyncDate);
         $now = $this->getPast90MinTime();
         if ($sdate < $now) {
             $this->updateLastSyncedOnWithAdd90Min($lastSyncDate, $folderSeq);
         }
     }
 }
Пример #6
0
     } elseif (strtoupper($fileType) == "WAD" && $folder->getLocationSeq() == 10) {
         echo "\n" . "Parsing WAD of APPCB file";
         //this case of APPCB exponential files
         $WQDDataArray = ParserWADAPPCB::parse($value, $folder->getSeq());
     } elseif (strtoupper($fileType) == "LSI") {
         //this case of AMBUJA lsi files for stack folders
         $WQDDataArray = ParserStackLsi::parse($value, $folder->getSeq());
     } elseif (strtoupper($fileType) == "TXT" && ($folder->getSeq() == 48 || $folder->getSeq() == 49)) {
         //this case of Bhoomi instruments first parser
         $WQDDataArray = ParserBhoomiFiles::parse($value, $folder->getSeq());
     } else {
         $WQDDataArray = ParserWQD::parseWQD($value, $folder->getSeq());
     }
     if ($WQDDataArray != null) {
         if ($folder->getStationType() == "stack" || $folder->getStationType() == "effluent") {
             $WDSD = WQDStackDataStore::getInstance();
             $WDSD->saveSyncedData($WQDDataArray);
             echo "\n" . date("Y-m-d  H:i:s") . " Stack File Saved Successfully";
         } else {
             $WDD = WQDDataDataStore::getInstance();
             $WDD->SaveList($WQDDataArray);
             echo "\n" . date("Y-m-d  H:i:s") . " AQMS File Saved Successfully";
             if ($status != null) {
                 echo "\n Status from save call" . $status;
             }
         }
         unlink($value);
         unset($WQDDataArray);
         unset($wqdFile);
     }
 } catch (Exception $e) {