Ejemplo n.º 1
0
 private function __construct()
 {
     $this->processedReportsModel = new ScheduleTypeReportProcessed();
     $this->synchronization = new Synchronization();
     $this->_logger = LoggerFactory::getFileLogger('ExchangeODSS');
     TimezoneWork::set('UTC');
 }
 public function init()
 {
     parent::init();
     ini_set('memory_limit', '-1');
     set_time_limit(0);
     // All reports are generated basing on data in UTC time.
     TimezoneWork::set('UTC');
 }
Ejemplo n.º 3
0
 public function init()
 {
     parent::init();
     ini_set('memory_limit', '-1');
     set_time_limit(0);
     self::$_logger = LoggerFactory::getFileLogger('reports');
     // All reports are generated basing on data in UTC time.
     TimezoneWork::set('UTC');
 }
Ejemplo n.º 4
0
 /**
  * runs backup process:
  * gets last backup info to identify if need to run new backup or continue precious
  * runs "makeBackup()"
  * 
  * @return type 
  */
 public function run()
 {
     TimezoneWork::set('UTC');
     It::debug("\n\n== STARTED MOVE DATABASE TO BACKUP ==", 'backup_database');
     $this->settings = Settings::model()->findByPk(1);
     /**
      * check if backup process is enabled */
     if (!$this->settings->db_exp_enabled) {
         It::debug("disabled", 'backup_database');
         return;
     } else {
         It::debug("enabled", 'backup_database');
     }
     /**
      * check time */
     $now = time();
     // Here we check if we should make backup
     $last_backup = BackupOldDataTx::getLastBackupInfo();
     // calculate date of the next backup
     $next_planned = strtotime($last_backup->backup_date) + $this->settings->db_exp_frequency * 86400;
     // exit if time not yet or prew backup not completed
     if ($next_planned >= $now and $last_backup->completed == 1) {
         It::debug("not time yet", 'backup_database');
         return;
     }
     /**
      * create new transaction */
     It::debug("create new transaction", 'backup_database');
     $last_backup = new BackupOldDataTx();
     $last_backup->backup_date = new CDbExpression('NOW()');
     $last_backup->data_timestamp_limit = date('Y-m-d 00:00:00', $now - $this->settings->db_exp_period * 86400);
     $last_backup->save();
     $this->current_backup = $last_backup;
     /**
      * add log */
     $this->addBackupLog("Need to Move Data stored before " . $last_backup->data_timestamp_limit . '; Date of backup: ' . $last_backup->backup_date . '; Frequency = ' . $this->settings->db_exp_frequency . '; ');
     It::debug("NOW = " . $now . " = " . date('Y-m-d H:i:s', $now), 'backup_database');
     It::debug("last backup (backup_frequency) = " . $this->settings->db_exp_frequency, 'backup_database');
     It::debug("last backup (id) = " . $last_backup->id, 'backup_database');
     It::debug("last backup (date of backup) = " . $last_backup->backup_date, 'backup_database');
     It::debug("last backup (data timestamp limit) = " . $last_backup->data_timestamp_limit, 'backup_database');
     It::debug("last backup (completed) = " . $last_backup->completed, 'backup_database');
     /**
      * make backup*/
     $this->makeBackup();
     //TODO: off delete row
 }
 public function actionIndex()
 {
     // return maintenance to framework
     //Listener::checkPreparingProcess();
     $route = Yii::app()->getUrlManager()->parseUrl(Yii::app()->getRequest());
     if (strtolower($route) != strtolower('update/CheckExtraUpdate')) {
         if (isset($_POST['change_timezone_id'])) {
             Yii::app()->user->setTZ($_POST['change_timezone_id']);
         }
         $tz = Yii::app()->user->getTZ();
         // Set timezone in either case, because mysql timezone settings can differ from php
         //				if ($tz != date_default_timezone_get())
         //				{
         TimezoneWork::set($tz);
         //				}
     }
     Yii::app()->runController($route);
 }
Ejemplo n.º 6
0
 protected function _init()
 {
     $this->_logger->log(__METHOD__);
     $current_user_timezone = date_default_timezone_get();
     $timezone_id = 'UTC';
     if ($timezone_id != $current_user_timezone) {
         TimezoneWork::set($timezone_id);
     }
     $this->_prepareScheduleInfo();
     $this->_prepareListenerLogInfo();
     $this->_prepareStationInfo();
     if ($timezone_id != $current_user_timezone) {
         TimezoneWork::set($current_user_timezone);
     }
     if ($this->errors) {
         return false;
     }
     return true;
 }
Ejemplo n.º 7
0
 public function save()
 {
     $sql = "SET FOREIGN_KEY_CHECKS = 0;\n";
     $sql .= "";
     foreach ($this->data_after_validor as $key => $value) {
         $sql .= sqlBuilder::createTruncateTableCommand($key);
         $sql .= sqlBuilder::createInsertFromArray($value, $key);
     }
     $sql .= "\n\nSET FOREIGN_KEY_CHECKS = 1;\n";
     $connection = Yii::app()->db;
     $transaction = $connection->beginTransaction();
     try {
         TimezoneWork::set('UTC');
         $command = $connection->createCommand($sql);
         $command->execute();
         $transaction->commit();
         $this->result_success = true;
         return true;
     } catch (Exeption $e) {
         $transaction->rollback();
         $this->result_success = false;
     }
     return false;
     //            try{
     //                $count = $command->execute();
     //                $this->_logger->log(__METHOD__, array('count' => $count));
     //            } catch (Exception $e) {
     //                $this->_logger->log(__METHOD__,array('err' => $e->getMessage()));
     //            }
 }
 /**
  *
  * @return boolean 
  */
 public function generate()
 {
     $this->_logger->log(__METHOD__);
     if ($this->errors) {
         $this->_logger->log(__METHOD__, array('errors' => $this->errors));
         return false;
     }
     $current_user_timezone = date_default_timezone_get();
     $timezone_id = 'UTC';
     if ($timezone_id != $current_user_timezone) {
         TimezoneWork::set($timezone_id);
     }
     $this->sensors = $this->prepareSensorsInfo($this->listener_log_info->log_id);
     $this->calculations = $this->_prepareCalculationsInfo($this->listener_log_info->log_id);
     if ($timezone_id != $current_user_timezone) {
         TimezoneWork::set($current_user_timezone);
     }
     if ($this->errors) {
         $this->_logger->log(__METHOD__, array('errors' => $this->errors));
         return false;
     }
     $this->report_parts = array();
     $this->explanations = array();
     $this->_measuring_timestamp = strtotime($this->listener_log_info->measuring_timestamp);
     $this->_measuring_day = gmdate('d', $this->_measuring_timestamp);
     $this->_measuring_hour = gmdate('H', $this->_measuring_timestamp);
     $this->_measuring_minute = gmdate('i', $this->_measuring_timestamp);
     $this->_logger->log(__METHOD__ . ' Prepare sections.');
     foreach ($this->getSections() as $sectionNumber => $section) {
         $this->_section = $sectionNumber;
         $this->_logger->log(__METHOD__, array('section' => $section));
         foreach ($section as $subsectionNumber => $subsection) {
             $this->_subsection = $subsectionNumber;
             $this->_logger->log(__METHOD__, array('subsection' => $subsection));
             $this->{'write' . $subsection}();
         }
     }
     return true;
 }
