Skip to content

Commit

Permalink
Merge pull request #1285 from weather-gov/eg-1252-additional-details
Browse files Browse the repository at this point in the history
Additional observation details
  • Loading branch information
eric-gade authored Jun 6, 2024
2 parents 909e750 + 9a365f3 commit 63951c5
Show file tree
Hide file tree
Showing 12 changed files with 415 additions and 202 deletions.
83 changes: 0 additions & 83 deletions tests/e2e/cypress/e2e/location-page.cy.js

This file was deleted.

85 changes: 85 additions & 0 deletions tests/playwright/e2e/location-page.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* eslint-disable no-await-in-loop, no-plusplus */
const { test, expect } = require("@playwright/test");

const { describe, beforeEach } = test;

describe("the location page", () => {
beforeEach(async ({page}) => {
await page.goto("http://localhost:8081/play/testing");
});

test("does not display marine alerts", async ({page}) => {
await page.goto("/point/33.521/-86.812");
const alertEl = page.locator("weathergov-alert-list > div");

await expect(alertEl).toHaveCount(1);
await expect(alertEl).toContainText("Wind Advisory");
await expect(alertEl).not.toContainText("Small Craft Advisory");
});

test("does include alerts based on fire zone", async ({page}) => {
await page.goto("/point/34.749/-92.275");
const alertEl = page.locator("weathergov-alert-list > div");

await expect(alertEl).toContainText("Red Flag Warning");
});

describe("shows n/a for unavailable data", () => {
test("wind is null", async ({page}) => {
await page.goto("/point/33.211/-87.566");
const windEl = page.locator(".weather-gov-current-conditions .wx-wind-speed > td");

await expect(windEl).toContainText("N/A");
});
});

describe("Radar component loading tests", () => {
test("does not kload if the current tab is not displaying", async ({page}) => {
await page.goto("/point/33.521/-86.812");
const radarContainer = page.locator("#wx_radar_container");

await expect(radarContainer).toBeEmpty();
});

test("loads correctly after switching to the current tab", async ({page}) => {
await page.goto("/point/33.521/-86.812");
const currentTab = page.locator('[data-tab-name="current"]');
const radarContainer = page.locator("#wx_radar_container");

await currentTab.click();

await expect(radarContainer).not.toBeVisible();
await page.pause();
});
});

describe("Page load error messages", () => {
test("should load the default tabbed view without any error messages", async ({page}) => {
await page.goto("/point/34.749/-92.275");
const errorEl = page.locator(".usa-alert--error");

await expect(errorEl).toHaveCount(0);
});

test("should load without any error messages in the today tab", async ({page}) => {
await page.goto("/point/34.749/-92.275#today");
const errorEl = page.locator(".usa-alert--error");

await expect(errorEl).toHaveCount(0);
});

test("should load without any error messages in the daily (7-day) tab", async ({page}) => {
await page.goto("/point/34.749/-92.275#daily");
const errorEl = page.locator(".usa-alert--error");

await expect(errorEl).toHaveCount(0);
});

test("should load without any error messages in the current conditions tab", async ({page}) => {
await page.goto("/point/34.749/-92.275#current");
const errorEl = page.locator(".usa-alert--error");

await expect(errorEl).toHaveCount(0);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ final class ObservationsStructureTest extends EndToEndBase
"angle" => 250,
],
],
"gusts" => null,
"pressure" => [
"mercury_inches" => 30.3,
"mbar" => 1026.1,
],
"dewpoint" => 22,
"visibility" => 10.0,
"stationInfo" => [
"name" => "Birmingham, Birmingham International Airport",
"identifier" => "KBHM",
Expand Down
30 changes: 30 additions & 0 deletions web/modules/weather_data/src/Service/ObservationsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ public function getCurrentConditionsFromGrid($wfo, $x, $y, $self = false)
);
}

// Get the barometric pressure or null
$pressure = $obs->barometricPressure;
if ($pressure->value == null) {
$pressure = null;
} else {
$pressure = [
"mbar" => round(
UnitConversion::getPressureScalar($pressure, false),
2, // round to 2 decimal places
),
"mercury_inches" => round(
UnitConversion::getPressureScalar($pressure),
2, // round to 2 decimal places
),
];
}

$description = ucfirst(strtolower($obs->textDescription));

return [
Expand All @@ -182,6 +199,7 @@ public function getCurrentConditionsFromGrid($wfo, $x, $y, $self = false)
"temperature" => UnitConversion::getTemperatureScalar(
$obs->temperature,
),
"dewpoint" => UnitConversion::getTemperatureScalar($obs->dewpoint),
"timestamp" => [
"formatted" => $timestamp->format("l g:i A T"),
"utc" => $timestamp->format("c"),
Expand All @@ -196,6 +214,18 @@ public function getCurrentConditionsFromGrid($wfo, $x, $y, $self = false)
$obs->windDirection->value,
),
],
"gusts" =>
$obs->windGust->value === null
? null
: UnitConversion::getSpeedScalar($obs->windGust),
"pressure" => $pressure,
"visibility" =>
$obs->visibility->value === null
? null
: round(
UnitConversion::getDistanceScalar($obs->visibility),
2,
),
"stationInfo" => [
"name" => $observationStation->properties->name,
"identifier" =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Drupal\weather_data\Service\Test;

use Drupal\weather_data\Service\UnitConversion;
use PHPUnit\Framework\TestCase;

final class PressureUnitConversionTest extends TestCase
{
/**
* Test when the pressure value is null
* @group unit
* @group units-utility
*/
public function testNullPressure(): void
{
$expected = null;
$actual = UnitConversion::getPressureScalar((object) ["value" => null]);

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

/**
* Test from Pa to mbar
* @group unit
* @group units-utility
*/
public function testPaToMbar(): void
{
$expected = 0.15;
$pressure = (object) [
"unitCode" => "wmoUnit:Pa",
"value" => 15,
];
$actual = UnitConversion::getPressureScalar($pressure, false);

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

/**
* Test from Pa to Mercury
* @group unit
* @group units-utility
*/
public function testPaToPsi(): void
{
$expected = 0.0044295;
$pressure = (object) [
"unitCode" => "wmoUnit:Pa",
"value" => 15,
];
$actual = round(UnitConversion::getPressureScalar($pressure), 7);

$this->assertEquals($expected, $actual);
}
}
49 changes: 49 additions & 0 deletions web/modules/weather_data/src/Service/UnitConversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,53 @@ public static function getTemperatureScalar(

return (int) round($out);
}

/**
* Get a pressure scalar from a wmoUnit pressure object
*/
public static function getPressureScalar(
\stdClass $pressure,
bool $inPsi = true,
) {
$rawValue = $pressure->value;

if ($rawValue == null) {
return null;
}

$inPa = $pressure->unitCode == "wmoUnit:Pa";

if ($inPsi) {
return $rawValue * 0.0002953;
} else {
return $rawValue * 0.01;
}
}

/**
* Get a distance scalar from objects like a visibility distance
*/
public static function getDistanceScalar(
\stdClass $distance,
bool $inMiles = true,
) {
$rawValue = $distance->value;

if ($rawValue == null) {
return null;
}

$inMeters = $distance->unitCode == "wmoUnit:m";

$valueInKm = $rawValue;
if ($inMeters) {
$valueInKm = $valueInKm * 0.001;
}

if ($inMiles) {
return $valueInKm * 0.6213711922;
} else {
return $valueInKm;
}
}
}
2 changes: 1 addition & 1 deletion web/themes/new_weather_theme/assets/css/styles.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/themes/new_weather_theme/assets/css/styles.css.map

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions web/themes/new_weather_theme/assets/sass/components/obs-table.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@use "uswds-core" as *;

/* Observation table overrides
------------------------------- */
.usa-table.observation-table {
td,
th {
vertical-align: top;
padding: units(1) units(4) units(0.5) inherit;
}

th { padding-left: 0; }

tr:first-of-type > td {
border-top: none;
}

tr:last-of-type > td,
tr:last-of-type > th {
border-bottom: none;
}

margin-top: 0;
line-height: line-height('body', 2);
}
1 change: 1 addition & 0 deletions web/themes/new_weather_theme/assets/sass/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
@use "components/frontpage";
@use "components/visual-page-headings";
@use "components/wx-loader";
@use "components/obs-table";
Loading

0 comments on commit 63951c5

Please sign in to comment.