Skip to content

Commit

Permalink
Merge pull request #213 from Daveiano/196-all-time-stats-table
Browse files Browse the repository at this point in the history
Fixes GH-196
  • Loading branch information
Daveiano authored Oct 28, 2023
2 parents 7ee1512 + 52e8d98 commit 0553846
Show file tree
Hide file tree
Showing 23 changed files with 194 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -732,3 +732,4 @@ See https://github.com/Daveiano/weewx-wdc/compare/v3.2.0...11eed6b3#diff-ba225fb
- Only show 3 decimals for the geocode provided by weewx-forecast GH-191
- Make sidebar scrollable (if there are too many items) GH-193
- Make icon/logo user configurable GH-205
- Enhancement to the All Time Statistics: Show climatological days per month and per year. GH-196
1 change: 1 addition & 0 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def __init__(self):
"skins/weewx-wdc/includes/body-alternative.inc",
"skins/weewx-wdc/includes/forecast.inc",
"skins/weewx-wdc/includes/forecast-table.inc",
"skins/weewx-wdc/includes/year-stats-table.inc",
"skins/weewx-wdc/includes/icons/barometer.svg",
"skins/weewx-wdc/includes/pictograms/sun.svg",
"skins/weewx-wdc/includes/pictograms/moon.svg",
Expand Down
10 changes: 7 additions & 3 deletions skins/weewx-wdc/includes/climatological-days.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#end if

#set $show_rain_stats_table = ($context == 'alltime' and $to_bool($DisplayOptions.get('show_last_rain', True))) or (($most_days_with_rain is not None and $to_bool($DisplayOptions.get('show_most_days_with_rain', 'True'))) or ($most_days_without_rain is not None and $to_bool($DisplayOptions.get('show_most_days_without_rain', 'True'))) or $to_bool($DisplayOptions.get('show_most_rain_within_one_day', 'True')))
#set $show_climatological_days_per_month = $to_bool($DisplayOptions.get('climatological_days_per_month', True))

<script
type="module"
Expand All @@ -35,9 +36,7 @@
id="tab-diagram-rain"
target="panel-diagram-rain"
value="diagram-rain"
>
$gettext('rainDays')
</bx-tab>
>$obs.label.rain</bx-tab>
#end if
#if $getattr($get_time_span_from_context($context, $day, $week, $month, $year, $alltime, $yesterday), 'outTemp').has_data
<bx-tab
Expand Down Expand Up @@ -134,6 +133,11 @@
#end if
</bx-structured-list-body>
</bx-structured-list>

<!--prettier-ignore-->
#if $show_climatological_days_per_month
#include "includes/year-stats-table.inc"
#end if
</div>
<!--prettier-ignore-->
#if $getattr($get_time_span_from_context($context, $day, $week, $month, $year, $alltime, $yesterday), 'rain').has_data
Expand Down
168 changes: 168 additions & 0 deletions skins/weewx-wdc/includes/year-stats-table.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<!--prettier-ignore-->
#errorCatcher Echo
#encoding UTF-8

#import calendar
#import datetime
#from weeutil.weeutil import startOfDay, startOfArchiveDay

#set $first_option = $DisplayOptions.get('climatological_days', [])[0].replace(' ', '_').lower()

<script
type="module"
src="https://1.www.s81c.com/common/carbon/web-components/version/v1.21.0/tabs.min.js"
></script>

<script
type="module"
src="https://1.www.s81c.com/common/carbon/web-components/version/v1.21.0/structured-list.min.js"
></script>

<bx-tabs trigger-content="Select an item" value="$first_option" type="default">
<!--prettier-ignore-->
#for $clim_day in $DisplayOptions.get('climatological_days')
#set $clim_day_class = $clim_day.replace(' ', '_').lower()
<bx-tab
id="tab-$gettext($clim_day_class)"
target="panel-$gettext($clim_day_class)"
value="$gettext($clim_day_class)"
>$gettext($clim_day)</bx-tab
>
#end for
</bx-tabs>