Ejemplo n.º 9
0
 public function generate()
 {
     $this->_logger->log(__METHOD__);
     if ($this->errors) {
         $this->_logger->log(__METHOD__, array('errors' => $this->errors));
         return false;
     }
     $current_user_timezone = date_default_timezone_get();
     $timezone_id = 'UTC';
     if ($timezone_id != $current_user_timezone) {
         TimezoneWork::set($timezone_id);
     }
     $this->report_parts = array();
     $this->explanations = array();
     // get sensors' values for all messages received in reporting period
     $sql = "SELECT `t5`.`listener_log_id`,\r\n                       `t5`.`measuring_timestamp`,\r\n                       `t1`.`station_sensor_id`, `t1`.`sensor_id_code`, \r\n                       \r\n                       `t3`.`feature_code`, `t3`.`feature_constant_value`,\r\n                       `t4`.`code` AS `metric_code`, \r\n                       `t5`.`sensor_feature_value`, \r\n                       `t5`.`is_m`,\r\n                       `t5`.`period` AS `sensor_feature_period`,\r\n                       `t6`.`code` AS `value_metric_code`,\r\n                       `t7`.`handler_id_code`\r\n\r\n                FROM `" . SensorData::model()->tableName() . "`  `t5`\r\n                LEFT JOIN `" . StationSensor::model()->tableName() . "`        `t1` ON t1.station_sensor_id = t5.sensor_id\r\n                LEFT JOIN `" . StationSensorFeature::model()->tableName() . "` `t3` ON (`t3`.`sensor_feature_id` = `t5`.`sensor_feature_id`)\r\n                LEFT JOIN `" . RefbookMetric::model()->tableName() . "`        `t4` ON `t4`.`metric_id` = `t3`.`metric_id`\r\n                LEFT JOIN `" . RefbookMetric::model()->tableName() . "`        `t6` ON `t6`.`metric_id` = `t5`.`metric_id`\r\n                LEFT JOIN `" . SensorDBHandler::model()->tableName() . "`      `t7` ON t7.handler_id = t1.handler_id\r\n                WHERE `t5`.`station_id` = '" . $this->station_info->station_id . "' AND `t5`.`listener_log_id` IN (" . $this->schedule_process_info->listener_log_ids . ")\r\n                ORDER BY `t5`.`measuring_timestamp` DESC, `t1`.`sensor_id_code` ASC, `t3`.`feature_code` ASC";
     $sensor_data = Yii::app()->db->createCommand($sql)->queryAll();
     $data = array();
     if ($sensor_data) {
         // get calculation values for all messages received in reporting period
         $sql = "SELECT `t1`.`listener_log_id`,\r\n                           `t1`.`value`,\r\n                           `t3`.`handler_id_code`\r\n                    FROM `" . StationCalculationData::model()->tableName() . "`    `t1`\r\n                    LEFT JOIN `" . StationCalculation::model()->tableName() . "`   `t2` ON t2.calculation_id = t1.calculation_id\r\n                    LEFT JOIN `" . CalculationDBHandler::model()->tableName() . "` `t3` ON `t3`.`handler_id` = `t2`.`handler_id`\r\n                    WHERE `t2`.`station_id` = '" . $this->station_info->station_id . "' AND `t1`.`listener_log_id` IN (" . $this->schedule_process_info->listener_log_ids . ")\r\n                    ORDER BY `t3`.`handler_id_code`";
         $res2 = Yii::app()->db->createCommand($sql)->queryAll();
         if ($res2) {
             foreach ($res2 as $key => $value) {
                 $calculations[$value['listener_log_id']][] = $value;
             }
         }
         foreach ($sensor_data as $key => $value) {
             $data[$value['listener_log_id']][] = $value;
         }
         // prepare $result_item array, where each line represents line in report.
         foreach ($data as $key => $value) {
             $result_item = array('StationId', $this->station_info->station_id_code, 'WMO AWS #', $this->station_info->wmo_block_number . $this->station_info->station_number, 'National AWS #', $this->station_info->national_aws_number, 'Tx DateTime', date('m/d/Y H:i', strtotime($value[0]['measuring_timestamp'])));
             foreach ($value as $key2 => $value2) {
                 $handler_obj = SensorHandler::create($value2['handler_id_code']);
                 if (in_array($value2['handler_id_code'], array('BatteryVoltage', 'Humidity', 'Pressure', 'Temperature'))) {
                     $sensor_id_code = $value2['sensor_id_code'];
                 } else {
                     $sensor_id_code = $value2['sensor_id_code'] . ' (' . $handler_obj->getFeatureName($value2['feature_code']) . ')';
                 }
                 $result_item[] = $sensor_id_code;
                 if ($value2['is_m']) {
                     $result_item[] = '-';
                 } else {
                     $value2['sensor_feature_value'] = $handler_obj->applyOffset($value2['sensor_feature_value'], $this->station_info->magnetic_north_offset);
                     $result_item[] = str_replace(',', ' ', $handler_obj->formatValue($value2['sensor_feature_value'], $value2['feature_code']));
                 }
             }
             if (isset($calculations[$key])) {
                 foreach ($calculations[$key] as $key2 => $value2) {
                     if ($value2['handler_id_code'] === 'DewPoint') {
                         $result_item[] = 'DP';
                     } else {
                         if ($value2['handler_id_code'] === 'PressureSeaLevel') {
                             $result_item[] = 'MSL';
                         } else {
                             $result_item[] = 'Unknown calculation';
                         }
                     }
                     $result_item[] = str_replace(',', ' ', number_format(round($value2['value'], 1), 1));
                 }
             }
             $this->report_parts[] = $result_item;
         }
     }
     if ($timezone_id != $current_user_timezone) {
         TimezoneWork::set($current_user_timezone);
     }
     $this->_logger->log(__METHOD__ . ' Export generation completed.');
     return true;
 }
