Exemplo n.º 1
0
// Current time
$now = time();
$imgIndex = new Database_ImgIndex();
// Get a list of the datasources grouped by instrument
$instruments = $imgIndex->getDataSourcesByInstrument();
$tableRow = "<tr class='%s'><td>%s</td><td>%s</td><td>%s</td><td align='center'>%s</td></tr>";
// Create table of datasource statuses
foreach ($instruments as $name => $datasources) {
    $oldest = array("level" => 0, "datetime" => new DateTime(), "icon" => null);
    $maxElapsed = 0;
    $oldestDate = null;
    $subTableHTML = "";
    // Create table row for a single datasource
    foreach ($datasources as $ds) {
        // Determine status icon to use
        $date = $imgIndex->getNewestData($ds['id']);
        $elapsed = $now - strtotime($date);
        $level = computeStatusLevel($elapsed, $name);
        // Create status icon
        $icon = getStatusIcon($level);
        // Convert to human-readable date
        $timestamp = strtotime($date);
        $datetime = new DateTime();
        $datetime->setTimestamp($timestamp);
        // CSS classes for row
        $classes = "datasource {$name}";
        // create HTML for subtable row
        $subTableHTML .= sprintf($tableRow, $classes, "&nbsp;&nbsp;&nbsp;&nbsp;" . $ds['name'], $datetime->format('M j Y H:i:s'), "", $icon);
        // If the elapsed time is greater than previous max store it
        if ($datetime < $oldest['datetime']) {
            $oldest = array('level' => $level, 'datetime' => $datetime, 'icon' => $icon);
Exemplo n.º 2
0
 /**
  * Returns status information (i.e. time of most recent available data)
  * based on either observatory, instrument, detector or measurement.
  *
  * There are two types of queries that can be made:
  *
  * (1) instrument
  *
  * If key is set to instrument, then the time of the data source associated
  * with that instrument that is lagging the furthest behind is returned.
  *
  * (2) nickname
  *
  * If the key is set to nickname, then the most recent image times
  * are returned for all datasources, sorted by instrument.
  */
 public function getStatus()
 {
     // Connect to database
     include_once HV_ROOT_DIR . '/../src/Database/ImgIndex.php';
     include_once HV_ROOT_DIR . '/../src/Helper/DateTimeConversions.php';
     $imgIndex = new Database_ImgIndex();
     // Default to instrument-level status information
     if (!isset($this->_options['key'])) {
         $this->_options['key'] = 'instrument';
     }
     $statuses = array();
     // Case 1: instrument
     $instruments = $imgIndex->getDataSourcesByInstrument();
     // Date format
     $format = 'Y-m-d H:i:s';
     // Current time
     $now = new DateTime();
     // Iterate through instruments
     foreach ($instruments as $inst => $dataSources) {
         $oldest = new DateTime('2035-01-01');
         // Keep track of which datasource is the furthest behind
         foreach ($dataSources as $dataSource) {
             // Get date string for most recent image
             $dateStr = $imgIndex->getNewestData($dataSource['id']);
             // Skip data source if no images are found
             if (is_null($dateStr)) {
                 continue;
             }
             // Convert to DateTime
             $date = DateTime::createFromFormat($format, $dateStr);
             // Store if older
             if ($date < $oldest) {
                 $oldest = $date;
             }
         }
         // Get elapsed time
         $delta = $now->getTimestamp() - $oldest->getTimestamp();
         // Add to result array
         if ($delta > 0) {
             $statuses[$inst] = array('time' => toISOString($oldest), 'level' => $this->_computeStatusLevel($delta, $inst), 'secondsBehind' => $delta);
         }
     }
     // Get a list of the datasources grouped by instrument
     $this->_printJSON(json_encode($statuses));
 }