Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add current satellite loop #1310

Merged
merged 9 commits into from
Aug 1, 2024
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
Loading