Ejemplo n.º 10
0
 public function generate()
 {
     $this->_logger->log(__METHOD__);
     $current_user_timezone = date_default_timezone_get();
     $timezone_id = 'UTC';
     if ($timezone_id != $current_user_timezone) {
         TimezoneWork::set($timezone_id);
     }
     if (is_null($this->listener_log_info)) {
         return false;
     }
     $this->_logger->log(__METHOD__ . "this->listener_log_info->log_id " . $this->listener_log_info->log_id);
     $this->sensors = $this->prepareSensorsInfo($this->listener_log_info->log_id);
     $this->calculations = $this->_prepareCalculationsInfo($this->listener_log_info->log_id);
     if ($timezone_id != $current_user_timezone) {
         TimezoneWork::set($current_user_timezone);
     }
     if ($this->errors) {
         $this->_logger->log(__METHOD__, array('errors' => $this->errors));
         return false;
     }
     $this->report_parts = array();
     $this->explanations = array();
     $measuring_timestamp = strtotime($this->listener_log_info->measuring_timestamp);
     $measuring_day = gmdate('d', $measuring_timestamp);
     $measuring_hour = gmdate('H', $measuring_timestamp);
     $measuring_minute = gmdate('i', $measuring_timestamp);
     $section = 0;
     $i = 0;
     // Section #0 - #0
     // CONSTANT
     $this->report_parts[$section][$i] = 'AAXX';
     $this->explanations[$section][$i][] = '<span>AAXX</span>: Fixed';
     $i++;
     $this->explanations[$section][$i][] = ' ';
     // Section #0 - #1
     // Day of the month (UTC), with 01 indicating the first day, 02 the second day,
     // etc.: @DTKY01111229 => 29
     $this->report_parts[$section][$i] = $measuring_day;
     $this->explanations[$section][$i][] = "<span>" . $this->report_parts[$section][$i] . "</span>: Day of the month. Measurement timestamp = '" . $this->listener_log_info->measuring_timestamp . " UTC'";
     // Section #0 - #2
     // Actual time of observation, to the nearest whole hour UTC (Barometer reading time)
     // (round up or down to nearest hour):
     // @DTKY011112290653 => 0653 => 07
     $this->report_parts[$section][$i] .= $measuring_minute >= 30 ? $measuring_hour + 1 : $measuring_hour;
     $this->explanations[$section][$i][] = "<span>" . $measuring_hour . "</span>: Actual time of observation, to the nearest whole hour UTC." . ($measuring_minute >= 30 ? ' +1 = ' . ($measuring_hour + 1) . '. Because minutes >= 30' : '');
     // Section #0 - #3
     // Indicator for source and units of wind speed (1 = m/s) => taken from table 1855
     if (isset($this->sensors['wind_speed_10'])) {
         if ($this->sensors['wind_speed_10']['metric_code'] === 'meter_per_second') {
             $this->report_parts[$section][$i] .= '1';
             $this->explanations[$section][$i][] = "<span>1</span>: Indicator for source and units of wind speed. Sensor " . $this->sensors['wind_speed_10']['sensor_id_code'] . " metric is 'meter_per_second' (see table 1855)";
         } else {
             if ($this->sensors['wind_speed_10']['metric_code'] === 'knot') {
                 $this->report_parts[$section][$i] .= '4';
                 $this->explanations[$section][$i][] = "<span>4</span>: Indicator for source and units of wind speed. Sensor " . $this->sensors['wind_speed_10']['sensor_id_code'] . " metric is 'knot' (see table 1855)";
             } else {
                 $this->report_parts[$section][$i] .= '/';
                 $this->explanations[$section][$i][] = "<span>/</span>: Indicator for source and units of wind speed. Sensor " . $this->sensors['wind_speed_10']['sensor_id_code'] . " metric is '" . $this->sensors['wind_speed_10']['metric_code'] . "' wich has not association in Table 1855";
             }
         }
     } else {
         $this->report_parts[$section][$i] .= '/';
         $this->explanations[$section][$i][] = "<span>/</span>: Indicator for source and units of wind speed. Station has not Wind Speed sensor";
     }
     $i++;
     $this->explanations[$section][$i][] = ' ';
     // Section #0 - #4
     // WMO Block# (take from the station setup) => admin > stations > tky01 = 08 (make sure to add the 0's)
     $this->report_parts[$section][$i] = str_pad($this->station_info['wmo_block_number'], 2, '0', STR_PAD_LEFT);
     $this->explanations[$section][$i][] = '<span>' . $this->station_info['wmo_block_number'] . '</span>: WMO Block#.';
     // Section #0 - #5
     // WMO Station # (take from the station setup) => admin > stations > tky01 = 007
     $this->report_parts[$section][$i] .= str_pad($this->station_info['station_number'], 3, '0', STR_PAD_LEFT);
     $this->explanations[$section][$i][] = '<span>' . $this->station_info['station_number'] . '</span>: WMO Station#.';
     $i++;
     $section = 1;
     // SECTION #1
     // Section #1 - #0
     // Indicator for inclusion or omission of precipitation data (Table 1819):
     // RN1038003018114366: there was rain, we only include in section 1
     $this->report_parts[$section][$i] = isset($this->sensors['rain_in_period']) ? '1' : '0';
     $this->explanations[$section][$i][] = "<span>" . (isset($this->sensors['rain_in_period']) ? '1' : '0') . "</span>: Indicator for RAIN inclusion. The station has rain sensor " . $this->sensors['rain_in_period']['sensor_id_code'];
     // Section #1 - #1
     // Indicator for type of station operation (manned or automatic) and for present and past weather data (1860):
     // 6 (if automatic) or 3 (if manned)..
     $this->report_parts[$section][$i] .= '6';
     $this->explanations[$section][$i][] = "<span>6</span>: Automatic station. Because all stations in this software are automatic.";
     // If Cloud Amount Height is present then take it, otherwise - Cloud Depth Height
     $cloudHeightSensor = isset($this->sensors['cloud_amount_height_1']) ? $this->sensors['cloud_amount_height_1'] : (isset($this->sensors['cloud_height_height_1']) ? $this->sensors['cloud_height_height_1'] : null);
     // Section #1 - #2
     // Height above surface of the base of the lowest cloud seen
     if (!is_null($cloudHeightSensor)) {
         if ($cloudHeightSensor['is_m'] == 1) {
             $this->report_parts[$section][$i] .= '/';
             $this->explanations[$section][$i][] = "<span>/</span>: Height above surface of the base of the lowest cloud seen. Because Cloud Sensor height#1 value is unavailable";
         } else {
             $tmp_data = It::convertMetric($cloudHeightSensor['sensor_feature_value'], $cloudHeightSensor['metric_code'], 'meter');
             $tmp_data2 = $this->_get_cloud_height_code($tmp_data);
             $this->report_parts[$section][$i] .= $tmp_data2;
             $this->explanations[$section][$i][] = "<span>" . $tmp_data2 . "</span>: Height above surface of the base of the lowest cloud seen. (Cloud Height #1 = " . round($cloudHeightSensor['sensor_feature_value'], 1) . " " . $cloudHeightSensor['metric_code'] . " = " . round($tmp_data, 1) . " meter, see table 1600.)";
         }
     } else {
         $this->report_parts[$section][$i] .= '/';
         $this->explanations[$section][$i][] = "<span>/</span>: Height above surface of the base of the lowest cloud seen. Because no Cloud Sensor";
     }
     // Section #1 - #3
     // Horizontal visibility at surface
     if (isset($this->sensors['visibility_1'])) {
         if ($this->sensors['visibility_1']['is_m']) {
             $this->report_parts[$section][$i] .= '//';
             $this->explanations[$section][$i][] = "<span>//</span>: Horizontal visibility at surface. Because value of Visibility Sensor is unavailable.";
         } else {
             $tmp_data = It::convertMetric($this->sensors['visibility_1']['sensor_feature_value'], $this->sensors['visibility_1']['metric_code'], 'kilometer');
             $tmp_data2 = $this->_get_visibility_code($tmp_data);
             $this->report_parts[$section][$i] .= $tmp_data2;
             $this->explanations[$section][$i][] = "<span>" . $tmp_data2 . "</span>: Horizontal visibility at surface. (Visibility = " . round($this->sensors['visibility_1']['sensor_feature_value'], 1) . " " . $this->sensors['visibility_1']['metric_code'] . " = " . round($tmp_data, 1) . " km, See table 4377) ";
         }
     } else {
         $this->report_parts[$section][$i] .= '//';
         $this->explanations[$section][$i][] = "<span>//</span>: Horizontal visibility at surface. Because no Visibility Sensor";
     }
     $i++;
     $this->explanations[$section][$i][] = ' ';
     // Section #1 - #4
     // Cloud cover (2700)
     if (isset($this->sensors['cloud_amount_amount_total'])) {
         if ($this->sensors['cloud_amount_amount_total']['is_m']) {
             $this->report_parts[$section][$i] = '/';
             $this->explanations[$section][$i][] = "<span>/</span>: Cloud cover. Because value of Cloud Sensor is unavailable";
         } else {
             $tmp_data = $this->_get_cloud_cover_code(round($this->sensors['cloud_amount_amount_total']['sensor_feature_value'], 1));
             $this->report_parts[$section][$i] = $tmp_data;
             $this->explanations[$section][$i][] = "<span>" . $tmp_data . "</span>: Cloud cover. (Cloud Amount #1 = " . round($this->sensors['cloud_amount_amount_total']['sensor_feature_value']) . "/8. See code table 2700)";
         }
     } else {
         $this->report_parts[$section][$i] = '/';
         $this->explanations[$section][$i][] = "<span>/</span>: Cloud cover. Because no info about Cloud Amount";
     }
     // Section #1 - #5
     // True Wind Direction (Table 0877)
     // Example: WD11245 => 245 degrees => table 0877 => 25
     if (isset($this->sensors['wind_direction_10'])) {
         if ($this->sensors['wind_direction_10']['is_m']) {
             $this->report_parts[$section][$i] .= '//';
             $this->explanations[$section][$i][] = "<span>//</span>: True Wind Direction. Because value of Wind Direction sensor is unavailable.";
         } else {
             $handler_obj = SensorHandler::create($this->sensors['wind_direction_10']['handler_id_code']);
             $value = $handler_obj->applyOffset($this->sensors['wind_direction_10']['sensor_feature_value'], $this->station_info['magnetic_north_offset']);
             $value = It::convertMetric($value, $this->sensors['wind_direction_10']['metric_code'], 'degree');
             $tmp_val = $this->_get_wind_direction_code($value);
             $this->report_parts[$section][$i] .= $tmp_val;
             $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: True Wind Direction. Because value of " . $this->sensors['wind_direction_10']['sensor_id_code'] . ' = ' . $value . ' degree. See table 0877.';
         }
     } else {
         $this->report_parts[$section][$i] .= '//';
         $this->explanations[$section][$i][] = "<span>//</span>: True Wind Direction. Because no Wind Direction sensor";
     }
     // Section #1 - #6
     // Wind Speed in Units (rounded meter per second )
     // Example: WS23069006540632 => instantaneous = 0690
     if (isset($this->sensors['wind_speed_10'])) {
         if ($this->sensors['wind_speed_10']['is_m']) {
             $this->report_parts[$section][$i] .= '//';
             $this->explanations[$section][$i][] = "<span>//</span>: Because value of Wind Speed sensor is unavailable.";
         } else {
             $value = It::convertMetric($this->sensors['wind_speed_10']['sensor_feature_value'], $this->sensors['wind_speed_10']['metric_code'], 'meter_per_second');
             $tmp_val = round($value);
             $tmp_val = substr($tmp_val, -2);
             $tmp_val = str_pad($tmp_val, 2, '0', STR_PAD_LEFT);
             $this->report_parts[$section][$i] .= $tmp_val;
             $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span> m/s: Wind Speed in Units. Because value of " . $this->sensors['wind_speed_10']['sensor_id_code'] . " = " . $this->sensors['wind_speed_10']['sensor_feature_value'] . " " . $this->sensors['wind_speed_10']['metric_code'];
         }
     } else {
         $this->report_parts[$section][$i] .= '//';
         $this->explanations[$section][$i][] = "<span>//</span>: Wind Speed in Units. Because no Wind Speed sensor.";
     }
     $i++;
     $this->explanations[$section][$i][] = ' ';
     // Section #1 - #7
     // FIXED
     $this->report_parts[$section][$i] = '1';
     $this->explanations[$section][$i][] = '<span>1</span>: Fixed.';
     // Section #1 - #8 - Sign of the data (Code table 3845), in this case relative to temperature (Celsius): TP11772
     // Section #1 - #9 - Air temperature, in tenths of a degree Celsius (observed): TP11772
     if (isset($this->sensors['temperature'])) {
         if ($this->sensors['temperature']['is_m']) {
             $this->report_parts[$section][$i] .= '/';
             $this->explanations[$section][$i][] = "<span>/</span>: Sign of the temperature data (Celsius). Because value of Temperature Sensor is unavailable.";
             $this->report_parts[$section][$i] .= '///';
             $this->explanations[$section][$i][] = "<span>///</span>: Air temperature, in tenths of a degree Celsius. Because value Temperature Sensor is unavailable.";
         } else {
             $value = It::convertMetric($this->sensors['temperature']['sensor_feature_value'], $this->sensors['temperature']['metric_code'], 'celsius');
             $tmp_val = $value >= 0 ? '0' : '1';
             $this->report_parts[$section][$i] .= $tmp_val;
             $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Sign of the temperature data (Celsius). Because value of " . $this->sensors['temperature']['sensor_id_code'] . " = " . $value . " Celsius degree" . ($this->sensors['temperature']['metric_code'] != 'celsius' ? ' (' . $this->sensors['temperature']['sensor_feature_value'] . ' ' . $this->sensors['temperature']['metric_code'] . ')' : '') . ". See table 3845.";
             $tmp_val = abs(round($value * 10));
             $tmp_val = substr($tmp_val, -3);
             $tmp_val = str_pad($tmp_val, 3, '0', STR_PAD_LEFT);
             $this->report_parts[$section][$i] .= $tmp_val;
             $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Air temperature, in tenths of a degree Celsius. Because value of " . $this->sensors['temperature']['sensor_id_code'] . " = " . $value . " Celsius degree" . ($this->sensors['temperature']['metric_code'] != 'celsius' ? ' (' . $this->sensors['temperature']['sensor_feature_value'] . ' ' . $this->sensors['temperature']['metric_code'] . ')' : '') . "";
         }
     } else {
         $this->report_parts[$section][$i] .= '/';
         $this->explanations[$section][$i][] = "<span>/</span>: Sign of the temperature data (Celsius). Because no Temperature Sensor.";
         $this->report_parts[$section][$i] .= '///';
         $this->explanations[$section][$i][] = "<span>///</span>: Air temperature, in tenths of a degree Celsius. Because no Temperature Sensor.";
     }
     $i++;
     $this->explanations[$section][$i][] = " ";
     // Section #1 - #10 FIXED
     $this->report_parts[$section][$i] = '2';
     $this->explanations[$section][$i][] = "<span>2</span>: Fixed.";
     // Section #1 - #11 - Sign of the data (Code table 3845), in this case relative to DewPoint or Humidity (if there is now DewPoint)
     // Section #1 - #12 - Dew Point (include if calculated), else Humidity (HU in case sn =9) (observed) => no DewPoint or Humidity.. Can we exclude it? Have to add '///'? Can we exclude 'Sn' as well?
     if (isset($this->calculations['DewPoint'])) {
         $tmp_val = $this->calculations['DewPoint']['value'] >= 0 ? '0' : '1';
         $this->report_parts[$section][$i] .= $tmp_val;
         $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Sign of the data (Code table 3845), in this case relative to DewPoint or Humidity (if there is no DewPoint). Because 1) we have DewPoint; 2) DewPoint value is = " . $this->calculations['DewPoint']['value'];
         $tmp_val = round(abs($this->calculations['DewPoint']['value'] * 10));
         $tmp_val = substr($tmp_val, -3);
         $tmp_val = str_pad($tmp_val, 3, '0', STR_PAD_LEFT);
         $this->report_parts[$section][$i] .= $tmp_val;
         $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Dew Point (include if calculated), else Humidity (HU in case sn=9). Because we have Dew Point calculation and its vaue = " . $this->calculations['DewPoint']['value'];
     } else {
         if (isset($this->sensors['humidity']) && !$this->sensors['humidity']['is_m']) {
             $this->report_parts[$section][$i] .= '9';
             $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Sign of the data (Code table 3845), in this case relative to DewPoint or Humidity (if there is no DewPoint). Because 1) we have don't have DewPoint, but we have Humidity; 2) result is 9 according to table 3845.";
             $tmp_val = round($this->sensors['humidity']['sensor_feature_value']);
             $tmp_val = substr($tmp_val, -3);
             $tmp_val = str_pad($tmp_val, 3, '0', STR_PAD_LEFT);
             $this->report_parts[$section][$i] .= $tmp_val;
             $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Dew Point (include if calculated), else Humidity (HU in case sn=9). Because we don't have DewPoint calculation, but we have Humidity Sensor " . $this->sensors['humidity']['sensor_id_code'] . ' with value = ' . $this->sensors['humidity']['sensor_feature_value'] . '%';
         } else {
             $this->report_parts[$section][$i] .= '/';
             $this->explanations[$section][$i][] = "<span>/</span>: Sign of the data (Code table 3845), in this case relative to DewPoint or Humidity (if there is no DewPoint). Because Station has not DewPoint Calculation, Humidity Sensor";
             $this->report_parts[$section][$i] .= '///';
             $this->explanations[$section][$i][] = "<span>///</span>: Dew Point (include if calculated), else Humidity (HU in case sn=9). Because Station has not DewPoint Calculation, Humidity Sensor";
         }
     }
     $i++;
     $this->explanations[$section][$i][] = " ";
     // Section #1 - #13
     // FIXED
     $this->report_parts[$section][$i] = '3';
     $this->explanations[$section][$i][] = "<span>3</span>: Fixed.";
     // Section #1 - #14
     // Pressure at station level, in tenths of a hectopascal, omitting thousands
     // digit of hectopascals of the pressure value. (observed)
     // Example: PR105090
     if (isset($this->sensors['pressure'])) {
         if ($this->sensors['pressure']['is_m']) {
             $this->report_parts[$section][$i] .= '////';
             $this->explanations[$section][$i][] = "<span>////</span>: Pressure at station level, in tenths of a hectopascal, omitting thousands digit of hectopascals of the pressure value. Because value of Pressure Sensor is unavailable.";
         } else {
             $value = It::convertMetric($this->sensors['pressure']['sensor_feature_value'], $this->sensors['pressure']['metric_code'], 'hpascal');
             $tmp_val = round($value * 10);
             $tmp_val = substr($tmp_val, -4);
             $tmp_val = str_pad($tmp_val, 4, '0', STR_PAD_LEFT);
             $this->report_parts[$section][$i] .= $tmp_val;
             $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Pressure at station level, in tenths of a hectopascal, omitting thousands digit of hectopascals of the pressure value. Because value of Pressure Sensor " . $this->sensors['pressure']['sensor_id_code'] . ' = ' . $this->sensors['pressure']['sensor_feature_value'] . ' ' . $this->sensors['pressure']['metric_code'] . ($this->sensors['pressure']['metric_code'] != 'hpascal' ? ' (' . $value . ' hPa)' : '');
         }
     } else {
         $this->report_parts[$section][$i] .= '////';
         $this->explanations[$section][$i][] = "<span>////</span>: Pressure at station level, in tenths of a hectopascal, omitting thousands digit of hectopascals of the pressure value. Because no Pressure Sensor.";
     }
     $i++;
     $this->explanations[$section][$i][] = " ";
     // Section #1 - #15 FIXED
     $this->report_parts[$section][$i] = '4';
     $this->explanations[$section][$i][] = "<span>4</span>: Fixed.";
     // Section #1 - #16 - Pressure at mean sea level, in tenths of a hectopascal, omitting thousands digit of hectopascals of the pressure value. (assuming accurate adjustment to sea level in possible) (Calculated)
     if (isset($this->calculations['PressureSeaLevel'])) {
         $tmp_val = round(abs($this->calculations['PressureSeaLevel']['value'] * 10));
         $tmp_val = substr($tmp_val, -4);
         $tmp_val = str_pad($tmp_val, 4, '0', STR_PAD_LEFT);
         $this->report_parts[$section][$i] .= $tmp_val;
         $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Pressure at mean sea level, in tenths of a hectopascal, omitting thousands digit of hectopascals of the pressure value. Because Pressure MSL=" . $this->calculations['PressureSeaLevel']['value'];
     } else {
         $this->report_parts[$section][$i] .= '////';
         $this->explanations[$section][$i][] = "<span>////</span>: Pressure at mean sea level, in tenths of a hectopascal, omitting thousands digit of hectopascals of the pressure value. Because no calculation Pressure MSL";
     }
     $i++;
     $this->explanations[$section][$i][] = " ";
     // Section #1 - #17 - FIXED
     $this->report_parts[$section][$i] = '6';
     $this->explanations[$section][$i][] = "<span>6</span>: Fixed.";
     // Section #1 - #18
     // Amount of precipitation which has fallen during the period preceding the time of observation, as indicated by tR (Table 3590)
     if (isset($this->sensors['rain_in_period'])) {
         if ($this->sensors['rain_in_period']['is_m']) {
             $this->report_parts[$section][$i] .= '///';
             $this->explanations[$section][$i][] = '<span>///</span>: Amount of precipitation which has fallen during the period preceding the time of observation. Because value of Rain Sensor is unavailable.';
         } else {
             $value = It::convertMetric($this->sensors['rain_in_period']['sensor_feature_value'], $this->sensors['rain_in_period']['metric_code'], 'millimeter');
             $tmp_val = $this->_get_rain_code($value);
             $this->report_parts[$section][$i] .= $tmp_val;
             $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Amount of precipitation which has fallen during the period preceding the time of observation. Because value of Rain Sensor " . $this->sensors['rain_in_period']['sensor_id_code'] . " = " . $this->sensors['rain_in_period']['sensor_feature_value'] . ' ' . $this->sensors['rain_in_period']['metric_code'] . ', see table 3590 to understand result.';
         }
     } else {
         $this->report_parts[$section][$i] .= '///';
         $this->explanations[$section][$i][] = '<span>///</span>: Amount of precipitation which has fallen during the period preceding the time of observation. Because no Rain sensor';
     }
     // Section #1 - #19
     // Duration of period of reference for amount of precipitation (Table 4019);
     // This depends upon the period of transmission of SYNOP. If hourly transmission then the data should be for 1 hour.
     $tmp_val = $this->_get_duration_of_synop_transmission($this->schedule_info->period);
     $this->report_parts[$section][$i] .= $tmp_val;
     $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Duration of period of reference for amount of precipitation. Because period of SYNOP transmission is " . $this->schedule_info->period . ' minutes, see table 4019 to understand result';
     $i++;
     // Section #2 is not included
     // Section #3 - #20 - FIXED
     $section = 3;
     $this->report_parts[$section][$i] = '333';
     $this->explanations[$section][$i][] = '<span>333</span>: Fixed.';
     $i++;
     $this->explanations[$section][$i][] = " ";
     $this->report_parts[$section][$i] = '5';
     $this->explanations[$section][$i][] = "<span>5</span>: Fixed.";
     //$i++;
     if ((!isset($this->sensors['solar_radiation_in_period']) || $this->sensors['solar_radiation_in_period']['is_m']) && (!isset($this->sensors['sun_duration_in_period']) || $this->sensors['sun_duration_in_period']['is_m'])) {
         $this->report_parts[$section][$i] = '/////////';
         $this->explanations[$section][$i][] = "<span>/////////</span>: No Solar Radiation, no Sun Duration sensor.";
     } else {
         $this->report_parts[$section][$i] = '53';
         $this->explanations[$section][$i][] = "<span>53</span>: Is fixed.";
         if (isset($this->sensors['solar_radiation_in_period'])) {
             $tmp_val = ceil($this->sensors['solar_radiation_in_period']['sensor_feature_period'] / 6);
             $tmp_val = substr($tmp_val, -2);
             $tmp_val = str_pad($tmp_val, 2, '0', STR_PAD_LEFT);
             $this->report_parts[$section][$i] .= $tmp_val;
             $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Duration of period for Solar Radiation " . $this->sensors['solar_radiation_in_period']['sensor_id_code'] . " (" . $this->sensors['solar_radiation_in_period']['sensor_feature_period'] . " / 6). Highest whole figure was taken.";
             $this->report_parts[$section][$i] .= '2';
             $this->explanations[$section][$i][] = "<span>2</span>: Fixed and = 2, because period of Solar Radiation " . $this->sensors['solar_radiation_in_period']['sensor_id_code'] . " was taken (Not period of Sun Duration). Period for Solar Radiation (" . $this->sensors['solar_radiation_in_period']['sensor_feature_period'] . " / 6). Highest whole figure was taken.";
             $value = It::convertMetric($this->sensors['solar_radiation_in_period']['sensor_feature_value'], $this->sensors['solar_radiation_in_period']['metric_code'], 'kjoule_per_sq_meter');
             $tmp_val = substr(round($value), -4);
             $tmp_val = str_pad($tmp_val, 4, '0', STR_PAD_LEFT);
             $this->report_parts[$section][$i] .= $tmp_val;
             $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Value of Solar Radiation Sensor " . $this->sensors['solar_radiation_in_period']['sensor_id_code'] . " = " . $this->sensors['solar_radiation_in_period']['sensor_feature_value'] . ' ' . $this->sensors['solar_radiation_in_period']['metric_code'] . ($this->sensors['solar_radiation_in_period']['metric_code'] != 'kjoule_per_sq_meter' ? ' ( = ' . $value . ' kjoule_per_sq_meter)' : '');
         } else {
             $tmp_val = ceil($this->sensors['sun_duration_in_period']['sensor_feature_period'] / 6);
             $tmp_val = substr($tmp_val, -2);
             $tmp_val = str_pad($tmp_val, 2, '0', STR_PAD_LEFT);
             $this->report_parts[$section][$i] .= $tmp_val;
             $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Duration of period for Sun Duration " . $this->sensors['sun_duration_in_period']['sensor_id_code'] . " measurememt (" . $this->sensors['sun_duration_in_period']['sensor_feature_period'] . " / 6). Highest whole figure was taken.";
             $this->report_parts[$section][$i] .= '3';
             $this->explanations[$section][$i][] = "<span>3</span>: Fixed and = 3, because period of Sun Duration " . $this->sensors['sun_duration_in_period']['sensor_id_code'] . " was taken (Not period of Solar Radiation). Period for Sun Duration (" . $this->sensors['sun_duration_in_period']['sensor_feature_period'] . " / 6). Highest whole figure was taken.";
             $tmp_val = round($this->sensors['sun_duration_in_period']['sensor_feature_value']);
             $tmp_val = substr($tmp_val, -4);
             $tmp_val = str_pad($tmp_val, 4, '0', STR_PAD_LEFT);
             $this->report_parts[$section][$i] .= $tmp_val;
             $this->explanations[$section][$i][] = "<span>" . $tmp_val . "</span>: Value of Sun Duration Sensor " . $this->sensors['sun_duration_in_period']['sensor_id_code'] . " = " . $this->sensors['sun_duration_in_period']['sensor_feature_value'] . ' ' . $this->sensors['sun_duration_in_period']['metric_code'] . ' minutes';
         }
     }
     return true;
 }
 /**
  * @var $stationForm configForm
  * **/
 public function run($args)
 {
     //        error_reporting(null);
     ini_set('display_errors', 1);
     $this->_logger = LoggerFactory::getFileLogger('GenerateMessageCommand');
     //        $this->_logger = LoggerFactory::getConsoleLogger();
     $this->_logger->log('start');
     //       $args:
     //       $args[0] AWS01
     //       $args[1] "sensors:TS1;TS2;"
     $station_id_code = false;
     if (preg_match('/^([A-Z,a-z,0-9]{4,5})$/', $args[0], $matchesStations)) {
         $station_id_code = $matchesStations[1];
     } else {
         $this->_logger->log(' Station ID can contain only Letters (A-Z) and Figures (1-9), and must be of 4(rain) or 5(AWS) chars length.');
     }
     $sensor_id_codes = array();
     if (isset($args[1])) {
         if (preg_match("/^sensors:([A-Za-z1-9;]+)/", $args[1], $matchesSensors)) {
             $sensor_id_code = explode(';', $matchesSensors[1]);
             $sensor_id_codes = array_values($sensor_id_code);
             $sensor_id_codes_count = count($sensor_id_codes);
             for ($i = 0; $i < $sensor_id_codes_count; $i++) {
                 if (!preg_match('/^([A-Z,a-z]{2})([1-9]{1})$/', $sensor_id_codes[$i], $matches)) {
                     unset($sensor_id_codes[$i]);
                     $this->_logger->log('Sensor ID should contain two letters and 1 digit. Ex.: TP1');
                 }
             }
             $sensor_id_codes = array_values($sensor_id_codes);
         }
     }
     $station = Station::getStationByCode($station_id_code, array('sensors.handler', 'sensors.features.metric'));
     //            $sql = "SELECT `t1`.`station_sensor_id`, `t1`.`sensor_id_code`,  `t2`.`handler_id_code`, `t3`.`feature_code`, `t4`.`code` AS `metric_code`
     //                            FROM `".StationSensor::model()->tableName()."` `t1`
     //                            LEFT JOIN `".SensorDBHandler::model()->tableName()."`      `t2` ON `t2`.`handler_id` = `t1`.`handler_id`
     //                            LEFT JOIN `".StationSensorFeature::model()->tableName()."` `t3` ON `t3`.`sensor_id`  = `t1`.`station_sensor_id`
     //                            LEFT JOIN `".RefbookMetric::model()->tableName()."`        `t4` ON `t4`.`metric_id`  = `t3`.`metric_id`
     //                            WHERE `t1`.`station_id` = '".$station_id."' AND `t1`.`station_sensor_id` IN (".implode(',',$sensor_id).")";
     //            $res = Yii::app()->db->createCommand($sql)->queryAll();
     if ($station) {
         TimezoneWork::set($station->timezone_id);
         $sensors = array();
         foreach ($station->sensors as $key => $sensor) {
             if (in_array($sensor->sensor_id_code, $sensor_id_codes) || count($sensor_id_codes) == 0) {
                 if (!isset($sensors[$sensor->station_sensor_id])) {
                     $sensors[$sensor->station_sensor_id] = array('station_sensor_id' => $sensor->station_sensor_id, 'sensor_id_code' => $sensor->sensor_id_code, 'handler_id_code' => $sensor->handler->handler_id_code);
                 }
                 foreach ($sensor->features as $feature) {
                     if (is_object($feature->metric)) {
                         $sensors[$sensor->station_sensor_id]['features'][$feature->feature_code] = $feature->metric->code;
                     }
                 }
             }
         }
         $i = time();
         $messages[$i]['timestamp'] = $i;
         $this->_logger->log(__METHOD__ . ': sensors ' . print_r($sensors['sensor_id_code'], 1));
         foreach ($messages as $key => $value) {
             if ($station->station_type === 'rain') {
                 $messages[$key]['parts'][] = 'D';
                 $messages[$key]['parts'][] = $station->station_id_code;
                 $messages[$key]['parts'][] = date('ymd', $key);
                 $messages[$key]['parts'][] = date('Hi', $key);
                 $messages[$key]['parts'][] = str_pad(rand(100, 135), 3, "0", STR_PAD_LEFT);
                 $messages[$key]['parts'][] = '00';
             } else {
                 $messages[$key]['parts'][] = 'D';
                 $messages[$key]['parts'][] = $station->station_id_code;
                 $messages[$key]['parts'][] = date('ymd', $key);
                 $messages[$key]['parts'][] = date('Hi', $key);
                 $messages[$key]['parts'][] = '00';
             }
             $sensors_values = array();
             if ($sensors) {
                 foreach ($sensors as $k1 => $v1) {
                     $handler = SensorHandler::create($v1['handler_id_code']);
                     $random_value = $handler->getRandomValue($v1['features']);
                     $sensors_values[] = $v1['sensor_id_code'] . $random_value;
                 }
                 shuffle($sensors_values);
                 foreach ($sensors_values as $k1 => $v1) {
                     $messages[$key]['parts'][] = $v1;
                 }
             }
             $crc = It::prepareCRC(implode('', $messages[$key]['parts']));
             $messages[$key]['parts'][] = $crc;
             array_push($messages[$key]['parts'], '$');
             array_unshift($messages[$key]['parts'], '@');
         }
         $messages_display = array();
         $messages_copy = array();
         foreach ($messages as $key => $value) {
             $messages_display[] = implode(' ', $value['parts']);
             $messages_copy[] = implode('', $value['parts']);
         }
         $this->_logger->log(__METHOD__ . ': $messages_copy ' . print_r($messages_copy, 1));
         foreach ($messages_copy as $msg) {
             ListenerLogTemp::addNew($msg, 0, 1, 'import', 0);
         }
     } else {
         $this->_logger->log(__METHOD__ . ': has no stations like ' . $args[0]);
     }
 }
