public static function parse($filePath, $folderSeq) { //$content = file("../files/AQMS.WQD"); //$folderSeq = 9; //$filePath = "G:/accgagal.txt"; $content = file($filePath); $numLines = count($content); $lineRow = 0; for ($i = 0; $i < $numLines; $i++) { if (trim($content[$i]) == "") { } else { $lineRow = $i; $i = $numLines; } } $arrayCount = 0; $WQDDataArray = new ArrayObject(); $numLines = count($content); $lineRow = 0; for ($i = $lineRow; $i < $numLines; $i++) { $WQDData = new WQDData(); $line = trim($content[$i]); $lineVals = explode(',', $line); $totalChannels = (count($lineVals) - 3) / 3; $reportNo = $lineVals[1]; if ($reportNo != "1") { continue; } $dateStr = $lineVals[2]; $dated = new DateTime($dateStr); $channels = array(); $varLocation = 3; for ($channelNo = 1; $channelNo <= $totalChannels; $channelNo++) { $channelNumber = $lineVals[$varLocation++]; $channelValue = $lineVals[$varLocation++]; $channelStatus = $lineVals[$varLocation]; $channelInfo = array(); $channelInfo['value'] = $channelValue; $channelInfo['status'] = $channelStatus; $channels[$channelNumber] = $channelInfo; $varLocation++; } $WQDData->setReportNo($reportNo); $WQDData->setFolderSeq($folderSeq); $WQDData->setDataDate(DateUtils::getSQLDateFromDateObj($dated)); $WQDData->setChannels($channels); $WQDData->setTotalChannels($totalChannels); $WQDData->setChecksum(0); $WQDDataArray[$arrayCount] = $WQDData; $arrayCount = $arrayCount + 1; } return $WQDDataArray; }
public static function parse($filePath, $folderSeq) { //$content = file("../files/AQMS.WQD"); $content = file($filePath); $numLines = count($content); $lineRow = 0; for ($i = 0; $i < $numLines; $i++) { if (trim($content[$i]) == "") { } else { $lineRow = $i; $i = $numLines; } } //$channelNumbers = explode(',', trim($content[$lineRow])); // $lineRow = $lineRow +1; // $channelNames = explode(',', trim($content[$lineRow])); // $totalChannels = count($channelNumbers); $arrayCount = 0; $WQDDataArray = new ArrayObject(); $numLines = count($content); $lineRow = $lineRow + 1; for ($i = $lineRow; $i < $numLines; $i++) { $WQDData = new WQDData(); $line = trim($content[$i]); $lineVals = explode(',', $line); $totalChannels = (count($lineVals) - 3) / 3; $reportNo = $lineVals[1]; if ($reportNo != "1") { continue; } $dateStr = $lineVals[2]; $dated = new DateTime($dateStr); //calculating first channel value $channels = array(); $varLocation = 4; for ($channelNo = 1; $channelNo <= $totalChannels; $channelNo++) { $channelValue = $lineVals[$varLocation++]; $channelStatus = $lineVals[$varLocation++]; $channelInfo = array(); $channelInfo['value'] = $channelValue; $channelInfo['status'] = $channelStatus; $channels[$channelNo] = $channelInfo; $varLocation++; } //foreach($channelNumbers as $channel){ // if($varLocation != 1){ // $channelValue = $lineVals[$varLocation]; // $channelStatus = $lineVals[$varLocation+1]; // $varLocation = $varLocation +2; // }else{ // $varLocation++; // } // $channelInfo = array(); // $channelInfo['value'] = $channelValue; // $channelInfo['status'] = $channelStatus; // $channels[$channel] = $channelInfo; // } //$checkSum = $lineVals[$varLocation]; $WQDData->setReportNo($reportNo); $WQDData->setFolderSeq($folderSeq); $WQDData->setDataDate(DateUtils::getSQLDateFromDateObj($dated)); $WQDData->setChannels($channels); $WQDData->setTotalChannels($totalChannels); $WQDData->setChecksum(0); $WQDDataArray[$arrayCount] = $WQDData; $arrayCount = $arrayCount + 1; } return $WQDDataArray; }
public static function parse($filePath, $folderSeq) { $gagalFolderSeq = array(33, 40, 35); //$content = file("D:/dat.lsi"); //$folderSeq = 33; $content = file($filePath); $numLines = count($content); $lineRow = 0; for ($i = 0; $i < $numLines; $i++) { if (trim($content[$i]) == "") { } else { $lineRow = $i; $i = $numLines; } } $arrayCount = 0; $WQDDataArray = new ArrayObject(); $numLines = count($content); for ($i = $lineRow; $i < $numLines; $i++) { $WQDData = new WQDData(); $line = trim($content[$i]); $line = rtrim($line, ','); $lineVals = explode(',', $line); $totalChannels = count($lineVals) - 2; $totalChannels = $totalChannels / 2; $reportNo = $lineVals[0]; if ($reportNo != "1") { continue; } $dateStr = $lineVals[1]; $dateStr = preg_replace('~\\x{00a0}~u', ' ', $dateStr); $dateStr = trim(html_entity_decode($dateStr)); if (in_array($folderSeq, $gagalFolderSeq)) { $dateStr = ParserStackLsi::convertDate($dateStr); } //$dateStr = ParserStackLsi::convertDate($dateStr); $dated = new DateTime($dateStr); $channels = array(); $varLocation = 2; for ($channelNo = 1; $channelNo <= $totalChannels; $channelNo++) { $channelValue = $lineVals[$varLocation]; $channelStatus = $lineVals[$varLocation + 1]; if ($channelStatus == "1" || $channelStatus == "Ok") { $channelStatus = "128"; } if ($channelStatus == "Abnormal") { $channelStatus = "0"; } $channelInfo = array(); $channelInfo['value'] = round($channelValue, 2); $channelInfo['status'] = $channelStatus; $channels[$channelNo] = $channelInfo; $varLocation++; $varLocation++; } $WQDData->setReportNo($reportNo); $WQDData->setFolderSeq($folderSeq); $WQDData->setDataDate(DateUtils::getSQLDateFromDateObj($dated)); $WQDData->setChannels($channels); $WQDData->setTotalChannels($totalChannels); $WQDData->setChecksum(0); $WQDDataArray[$arrayCount] = $WQDData; $arrayCount = $arrayCount + 1; } return $WQDDataArray; }
foreach ($folders as $folder) { $folSeq = $folder->getSeq(); $toDate = new DateTime(); $toDateStr = DateUtils::getSQLDateFromDateObj($toDate); $fromDate = new DateTime(); $latestDataRows = $WQDS->getChannelsLatestInfo($folSeq); if (count($latestDataRows) > 0) { $toDateStr = $latestDataRows['dated']; $fromDate = new DateTime($latestDataRows['dated']); } echo "To:" . $fromDate->format('Y-m-d H:i:s') . "<br>\n"; echo "FolderSeq:" . $folSeq . " FolderName:" . $folder->getFolderName() . "<br>\n"; $fromDate->modify('-1 day'); echo "From:" . $fromDate->format('Y-m-d H:i:s') . "<br>\n"; // $fromDate->add(DateInterval::createFromDateString('-1Day')); $fromDateStr = DateUtils::getSQLDateFromDateObj($fromDate); $dataRows = $WQDS->getAllDataByFol($fromDateStr, $toDateStr, $folSeq); if (count($dataRows) > 1) { $channelConfigs = $CCDS->FindByFolder($folSeq); $totalChannels = count($channelConfigs); $repStr = " CO O3 NO NO2 NOx NH3 SO2 Ben Tol PXY\r\n"; $repStr .= " mg/m³µg/m³ µg/m³ µg/m³ µg/m³µg/m³ µg/m³ µg/m³ µg/m³ µg/m³\r\n"; $matRepStr = " PM2.5 PM10 AT RH WS WD VWS BP SR\r\n"; $matRepStr .= " µg/m³ µg/m³ °C % m/s deg m/s mmHg W/m²\r\n"; foreach ($dataRows as $row) { $dated = new DateTime($row['wqdfiledatadated']); $repStr .= " " . $dated->format("d/m/y H:i"); $matRepStr .= "" . $dated->format("d/m/Y H:i"); foreach ($channelConfigs as $channelConfiguration) { $chNo = $channelConfiguration->getChannelNumber(); $chUnit = $channelConfiguration->getChannelUnit();
public function generateFile() { echo "APPCB Generator starts...\n"; $CCDS = ChannelConfigurationDataStore::getInstance(); $FDS = FolderDataStore::getInstance(); $WQDS = WQDDataDataStore::getInstance(); $folders = $FDS->FindByLocationSeqs("7,10"); echo "<br>--------TotalFolders:" . count($folders); foreach ($folders as $folder) { $stationName = $folder->getFolderName(); $stationNumber = substr($stationName, 7); $districtCode = "kham"; $industryCode = "ITCPBCM"; //if($folder->getSeq() == 20){ if ($folder->getLocationSeq() == 10) { $stationNumber = 1; if ($folder->getSeq() == 26) { $stationNumber = 2; } else { if ($folder->getSeq() == 27) { $stationNumber = 3; } else { if ($folder->getSeq() == 28) { $stationNumber = 4; } else { if ($folder->getSeq() == 29) { $stationNumber = 5; } } } } $districtCode = "hyde"; $industryCode = "APPCB"; } $folSeq = $folder->getSeq(); $latestDataRows = $WQDS->getChannelsLatestInfo($folSeq); echo "FolderSeq:" . $folSeq . " FolderName:" . $folder->getFolderName() . "<br>\n"; //echo ("<br>\nTotal Rows found:". count($latestDataRows)); echo "<br>\n ToDateFromLatestData " . $latestDataRows['dated']; if (count($latestDataRows) > 0) { $channelConfigs = $CCDS->FindByFolder($folSeq); $toDateStr = $latestDataRows['dated']; $toDate = new DateTime($toDateStr); $fromDate = new DateTime($toDateStr); $fromDate->setTime(0, 0, 0); $fromDateStr = DateUtils::getSQLDateFromDateObj($fromDate); echo "<br>From:" . $fromDateStr . "<br>\n"; echo "To:" . $toDateStr . "<br>\n"; $dataArray = $WQDS->getAllDataByFol($fromDateStr, $toDateStr, $folSeq); $channelNoArr = self::getChannelNumberNameArray(self::$channelsList, $channelConfigs); $addDatesData = array(); foreach ($dataArray as $data) { $channelData = array(); $dated = $data['wqdfiledatadated']; $chValues = array(); $chStatuses = array(); foreach ($channelNoArr as $key => $value) { $vl = (double) $data["ch" . $key . "value"]; if ($vl < 0) { $vl = "n.o"; } array_push($chValues, $vl); array_push($chStatuses, (double) $data["ch" . $key . "status"]); } $allDatesData[strtotime($dated)]['channelValue'] = $chValues; $allDatesData[strtotime($dated)]['channelStatuses'] = $chStatuses; } $channelArr = array(); foreach ($channelNoArr as $chName) { array_push($channelArr, $chName); } $dataSlices = DateUtils::getDateSlicesByInterval($fromDate, $toDate, "1hour"); $dataRows = $WQDS->getAverageDataByDataArrayDataSlices("1hour", $allDatesData, $dataSlices, $channelArr, "normal", array()); } else { echo " \n<br>Null FromDate"; } if (count($dataRows) > 1) { $repStr = ""; foreach ($dataRows as $dateStr => $row) { $chNameValueArr = array(); foreach ($row as $rowId => $rowVal) { $chNameValueArr[$channelArr[$rowId]] = $rowVal; } $repStr .= $districtCode; $repStr .= "," . $industryCode; $repStr .= "," . $stationNumber . ","; $dated = new DateTime($dateStr); $repStr .= $dated->format("m/d/Y h:i:s A"); $channelsList = self::$channelsList; foreach ($channelsList as $chName) { if ($chNameValueArr[$chName] != null) { $repStr .= "," . $chNameValueArr[$chName]; } else { $repStr .= ",NA"; } } $repStr .= "\r\n"; } echo $repStr; //$fileName = "khmmitcl".$folder->getFolderName(). date("Ymd") .".txt"; //$fileName = "air". date("Ymd") .".txt"; $fileName = "air" . $fromDate->format("Ymd") . ".txt"; $repFileName = "/home/envirote/public_html/Generated/APPCB/" . $folSeq . "/" . $fileName; //$repFileName ="d:". $folSeq ."/" . $fileName; if (!file_exists(dirname($repFileName))) { mkdir(dirname($repFileName), 0777, true); } $fh = fopen($repFileName, 'w') or die("can't open file"); fwrite($fh, $repStr); fclose($fh); } unset($channelArr); unset($latestDataRows); unset($channelConfigs); unset($channelNoArr); unset($dataSlices); unset($dataRows); unset($chNameValueArr); unset($allDatesData); unset($channelsList); } //for loop ends }