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

147 stat sum obs #156

Merged
merged 8 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"workbox-strategies": "^6.5.3"
},
"devDependencies": {
"@playwright/test": "1.31.2",
"@playwright/test": "latest",
"@types/carbon-components-react": "^7.46.1",
"@types/carbon__icons-react": "^10.24.0",
"@types/color": "^3.0.3",
Expand Down
7 changes: 7 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ const config: PlaywrightTestConfig = {
// ...devices["Desktop Safari"],
// viewport: { width: 1920, height: 1000 },
// },
// timeout: 50 * 1000,
// expect: {
// timeout: 25000,
// toHaveScreenshot: {
// maxDiffPixelRatio: 0.07,
// },
// },
// },

/* Test against mobile viewports. */
Expand Down
2 changes: 1 addition & 1 deletion skins/weewx-wdc/includes/body-alternative.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="bx--row">
<!--prettier-ignore-->
#for $skin_obs in $DisplayOptions.get('stat_tile_observations')
#if $skin_obs != 'windDir' and $skin_obs != 'windGustDir'
#if $skin_obs != 'windDir' and $skin_obs != 'windGustDir' and $skin_obs != 'rainRate'
#set $skin_obs_binding = $get_data_binding($skin_obs)

## I dont know why but $alltime($data_binding=$skin_obs_binding) crashes on the month-%Y-%m and year-%Y pages:
Expand Down
215 changes: 143 additions & 72 deletions skins/weewx-wdc/includes/stat-tile.inc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions skins/weewx-wdc/lang/de.conf
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"Sum week" = "Wöchentlich Total"
"Avg week" = "Wöchentlicher Durchschnitt"
"Total week" = "Wöchentliche Gesamtmenge"
"Total week short" = "Wö. Gesamt"
"Max month" = "Monatlich Max"
"Min month" = "Monatlich Min"
"Sum month" = "Monatlich Total"
Expand Down
1 change: 1 addition & 0 deletions skins/weewx-wdc/lang/en.conf
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"Sum week" = "Weekly Total"
"Avg week" = "Weekly average"
"Total week" = "Weekly totals"
"Total week short" = "Weekly totals"
"Max month" = "Monthly Max"
"Min month" = "Monthly Min"
"Sum month" = "Monthly Total"
Expand Down
1 change: 1 addition & 0 deletions skins/weewx-wdc/lang/it.conf
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
"Sum week" = "Totale Settimanale"
"Avg week" = "Media Settimanale"
"Total week" = "Totale Settimanale"
"Total week short" = "Totale Settimanale"
"Max month" = "Massimo Mensile"
"Min month" = "Minimo Mensile"
"Sum month" = "Totale Mensile"
Expand Down
55 changes: 52 additions & 3 deletions skins/weewx-wdc/src/js/live-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,26 @@ const _updateStatTile = (
unitMQTT: string
) => {
// Update the main value.
statTile.querySelector(
".stat-title-obs-value .raw"
)!.innerHTML = `${value}${unit}`;
const sumObs = statTile
.querySelector(".stat-title-obs-value .raw")
?.classList.contains("raw-sum");

if (sumObs) {
// Use the dayXXX value (sum).
const sumValue =
payLoad[
`day${observation[0].toUpperCase()}${observation.slice(1)}_${unitMQTT}`
];

statTile.querySelector(
".stat-title-obs-value .raw"
)!.innerHTML = `${parseFloat(sumValue).toFixed(rounding)}${unit}`;
} else {
// Use the current value.
statTile.querySelector(
".stat-title-obs-value .raw"
)!.innerHTML = `${value}${unit}`;
}

// For eg. the windDir arrows on the windSpeed and gustSpeed tiles.
const statTileDetail = statTile.querySelector(
Expand Down Expand Up @@ -183,6 +200,38 @@ const _updateStatTile = (
sumValue
).toFixed(rounding)}${unit}`;
}

// rainRate handling - rainRate is displayed in the rain tile.
if (observation === "rain") {
let rainRate: number | null = null;
if (payLoad["rainRate_inch_per_hour"]) {
rainRate = parseFloat(payLoad["rainRate_inch_per_hour"]);
} else if (payLoad["rainRate_mm_per_hour"]) {
rainRate = parseFloat(payLoad["rainRate_mm_per_hour"]);
} else if (payLoad["rainRate_cm_per_hour"]) {
rainRate = parseFloat(payLoad["rainRate_cm_per_hour"]);
}

if (rainRate === null) return;

const rainRateCurrent = statTile.querySelector(".value-rain-rate-current"),
rainRateMax = statTile.querySelector(".value-rain-rate-max"),
rainRateMaxValue = rainRateMax
? rainRateMax!.querySelector(".stat-value span.value")!.innerHTML
: "";

if (rainRateCurrent) {
rainRateCurrent.querySelector(
".stat-value span.value"
)!.textContent = `${rainRate.toFixed(rounding)}${unit}`;
}

if (rainRateMax && rainRate > parseFloat(rainRateMaxValue)) {
rainRateMax.querySelector(
".stat-value span.value"
)!.textContent = `${rainRate.toFixed(rounding)}${unit}`;
}
}
};

const _updateTableRow = (
Expand Down
70 changes: 52 additions & 18 deletions test/e2e-tests/stat-tiles/stat-tiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ test.describe("Stat tiles", () => {
await expect(windSpeed.locator("[data-test='min']")).toHaveCount(0);

const rain = page.locator(".stat-tile[data-test='rain']");
await expect(rain.locator(".value > span")).toHaveText("0.00 cm");
await expect(rain.locator("[data-test='sum'] .stat-value")).toHaveText(
"0.00 cm"
);
await expect(rain.locator(".value > span")).toContainText("0.00 cm Totals");
await expect(
rain.locator("[data-test='rain-rate-current'] .stat-value")
).toHaveText("0.00 cm/h");
await expect(rain.locator(".value > span")).toContainText("0.00 cm Totals");
await expect(
rain.locator("[data-test='rain-rate-max'] .stat-value")
).toHaveText("0.00 cm/h");
await expect(rain.locator("[data-test='min']")).toHaveCount(0);
await expect(rain.locator("[data-test='max']")).toHaveCount(0);

Expand All @@ -39,6 +43,16 @@ test.describe("Stat tiles", () => {
await expect(radiation.locator("[data-test='min']")).toHaveCount(0);
await expect(radiation.locator("[data-test='sum']")).toHaveCount(0);

const et = page.locator(".stat-tile[data-test='ET']");
await expect(et.locator(".value span.stat-title-obs-value")).toContainText(
"0.01 cm Totals"
);
await expect(et.locator("[data-test='min']")).toHaveCount(0);
await expect(et.locator("[data-test='max']")).toHaveCount(0);
await expect(et.locator("[data-test='total-week'] .stat-value")).toHaveText(
"1.37 cm"
);

// Test Icons.
expect(await outTemp.locator(".value svg").innerHTML()).toMatchSnapshot();
expect(
Expand Down Expand Up @@ -100,20 +114,6 @@ test.describe("Stat tiles", () => {
"37.4°C"
);

const rainRate = page.locator(".stat-tile[data-test='rainRate']");
await expect(rainRate.locator(".value span >> nth=0")).toContainText(
"0.00 cm/h"
);
await expect(rainRate.locator("[data-test='min'] .stat-value")).toHaveCount(
0
);
await expect(rainRate.locator("[data-test='sum'] .stat-value")).toHaveCount(
0
);
await expect(rainRate.locator("[data-test='max'] .stat-value")).toHaveText(
"0.30 cm/h"
);

const rain = page.locator(".stat-tile[data-test='rain']");
await expect(rain.locator(".value span >> nth=0")).toContainText("0.00 cm");
await expect(rain.locator("[data-test='min'] .stat-value")).toHaveCount(0);
Expand All @@ -123,6 +123,40 @@ test.describe("Stat tiles", () => {
);
});

test("Rain tile", async ({ page }) => {
await page.goto("artifacts-alternative-weewx-html/public_html/week.html");

let rain = page.locator(".stat-tile[data-test='rain']");
await expect(rain.locator(".value span >> nth=0")).toContainText(
"0.12 cm Totals"
);
await expect(rain.locator("[data-test='min'] .stat-value")).toHaveCount(0);
await expect(rain.locator("[data-test='sum'] .stat-value")).toHaveCount(0);
await expect(rain.locator("[data-test='max'] .stat-value")).toHaveCount(0);
await expect(
rain.locator("[data-test='rain-days'] .stat-value")
).toHaveText("1");
await expect(
rain.locator("[data-test='rain-rate-max'] .stat-value")
).toHaveText("0.30 cm/h");

await page.goto("artifacts-alternative-weewx-html/public_html/year.html");

rain = page.locator(".stat-tile[data-test='rain']");
await expect(rain.locator(".value span >> nth=0")).toContainText(
"18.74 cm Totals"
);
await expect(rain.locator("[data-test='min'] .stat-value")).toHaveCount(0);
await expect(rain.locator("[data-test='sum'] .stat-value")).toHaveCount(0);
await expect(rain.locator("[data-test='max'] .stat-value")).toHaveCount(0);
await expect(
rain.locator("[data-test='rain-days'] .stat-value")
).toHaveText("65");
await expect(
rain.locator("[data-test='rain-rate-max'] .stat-value")
).toHaveText("1.86 cm/h");
});

test("Custom Icons", async ({ page }) => {
await page.goto("artifacts-custom-weewx-html/public_html/index.html");

Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -706,19 +706,19 @@ __metadata:
languageName: node
linkType: hard

"@playwright/test@npm:1.31.2":
version: 1.31.2
resolution: "@playwright/test@npm:1.31.2"
"@playwright/test@npm:latest":
version: 1.32.3
resolution: "@playwright/test@npm:1.32.3"
dependencies:
"@types/node": "*"
fsevents: 2.3.2
playwright-core: 1.31.2
playwright-core: 1.32.3
dependenciesMeta:
fsevents:
optional: true
bin:
playwright: cli.js
checksum: 5459ee0ce15b9a54337f4c26e2ee2d29c11e67e6207c167158eb180a4bea6659c988a2897f51dbebf591fc879f0d81f417e70936b9d8a001448c957939882588
checksum: f248e5851d04183954ec6f3a5f2c8e3b0ea0085a83e0e695068c5c2eb6acd4dddb16829a429829a4eb9fe0a4518f6a5594890cf9bf4259255c9e07a5964be625
languageName: node
linkType: hard

Expand Down Expand Up @@ -4718,12 +4718,12 @@ __metadata:
languageName: node
linkType: hard

"playwright-core@npm:1.31.2":
version: 1.31.2
resolution: "playwright-core@npm:1.31.2"
"playwright-core@npm:1.32.3":
version: 1.32.3
resolution: "playwright-core@npm:1.32.3"
bin:
playwright: cli.js
checksum: bf1257b7d80b9d027c99cbfa7ab9d47a2110ec804422b3e3d623bbb3c43e06df7bec4764ca1d852a6d62c76e35c8776efb19941f42ce738db9bc92e7f1b6281c
checksum: 7ea091c41a7d1bb97b445bc541a85b123ffcf167bcc00fb7e13e9079f06c92f59fd27caf9d1c1d7e0054f2b5765d1a16d198833c2be7266cebb9dbb916cd90f4
languageName: node
linkType: hard

Expand Down Expand Up @@ -5949,7 +5949,7 @@ __metadata:
"@nivo/calendar": ^0.79.1
"@nivo/core": ^0.79.0
"@nivo/line": ^0.79.1
"@playwright/test": 1.31.2
"@playwright/test": latest
"@react-hook/media-query": ^1.1.1
"@types/carbon-components-react": ^7.46.1
"@types/carbon__icons-react": ^10.24.0
Expand Down