Ejemplo n.º 12
0
 public function checkPeriod($measuring_timestamp, $sensor_feature_id, $station_id, $key)
 {
     // todo
     $station = new Station();
     $stationData = $station->findbypk($station_id);
     if ($stationData['timezone_id']) {
         TimezoneWork::set($stationData['timezone_id']);
     }
     $last = $this->prepared_pairs[$this->checkPeriodArray[$key]];
     $criteria = new CDbCriteria();
     $criteria->select = 'measuring_timestamp, sensor_feature_value, sensor_feature_normalized_value, period, measuring_timestamp, sensor_feature_id, station_id';
     $criteria->addCondition('measuring_timestamp < "' . $measuring_timestamp . '"');
     $criteria->addCondition('sensor_feature_id = "' . $sensor_feature_id . '"');
     $criteria->addCondition('station_id = "' . $station_id . '"');
     $criteria->order = 'measuring_timestamp DESC';
     $criteria->limit = 1;
     $data = SensorData::model()->find($criteria);
     if (!is_null($data) and $data != false) {
         $value_norm = $last['normilized_value'] - $data['sensor_feature_normalized_value'];
         $getDate = getdate(strtotime($measuring_timestamp));
         $getDatePrev = getdate(strtotime($data['measuring_timestamp']));
         if ($getDate['yday'] != $getDatePrev['yday'] && ($getDate['hours'] != 0 || $getDate['minutes'] != 0 || $getDate['seconds'] != 0) || $getDate['yday'] == $getDatePrev['yday'] && $getDatePrev['hours'] == 0 && $getDatePrev['minutes'] == 0 && $getDatePrev['seconds'] == 0) {
             $this->prepared_pairs[$key]['period'] = $getDate['hours'] * 60 + $getDate['minutes'];
             $this->prepared_pairs[$key]['value'] = $last['value'];
             $this->prepared_pairs[$key]['normilized_value'] = $last['normilized_value'];
         } else {
             $this->prepared_pairs[$key]['period'] = round((strtotime($measuring_timestamp) - strtotime($data['measuring_timestamp'])) / 60);
             $this->prepared_pairs[$key]['value'] = $last['value'] - $data['sensor_feature_value'];
             $this->prepared_pairs[$key]['normilized_value'] = $value_norm;
             if ($this->prepared_pairs[$key]['value'] < 0) {
                 $this->prepared_pairs[$key]['period'] = $getDate['hours'] * 60 + $getDate['minutes'];
                 $this->prepared_pairs[$key]['value'] = $last['value'];
                 $this->prepared_pairs[$key]['normilized_value'] = $last['normilized_value'];
             }
             if ($last['value'] == 0 && $this->prepared_pairs[$key]['value'] < 0) {
                 $this->prepared_pairs[$key]['value'] = 0;
                 $this->prepared_pairs[$key]['normilized_value'] = 0.0;
             }
         }
         $this->_logger->log(__METHOD__ . ' getDate: ' . $measuring_timestamp);
         $this->_logger->log(__METHOD__ . ' sensor_feature_id: ' . $sensor_feature_id);
         $this->_logger->log(__METHOD__ . ' station_id: ' . $station_id);
         $this->_logger->log(__METHOD__ . ' getDatePrev: ' . $data['measuring_timestamp']);
     }
     return $this->prepared_pairs[$key];
 }