<div class="bx-ce-demo-devenv--tab-panels">
<!--prettier-ignore-->
#for $clim_day in $DisplayOptions.get('climatological_days')
#set $clim_day_class = $clim_day.replace(' ', '_').lower()
<!--prettier-ignore-->
<div
class="climatological-day-table"
id="panel-$clim_day_class"
role="tabpanel"
aria-labelledby="tab-$clim_day_class"
hidden
>
#if $context == 'alltime'
#set $archive_months = $SummaryByMonth
#if len($SummaryByYear) == 0
#set $SummaryByYear = $fake_get_report_years($alltime.start.format("%Y"), $latest.dateTime.format("%Y"))
#end if
#elif $context == 'year'
#set $SummaryByYear = [str($year_name)]
#set $archive_months = $filter_months($SummaryByMonth, $year_name)
#end if

#set $totals_per_month = {}
#set $totals_per_year = {}

<bx-structured-list>
<bx-structured-list-head>
<bx-structured-list-header-row>
#if $context == "alltime"
<bx-structured-list-header-cell>
$gettext('Year')
</bx-structured-list-header-cell>
#end if

#for $month in range(1, 13)
<bx-structured-list-header-cell>
$gettext(calendar.month_abbr[$month])
</bx-structured-list-header-cell>
#end for

<bx-structured-list-header-cell>
$gettext('Total')
</bx-structured-list-header-cell>
</bx-structured-list-header-row>
</bx-structured-list-head>
<bx-structured-list-body>
#for $year in $SummaryByYear
<bx-structured-list-row>
#if $context == "alltime"
<bx-structured-list-cell>$year</bx-structured-list-cell>
#end if

#set $months_for_year = $filter_months($archive_months, $year)

#for $month in range(1, 13)
#if not $month in $totals_per_month
#set $totals_per_month[$month] = []
#end if
#set $month_from_range = $year + '-' + str($month).zfill(2)

#if $month_from_range in $months_for_year
<bx-structured-list-cell data-testid="$month_from_range">
#set $time_span_start_ts = $startOfDay($datetime.datetime.strptime($month_from_range, "%Y-%m").replace(day=1).timestamp())
#set $time_span_end_ts = $datetime.datetime.strptime($month_from_range, "%Y-%m").replace(day=$calendar.monthrange(int($year), int($month))[1], hour=23, minute=59).timestamp()

#set $number_of_days = $get_climatological_day($clim_day, $time_span_start_ts, $time_span_end_ts)
#set $totals_per_year[$year] = $number_of_days + $totals_per_year[$year] if $year in $totals_per_year else $number_of_days
#silent $totals_per_month[$month].append($number_of_days)

$number_of_days
</bx-structured-list-cell>
#else
<bx-structured-list-cell>-</bx-structured-list-cell>
#end if
#end for

<bx-structured-list-cell data-testid="year-$year">
#if $year in $totals_per_year
<strong>$totals_per_year[$year]</strong>
#else
<strong>-</strong>
#end if
</bx-structured-list-cell>
</bx-structured-list-row>
#end for
#if $context == 'alltime'
<bx-structured-list-row data-test="total">
<bx-structured-list-cell>
<strong>$gettext("Total")</strong>
</bx-structured-list-cell>
#for $month in range(1, 13)
#if $month in $totals_per_month
<bx-structured-list-cell data-testid="month-$month">
<strong>$sum($totals_per_month[$month])</strong>
</bx-structured-list-cell>
#else
<bx-structured-list-cell>-</bx-structured-list-cell>
#end if
#end for
<bx-structured-list-cell>
<strong>
$get_climatological_day($clim_day, $alltime.start.raw, $alltime.end.raw)
</strong>
</bx-structured-list-cell>
</bx-structured-list-row>
<bx-structured-list-row data-test="average">
<bx-structured-list-cell>
<strong>$gettext("Average")</strong>
</bx-structured-list-cell>
#for $month in range(1, 13)
#if $month in $totals_per_month and $len($totals_per_month[$month]) > 0
<bx-structured-list-cell data-testid="month-$month">
<strong>$round($sum($totals_per_month[$month]) / $len($totals_per_month[$month]), 1)</strong>
</bx-structured-list-cell>
#else
<bx-structured-list-cell>-</bx-structured-list-cell>
#end if
#end for

