Skip to content

Commit

Permalink
Merge pull request #1310 from weather-gov/mgwalker/satellite
Browse files Browse the repository at this point in the history
Add current satellite loop
  • Loading branch information
greg-does-weather committed Aug 1, 2024
2 parents 2f1d253 + fb20ffc commit b47e41c
Show file tree
Hide file tree
Showing 10 changed files with 641 additions and 3 deletions.
23 changes: 23 additions & 0 deletions web/modules/weather_blocks/weather_blocks.module
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function weather_blocks_template_preprocess_default_variables_alter(
try {
$grid = $weatherData->getGridFromLatLon($lat, $lon);

$weatherMetadata["grid"] = $grid;

$alerts = $weatherData->getAlerts(
$grid,
SpatialUtility::pointArrayToObject([$lon, $lat]),
Expand All @@ -48,6 +50,27 @@ function weather_blocks_template_preprocess_default_variables_alter(
}
} catch (Throwable $e) {
}

try {
$wfo = strtolower($weatherMetadata["grid"]->wfo);
$satellite = $weatherData->getSatelliteMetadata($wfo);

$goes = "GOES16";
$satellite = $satellite->meta->satellite;
if ($satellite == "GOES-West") {
$goes = "GOES18";
}

if ($satellite) {
$weatherMetadata["satellite"] = [
"gif" =>
"https://cdn.star.nesdis.noaa.gov/WFO/$wfo/GEOCOLOR/$goes-" .
strtoupper($wfo) .
"-GEOCOLOR-600x600.gif",
];
}
} catch (Throwable $e) {
}
}

$variables["weather"] = $weatherMetadata;
Expand Down
11 changes: 11 additions & 0 deletions web/modules/weather_data/src/Service/DataLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,17 @@ public function getPlaceNearPolygon($points)
return self::$i_placeNearPolygon[$wktPoints];
}

public function getSatelliteMetadata($wfo)
{
$wfo = strtolower($wfo);
$url =
"https://cdn.star.nesdis.noaa.gov/WFO/catalogs/WFO_02_" .
$wfo .
"_catalog.json";
$response = $this->fetch($url)->wait();
return $response;
}

public function databaseFetch($sql)
{
return $this->database->query($sql)->fetch();
Expand Down
32 changes: 32 additions & 0 deletions web/modules/weather_data/src/Service/Test/DataLayer.php.test
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,36 @@ final class DataLayerTest extends TestCase

$this->assertEquals($expected, $actual);
}

/**
* @group unit
* @group data-layer
*/
public function testGetSatelliteMetadata(): void
{
$expected = (object) [
"satellite" => "is got",
];

$dataLayer = $this->getDataLayer(false);
$this->httpClient->append(
new Response(
200,
["Content-type", "application/json"],
json_encode($expected),
),
);

$actual = $dataLayer->getSatelliteMetadata("BOB");

$this->assertEquals($expected, $actual);
$this->assertEquals(
"GET",
$this->httpHistory[0]["request"]->getMethod(),
);
$this->assertEquals(
"/WFO/catalogs/WFO_02_bob_catalog.json",
$this->httpHistory[0]["request"]->getURI()->getPath(),
);
}
}
Loading

0 comments on commit b47e41c

Please sign in to comment.