Ejemplo n.º 13
0
 public function actionStationTypeDataHistory()
 {
     $ex_schedule_id = isset($_REQUEST['ex_schedule_id']) ? intval($_REQUEST['ex_schedule_id']) : null;
     if (!(int) $ex_schedule_id) {
         $this->redirect($this->createUrl('site/StationTypeDataExport'));
     }
     TimezoneWork::set('UTC');
     $history = ScheduleTypeReportProcessed::getHistory($ex_schedule_id);
     $scheduleTypeReport = new ScheduleTypeReport();
     $report = $scheduleTypeReport->findByPk($ex_schedule_id);
     $this->render('schedule_type_report_history', array('report' => $report, 'history' => $history));
 }
Ejemplo n.º 14
0
 public function generate()
 {
     $this->_logger->log(__METHOD__);
     $current_user_timezone = date_default_timezone_get();
     $timezone_id = 'UTC';
     if ($timezone_id != $current_user_timezone) {
         TimezoneWork::set($timezone_id);
     }
     $this->sensors = $this->prepareSensorsInfo($this->listener_log_info->log_id);
     $this->calculations = $this->_prepareCalculationsInfo($this->listener_log_info->log_id);
     if ($timezone_id != $current_user_timezone) {
         TimezoneWork::set($current_user_timezone);
     }
     if ($this->errors) {
         $this->_logger->log(__METHOD__, array('errors' => $this->errors));
         return false;
     }
     $this->report_parts = array();
     $this->explanations = array();
     $this->prepareSection0();
     $this->prepareSection1();
     $this->prepareSection3();
     $this->prepareSection4();
     $this->prepareSection5();
 }
