Skip to content

Commit

Permalink
Added clim. days table per year/month to stats page.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daveiano committed Oct 27, 2023
1 parent c8b22f4 commit 6baca1e
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 11 deletions.
3 changes: 3 additions & 0 deletions skins/weewx-wdc/includes/climatological-days.inc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
#end if
</bx-structured-list-body>
</bx-structured-list>

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

#import calendar
#import datetime

#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>

<bx-tabs
trigger-content="Select an item"
value="$first_option"
type="container"
>
<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()
Expand All @@ -39,6 +43,88 @@
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

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

<bx-structured-list>
<bx-structured-list-head>
<bx-structured-list-header-row>
<bx-structured-list-header-cell>
$gettext('Year')
</bx-structured-list-header-cell>

#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>
<bx-structured-list-cell>$year</bx-structured-list-cell>

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

#for $month in range(1, 13)
#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 = $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]).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
#set $totals_per_month[$month] = $number_of_days + $totals_per_month[$month] if $month in $totals_per_month else $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
<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>$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-body>
</bx-structured-list>
#end if
</div>
#end for
Expand Down
6 changes: 0 additions & 6 deletions skins/weewx-wdc/statistics.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@
#include "includes/climatological-days.inc"
</div>
</div>
<div class="bx--row">
<div class="bx--col">
<!--prettier-ignore-->
#include "includes/year-stats-table.inc"
</div>
</div>
#end if

<!--prettier-ignore-->
Expand Down

0 comments on commit 6baca1e

Please sign in to comment.