#if $len($SummaryByYear) > 0
<bx-structured-list-cell>
<strong>
$round($get_climatological_day($clim_day, $alltime.start.raw, $alltime.end.raw) / $len($SummaryByYear), 1)
</strong>
</bx-structured-list-cell>
#else
<bx-structured-list-cell>-</bx-structured-list-cell>
#end if
</bx-structured-list-row>
#end if
</bx-structured-list-body>
</bx-structured-list>
</div>
#end for
</div>
1 change: 1 addition & 0 deletions skins/weewx-wdc/skin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ SKIN_VERSION = 3.3.0

# These days will be shown on the year and statistics pages.
climatological_days = rainDays, summerDays, hotDays, desertDays, tropicalNights, stormDays, iceDays, frostDays
climatological_days_per_month = True
show_last_rain = True
show_most_days_with_rain = True
show_most_days_without_rain = True
Expand Down
4 changes: 4 additions & 0 deletions skins/weewx-wdc/src/scss/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,10 @@ bx-structured-list.forecast-list,
}
}

.climatological-day-table {
overflow-x: auto;
}

body.theme-classic {
div.bx--grid.bx--grid--full-width {
@include carbon--breakpoint-up(lg) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ test.describe("Climatological days", () => {
test("Rain Stats table", async ({ page }) => {
// Stats page.
const rainTable = page
.getByRole("tabpanel", { name: "Rain days" })
.getByRole("tabpanel", { name: "Rain", exact: true })
.locator(".clim-days-extended-table");

await page.getByRole("tab", { name: "Rain days" }).click();
await page.getByRole("tab", { name: "Rain", exact: true }).click();
await expect(rainTable).toBeVisible();

await expect(rainTable.getByTestId("last-rain")).toContainText(
Expand All @@ -112,7 +112,7 @@ test.describe("Climatological days", () => {
await page.goto(
"artifacts-alternative-weewx-html/public_html/year-2021.html"
);
await page.getByRole("tab", { name: "Rain days" }).click();
await page.getByRole("tab", { name: "Rain", exact: true }).click();
await expect(rainTable).toBeVisible();

await expect(rainTable.getByTestId("last-rain")).toHaveCount(0);
Expand All @@ -130,7 +130,7 @@ test.describe("Climatological days", () => {
await page.goto(
"artifacts-alternative-weewx-html/public_html/year-2022.html"
);
await page.getByRole("tab", { name: "Rain days" }).click();
await page.getByRole("tab", { name: "Rain", exact: true }).click();
await expect(rainTable).toBeVisible();

await expect(rainTable.getByTestId("last-rain")).toHaveCount(0);
Expand Down
1 change: 1 addition & 0 deletions test/test_install_report/src/skin-cmon.conf
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ SKIN_VERSION = 3.2.0

# These days will be shown on the year and statistics pages.
climatological_days = rainDays, summerDays, hotDays, desertDays, tropicalNights, stormDays, iceDays, frostDays
climatological_days_per_month = True

# What to show in the tables.
table_tile_observations = outTemp, outHumidity, barometer, windSpeed, windGust, windDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8
Expand Down
1 change: 1 addition & 0 deletions test/test_install_report/src/skin-custom-binding.conf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ SKIN_VERSION = 2.3.2

# These days will be shown on the year and statistics pages.
climatological_days = rainDays, summerDays, hotDays, desertDays, tropicalNights, stormDays, iceDays, frostDays
climatological_days_per_month = True

# What to show in the tables.
table_tile_observations = test_temp, outTemp, outHumidity, barometer, windSpeed, windGust, windDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8
Expand Down
1 change: 1 addition & 0 deletions test/test_install_report/src/skin-custom.conf
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ SKIN_VERSION = 2.2.1
[DisplayOptions]
layout = 'alternative'
climatological_days = rainDays, summerDays, hotDays, desertDays, tropicalNights, stormDays, iceDays, frostDays
climatological_days_per_month = True
table_tile_observations = outTemp, outHumidity, barometer, windSpeed, windGust, windDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8
stat_tile_observations = outTemp, outHumidity, barometer, windSpeed, windDir, windGust, windGustDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8

Expand Down
1 change: 1 addition & 0 deletions test/test_install_report/src/skin-dwd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ SKIN_VERSION = 2.3.0
[DisplayOptions]
layout = 'alternative'
climatological_days = rainDays, summerDays, hotDays, desertDays, tropicalNights, stormDays, iceDays, frostDays
climatological_days_per_month = True
table_tile_observations = outTemp, outHumidity, barometer, windSpeed, windGust, windDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8
stat_tile_observations = outTemp, outHumidity, barometer, windSpeed, windDir, windGust, windGustDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8
diagram_tile_observations = temp_min_max_avg, tempdew, outHumidity, barometer, windchill_heatindex, wind, windDir, windRose, rain, rainRate, snowDepth, UV, ET, radiation, cloudbase, appTemp
Expand Down
1 change: 1 addition & 0 deletions test/test_install_report/src/skin-forecast.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ SKIN_VERSION = 2.2.1
[DisplayOptions]
layout = 'alternative'
climatological_days = rainDays, summerDays, hotDays, desertDays, tropicalNights, stormDays, iceDays, frostDays
climatological_days_per_month = True
table_tile_observations = outTemp, outHumidity, barometer, windSpeed, windGust, windDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8
stat_tile_observations = outTemp, outHumidity, barometer, windSpeed, windDir, windGust, windGustDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8
diagram_tile_observations = temp_min_max_avg, tempdew, outHumidity, barometer, windchill_heatindex, wind, windDir, windRose, rain, rainRate, snowDepth, UV, ET, radiation, cloudbase, appTemp
Expand Down
1 change: 1 addition & 0 deletions test/test_install_report/src/skin-mqtt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ SKIN_VERSION = 2.3.0
[DisplayOptions]
layout = 'alternative'
climatological_days = rainDays, summerDays, hotDays, desertDays, tropicalNights, stormDays, iceDays, frostDays
climatological_days_per_month = True
table_tile_observations = outTemp, outHumidity, barometer, windSpeed, windGust, windDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8
stat_tile_observations = outTemp, outHumidity, barometer, windSpeed, windDir, windGust, windGustDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8

Expand Down
1 change: 1 addition & 0 deletions test/test_install_report/src/skin-sensor-status.conf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ SKIN_VERSION = 3.1.1

# These days will be shown on the year and statistics pages.
climatological_days = rainDays, summerDays, hotDays, desertDays, tropicalNights, stormDays, iceDays, frostDays
climatological_days_per_month = True

# What to show in the tables.
table_tile_observations = outTemp, outHumidity, barometer, windSpeed, windGust, windDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8
Expand Down
1 change: 1 addition & 0 deletions test/test_install_report/src/skin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ SKIN_VERSION = 2.3.0
[DisplayOptions]
layout = 'alternative'
climatological_days = rainDays, summerDays, hotDays, desertDays, tropicalNights, stormDays, iceDays, frostDays
climatological_days_per_month = True
table_tile_observations = outTemp, outHumidity, barometer, windSpeed, windGust, windDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8
stat_tile_observations = outTemp, outHumidity, barometer, windSpeed, windDir, windGust, windGustDir, rain, rainRate, snowDepth, dewpoint, windchill, heatindex, UV, ET, radiation, appTemp, cloudbase, extraTemp1, extraHumid1, extraTemp2, extraHumid2, extraTemp3, extraHumid3, extraTemp4, extraHumid4, extraTemp5, extraHumid5, extraTemp6, extraHumid6, extraTemp7, extraHumid7, extraTemp8, extraHumid8

Expand Down

0 comments on commit 0553846

Please sign in to comment.