Ejemplo n.º 15
0
    public function createExport()
    {
        TimezoneWork::set('UTC');
        $tablesArray = array();
        $settingsArray = array();
        $settingsArray['user_settings'] = false;
        $settingsArray['common_settings'] = false;
        // users and access tables
        if ($this->user_settings) {
            $userTable = Yii::app()->db->createCommand()->select('
                                            u.user_id,
                                            u.email,
                                            u.username,
                                            u.password,
                                            u.role,
                                            u.timezone_id,
                                            u.created,
                                            u.updated
                                        ')->from('user u')->queryAll();
            $tablesArray['user'] = $userTable;
            $access_userTable = Yii::app()->db->createCommand()->select('
                                            au.id,
                                            au.user_id,
                                            au.action_id,

                                        ')->from('access_user au')->queryAll();
            $tablesArray['access_user'] = $access_userTable;
            $access_globalTable = Yii::app()->db->createCommand()->select('
                                            ag.id,
                                            ag.controller,
                                            ag.action,
                                            ag.enable,
                                            ag.description,

                                        ')->from('access_global ag')->queryAll();
            $tablesArray['access_global'] = $access_globalTable;
            $settingsArray['user_settings'] = true;
        }
        $settingsTable = Settings::model()->findAll();
        $tablesArray['settings'] = self::modelDataToArray($settingsTable);
        //        $configTable = Yii::app()->db->createCommand()
        //            ->select('c.config_id, c.key, c.label, c.value, c.default, c.type')
        //            ->from('config c')
        //            ->queryAll();
        //        $tablesArray['config'] = $configTable;
        $station = Yii::app()->db->createCommand()->select('
                                                            s.station_id,
                                                            s.display_name,
                                                            s.station_id_code,
                                                            s.station_number,
                                                            s.station_type,
                                                            s.logger_type,
                                                            s.communication_type,
                                                            s.communication_port,
                                                            s.communication_esp_ip,
                                                            s.communication_esp_port,
                                                            s.details,
                                                            s.status_message_period,
                                                            s.event_message_period,
                                                            s.timezone_id,
                                                            s.timezone_offset,
                                                            s.wmo_block_number,
                                                            s.wmo_member_state_id,
                                                            s.wmo_station_number,
                                                            s.wmo_originating_centre,
                                                            s.national_aws_number,
                                                            s.lat,
                                                            s.lng,
                                                            s.altitude,
                                                            s.magnetic_north_offset,
                                                            s.country_id,
                                                            s.city_id,
                                                            s.awos_msg_source_folder,
                                                            s.icao_code,
                                                            s.phone_number,
                                                            s.sms_message,
                                                            s.station_gravity,
                                                            s.created,
                                                            s.updated
                                                            ')->from('station  s')->queryAll();
        $tablesArray['station'] = $station;
        $station_groupTable = Yii::app()->db->createCommand()->select('
                                                                        sg.group_id,
                                                                        sg.name
                                                            ')->from('station_group sg')->queryAll();
        $tablesArray['station_group'] = $station_groupTable;
        $station_group_destinationTable = Yii::app()->db->createCommand()->select('
                                                                        sgd.group_destination_id,
                                                                        sgd.group_id,
                                                                        sgd.station_id
                                                            ')->from('station_group_destination sgd')->queryAll();
        $tablesArray['station_group_destination'] = $station_group_destinationTable;
        $station_calculationTable = Yii::app()->db->createCommand()->select('
                                                                        sc.calculation_id,
                                                                        sc.station_id,
                                                                        sc.handler_id,
                                                                        sc.formula,
                                                                        sc.created,
                                                                        sc.updated
                                                            ')->from('station_calculation sc')->queryAll();
        $tablesArray['station_calculation'] = $station_calculationTable;
        $station_calculation_variableTable = Yii::app()->db->createCommand()->select('
                                                                        scv.calculation_variable_id,
                                                                        scv.calculation_id,
                                                                        scv.variable_name,
                                                                        scv.sensor_feature_id,
                                                                        scv.created,
                                                                        scv.updated
                                                            ')->from('station_calculation_variable scv')->queryAll();
        $tablesArray['station_calculation_variable'] = $station_calculation_variableTable;
        $station_sensorTable = Yii::app()->db->createCommand()->select('
                                                                        ss.station_sensor_id,
                                                                        ss.station_id,
                                                                        ss.sensor_id_code,
                                                                        ss.display_name,
                                                                        ss.created,
                                                                        ss.updated,
                                                                        ss.handler_id
                                                            ')->from('station_sensor ss')->queryAll();
        $tablesArray['station_sensor'] = $station_sensorTable;
        $station_sensor_featureTable = Yii::app()->db->createCommand()->select('
                                                                      ssf.sensor_feature_id,
                                                                      ssf.sensor_id,
                                                                      ssf.feature_code,
                                                                      ssf.feature_display_name,
                                                                      ssf.feature_constant_value,
                                                                      ssf.measurement_type_code,
                                                                      ssf.metric_id,
                                                                      ssf.is_main,
                                                                      ssf.filter_max,
                                                                      ssf.filter_min,
                                                                      ssf.filter_diff,
                                                                      ssf.has_filters,
                                                                      ssf.has_filter_min,
                                                                      ssf.has_filter_max,
                                                                      ssf.has_filter_diff,
                                                                      ssf.is_constant,
                                                                      ssf.is_cumulative,
                                                                      ssf.created,
                                                                      ssf.updated
                                                            ')->from('station_sensor_feature ssf')->queryAll();
        $tablesArray['station_sensor_feature'] = $station_sensor_featureTable;
        $sensor_handler_defaultTable = Yii::app()->db->createCommand()->select('
                                                                      sh.handler_id,
                                                                      sh.handler_id_code,
                                                                      sh.display_name,
                                                                      sh.handler_default_display_name,
                                                                      sh.default_prefix,
                                                                      sh.aws_panel_display_position,
                                                                      sh.aws_panel_show,
                                                                      sh.aws_single_display_position,
                                                                      sh.aws_single_group,
                                                                      sh.aws_station_uses,
                                                                      sh.rain_station_uses,
                                                                      sh.awa_station_uses,
                                                                      sh.flags,
                                                                      sh.start_time,
                                                                      sh.created,
                                                                      sh.updated
                                                            ')->from('sensor_handler sh')->queryAll();
        $tablesArray['sensor_handler'] = $sensor_handler_defaultTable;
        $sensor_handler_default_featureTable = Yii::app()->db->createCommand()->select('
                                                                    shdf.handler_feature_id,
                                                                    shdf.handler_id,
                                                                    shdf.feature_code,
                                                                    shdf.aws_panel_show,
                                                                    shdf.feature_constant_value,
                                                                    shdf.metric_id,
                                                                    shdf.filter_max,
                                                                    shdf.filter_min,
                                                                    shdf.filter_diff,
                                                                    shdf.created,
                                                                    shdf.updated
                                                            ')->from('sensor_handler_default_feature shdf')->queryAll();
        $tablesArray['sensor_handler_default_feature'] = $sensor_handler_default_featureTable;
        $schedule_reportTable = Yii::app()->db->createCommand()->select('
                                                                    sr.schedule_id,
                                                                    sr.report_type,
                                                                    sr.station_id,
                                                                    sr.send_like_attach,
                                                                    sr.send_email_together,
                                                                    sr.period,
                                                                    sr.report_format,
                                                                    sr.last_scheduled_run_fact,
                                                                    sr.last_scheduled_run_planned,
                                                                    sr.created,
                                                                    sr.updated
                                                            ')->from('schedule_report sr')->queryAll();
        $tablesArray['schedule_report'] = $schedule_reportTable;
        $schedule_report_to_stationTable = Yii::app()->db->createCommand()->select('
                                                                    srts.id,
                                                                    srts.schedule_id,
                                                                    srts.station_id
                                                            ')->from('schedule_report_to_station srts')->queryAll();
        $tablesArray['schedule_report_to_station'] = $schedule_report_to_stationTable;
        $schedule_report_destinationTable = Yii::app()->db->createCommand()->select('
                                                                    srd.schedule_destination_id,
                                                                    srd.schedule_id,
                                                                    srd.method,
                                                                    srd.destination_email,
                                                                    srd.destination_local_folder,
                                                                    srd.destination_ip,
                                                                    srd.destination_ip_port,
                                                                    srd.destination_ip_folder,
                                                                    srd.destination_ip_user,
                                                                    srd.destination_ip_password
                                                            ')->from('schedule_report_destination srd')->queryAll();
        $tablesArray['schedule_report_destination'] = $schedule_report_destinationTable;
        $ex_schedule_reportTable = Yii::app()->db->createCommand()->from('ex_schedule_report esr')->queryAll();
        $tablesArray['ex_schedule_report'] = $ex_schedule_reportTable;
        $ex_schedule_report_destinationTable = Yii::app()->db->createCommand()->from('ex_schedule_report_destination esrd')->queryAll();
        $tablesArray['ex_schedule_report_destination'] = $ex_schedule_report_destinationTable;
        //        $ex_schedule_report_processedTable = Yii::app()->db->createCommand()
        //                                                            ->from('ex_schedule_report_processed esrp')
        //                                                            ->queryAll();
        //        $tablesArray['ex_schedule_report_processed'] = $ex_schedule_report_processedTable;
        //        $ex_schedule_send_logTable = Yii::app()->db->createCommand()
        //
        //                                                            ->from('ex_schedule_send_log essl')
        //                                                            ->queryAll();
        //        $tablesArray['ex_schedule_send_log'] = $ex_schedule_send_logTable;
        $settingsArray['common_settings'] = true;
        $resultArray['config'] = $settingsArray;
        $resultArray['data'] = $tablesArray;
        $result = serialize($resultArray);
        $additional = "";
        if ($settingsArray['user_settings']) {
            $additional = "_users";
        }
        $fileName = 'settings_export' . $additional . '_' . date('Y_m_d_H_i_s') . '.conf';
        It::downloadFile($result, $fileName, 'text/conf');
    }
Ejemplo n.º 16
0
 public function __destruct()
 {
     if (get_class(Yii::app()) != 'CConsoleApplication') {
         $tz = Yii::app()->user->getTZ();
         if ($tz != date_default_timezone_get()) {
             TimezoneWork::set($tz);
         }
     }
 }
Ejemplo n.º 17
0
 public function __destruct()
 {
     if (get_class(Yii::app()) != 'CConsoleApplication') {
         $tz = Yii::app()->user->getTZ();
         $this->_logger->log(__METHOD__ . ' $tz: ' . $tz);
         $this->_logger->log(__METHOD__ . ' $tz: ' . $tz);
         $this->_logger->log(__METHOD__ . ' $tz: ' . $tz);
         $this->_logger->log(__METHOD__ . ' $tz: ' . $tz);
         if ($tz != date_default_timezone_get()) {
             TimezoneWork::set($tz);
         }
     }
 }
Ejemplo n.º 18
0
 public function actionScheduleRegenerateReport()
 {
     // All reports are generated basing on data in UTC time.
     TimezoneWork::set('UTC');
     $return = array('ok' => 0);
     $schedule_processed_id = isset($_REQUEST['schedule_processed_id']) ? intval($_REQUEST['schedule_processed_id']) : null;
     if ($schedule_processed_id) {
         $data = ScheduleReportProcessed::getInfoForRegenerate($schedule_processed_id);
         if (!is_null($data)) {
             $reportType = null;
             switch ($data->ScheduleReportToStation->schedule_report->report_type) {
                 case 'bufr':
                     $reportType = 'Bufr';
                     break;
                 case 'synop':
                     $reportType = 'Synop';
                     break;
                 case 'metar':
                     $reportType = 'Metar';
                     break;
                 case 'speci':
                     $reportType = 'Speci';
                     break;
                 default:
                     $reportType = 'Export';
                     break;
             }
             $weather_report = WeatherReport::create($reportType);
             $weather_report->load($schedule_processed_id);
             if (!$weather_report->errors) {
                 $weather_report->generate();
                 $weather_report->prepareReportComplete();
                 $weather_report->saveProcess();
                 $return['ok'] = 1;
                 $return['report_string_initial'] = $weather_report->getReportComplete();
             } else {
                 $return['errors'] = $weather_report->errors;
             }
         }
     }
     print json_encode($return);
     CApplication::end();
 }