Esempio n. 1
0
 /**
  * Retrieves the latest usage statistics from the database
  */
 public function getDataCoverage()
 {
     include_once HV_ROOT_DIR . '/../src/Helper/HelioviewerLayers.php';
     include_once HV_ROOT_DIR . '/../src/Helper/HelioviewerEvents.php';
     // Data Layers
     if (!empty($this->_options['imageLayers'])) {
         $layers = new Helper_HelioviewerLayers($this->_options['imageLayers']);
     } else {
         $layers = null;
     }
     // Events Layers
     if (!empty($this->_options['eventLayers'])) {
         $events = new Helper_HelioviewerEvents($this->_params['eventLayers']);
     } else {
         $events = null;
     }
     $start = @$this->_options['startDate'];
     if ($start && !preg_match('/^[0-9]+$/', $start)) {
         die("Invalid start parameter: {$start}");
     }
     $end = @$this->_options['endDate'];
     if ($end && !preg_match('/^[0-9]+$/', $end)) {
         die("Invalid end parameter: {$end}");
     }
     $current = @$this->_options['currentDate'];
     if ($current && !preg_match('/^[0-9]+$/', $current)) {
         die("Invalid end parameter: {$current}");
     }
     if (!$start) {
         $start = 0;
     }
     if (!$end) {
         $end = time() * 1000;
     }
     if (!$current) {
         $current = 0;
     }
     // set some utility variables
     $range = $end - $start;
     $startDate = gmstrftime('%Y-%m-%d %H:%M:%S', $start / 1000) + 60;
     $endDate = gmstrftime('%Y-%m-%d %H:%M:%S', $end / 1000) - 60;
     // find the right range
     if ($range < 105 * 60 * 1000) {
         $resolution = 'm';
         // 12 hours range loads hourly data
     } elseif ($range < 12 * 3600 * 1000) {
         $resolution = '5m';
         // one month range loads hourly data
     } elseif ($range < 2 * 24 * 3600 * 1000) {
         $resolution = '15m';
         // one month range loads hourly data
     } elseif ($range < 10 * 24 * 3600 * 1000) {
         $resolution = 'h';
         // one year range loads daily data
     } elseif ($range < 6 * 31 * 24 * 3600 * 1000) {
         $resolution = 'D';
         // half year range loads daily data
     } elseif ($range < 15 * 31 * 24 * 3600 * 1000) {
         $resolution = 'W';
         // greater range loads monthly data
     } else {
         $resolution = 'M';
     }
     //$resolution = 'm';
     $dateEnd = new DateTime();
     if (isset($this->_options['endDate'])) {
         $dateEnd->setTimestamp($this->_options['endDate'] / 1000);
     } else {
         $dateEnd->setTimestamp($end / 1000);
     }
     $dateStart = new DateTime();
     if (isset($this->_options['startDate'])) {
         $dateStart->setTimestamp($this->_options['startDate'] / 1000);
     } else {
         $dateStart->setTimestamp($start / 1000);
     }
     $dateCurrent = new DateTime();
     if (isset($this->_options['currentDate'])) {
         $dateCurrent->setTimestamp($this->_options['currentDate']);
     } else {
         $dateCurrent->setTimestamp($current);
     }
     include_once HV_ROOT_DIR . '/../src/Database/Statistics.php';
     $statistics = new Database_Statistics();
     if ($layers != null) {
         $this->_printJSON($statistics->getDataCoverage($layers, $resolution, $dateStart, $dateEnd));
     } else {
         if ($events != null) {
             if ($range < 24 * 60 * 60 * 1000) {
                 $resolution = 'm';
             }
             if ($resolution == '5m' || $resolution == '15m') {
                 $resolution = '30m';
             }
             $this->_printJSON($statistics->getDataCoverageEvents($events, $resolution, $dateStart, $dateEnd, $dateCurrent));
         }
     }
 }