diff --git a/bin/weewx/defaults.py b/bin/weewx/defaults.py index 5624529d..a44a7d2f 100644 --- a/bin/weewx/defaults.py +++ b/bin/weewx/defaults.py @@ -61,6 +61,7 @@ log_failure = False group_volume = gallon # The following are used internally and should not be changed: + group_boolean = boolean group_count = count group_interval = minute group_time = unix_epoch @@ -69,10 +70,11 @@ log_failure = False # The following section sets the formatting for each type of unit. [[StringFormats]] + boolean = %d centibar = %.0f cm = %.2f cm_per_hour = %.2f - count = %.0f + count = %d degree_C = %.1f degree_F = %.1f degree_compass = %.0f @@ -107,6 +109,7 @@ log_failure = False # The following section sets the label to be used for each type of unit [[Labels]] + boolean = "" centibar = " cb" cm = " cm" cm_per_hour = " cm/h" diff --git a/bin/weewx/manager.py b/bin/weewx/manager.py index d66f8da6..2deaf78c 100644 --- a/bin/weewx/manager.py +++ b/bin/weewx/manager.py @@ -258,9 +258,8 @@ class Manager(object): data. """ - # return self.exists(obs_type) and self.getAggregate(timespan, obs_type, 'count')[0] != 0 return self.exists(obs_type) \ - and weewx.xtypes.get_aggregate(obs_type, timespan, 'count', self)[0] + and weewx.xtypes.get_aggregate(obs_type, timespan, 'not_null', self)[0] def addRecord(self, record_obj, accumulator=None, diff --git a/bin/weewx/tests/expected/StandardTest/index.html b/bin/weewx/tests/expected/StandardTest/index.html index 684f52fe..e433b095 100644 --- a/bin/weewx/tests/expected/StandardTest/index.html +++ b/bin/weewx/tests/expected/StandardTest/index.html @@ -458,7 +458,15 @@ Test tag "has_data" with existent type that has data $day.outTemp.has_data TRUE - + + Test tag "not_null" with existent type that has no data $day.UV.not_null + 0 + + + Test tag "not_null" with existent type that has data $day.outTemp.not_null + 1 + + Test for a bad observation type on a $day tag: $day.foobar.min $day.foobar.min diff --git a/bin/weewx/tests/expected/StandardTest/metric/index.html b/bin/weewx/tests/expected/StandardTest/metric/index.html index 72939182..c3d00c59 100644 --- a/bin/weewx/tests/expected/StandardTest/metric/index.html +++ b/bin/weewx/tests/expected/StandardTest/metric/index.html @@ -458,7 +458,15 @@ Test tag "has_data" with existent type that has data $day.outTemp.has_data TRUE - + + Test tag "not_null" with existent type that has no data $day.UV.not_null + 0 + + + Test tag "not_null" with existent type that has data $day.outTemp.not_null + 1 + + Test for a bad observation type on a $day tag: $day.foobar.min $day.foobar.min diff --git a/bin/weewx/tests/test_skins/StandardTest/index.html.tmpl b/bin/weewx/tests/test_skins/StandardTest/index.html.tmpl index 4f1fc019..d8ed900f 100644 --- a/bin/weewx/tests/test_skins/StandardTest/index.html.tmpl +++ b/bin/weewx/tests/test_skins/StandardTest/index.html.tmpl @@ -458,7 +458,15 @@ FALSE#slurp Test tag "has_data" with existent type that has data \$day.outTemp.has_data $emit_boolean($day.outTemp.has_data) - + + Test tag "not_null" with existent type that has no data \$day.UV.not_null + $day.UV.not_null + + + Test tag "not_null" with existent type that has data \$day.outTemp.not_null + $day.outTemp.not_null + + Test for a bad observation type on a \$day tag: \$day.foobar.min $day.foobar.min diff --git a/bin/weewx/units.py b/bin/weewx/units.py index b45bc95e..38bebf2a 100644 --- a/bin/weewx/units.py +++ b/bin/weewx/units.py @@ -227,6 +227,7 @@ agg_group = { 'min_le' : "group_count", 'minmaxtime' : "group_time", 'mintime' : "group_time", + 'not_null' : "group_boolean", 'sum_ge' : "group_count", 'sum_le' : "group_count", 'vecdir' : "group_direction", @@ -239,6 +240,7 @@ agg_group = { USUnits = ListOfDicts({ "group_altitude" : "foot", "group_amp" : "amp", + "group_boolean" : "boolean", "group_concentration": "microgram_per_meter_cubed", "group_count" : "count", "group_data" : "byte", @@ -276,6 +278,7 @@ USUnits = ListOfDicts({ MetricUnits = ListOfDicts({ "group_altitude" : "meter", "group_amp" : "amp", + "group_boolean" : "boolean", "group_concentration": "microgram_per_meter_cubed", "group_count" : "count", "group_data" : "byte", @@ -468,6 +471,7 @@ conversionDict = { default_unit_format_dict = { "amp" : "%.1f", "bit" : "%.0f", + "boolean" : "%d", "byte" : "%.0f", "centibar" : "%.0f", "cm" : "%.2f", diff --git a/bin/weewx/xtypes.py b/bin/weewx/xtypes.py index 0e4225ef..40bd7651 100644 --- a/bin/weewx/xtypes.py +++ b/bin/weewx/xtypes.py @@ -240,6 +240,8 @@ class ArchiveTable(XType): 'mintime': "SELECT dateTime FROM %(table_name)s " "WHERE dateTime > %(start)s AND dateTime <= %(stop)s " "AND %(obs_type)s IS NOT NULL ORDER BY %(obs_type)s ASC LIMIT 1", + 'not_null': "SELECT %(obs_type)s IS NOT NULL FROM %(table_name)s " + "WHERE dateTime > %(start)s AND dateTime <= %(stop)s LIMIT 1", 'tderiv': "SELECT (b.%(obs_type)s - a.%(obs_type)s) / (b.dateTime-a.dateTime) " "FROM archive a, archive b " "WHERE b.dateTime = (SELECT MAX(dateTime) FROM archive " @@ -383,6 +385,8 @@ class DailySummaries(XType): "WHERE dateTime >= %(start)s AND dateTime < %(stop)s " "AND mintime IS NOT NULL " "ORDER BY min ASC, mintime ASC LIMIT 1", + 'not_null': "SELECT count>0 FROM %(table_name)s_day_%(obs_key)s " + "WHERE dateTime >= %(start)s AND dateTime < %(stop)s LIMIT 1", 'rms': "SELECT SUM(wsquaresum),SUM(sumtime) FROM %(table_name)s_day_%(obs_key)s " "WHERE dateTime >= %(start)s AND dateTime < %(stop)s", 'sum': "SELECT SUM(sum) FROM %(table_name)s_day_%(obs_key)s " @@ -469,7 +473,7 @@ class DailySummaries(XType): elif aggregate_type in ['mintime', 'maxmintime', 'maxtime', 'minmaxtime', 'maxsumtime', 'minsumtime', 'count', 'max_ge', 'max_le', 'min_ge', 'min_le', - 'sum_ge', 'sum_le', 'avg_ge', 'avg_le']: + 'not_null', 'sum_ge', 'sum_le', 'avg_ge', 'avg_le']: # These aggregates are always integers: value = int(row[0]) diff --git a/docs/changes.txt b/docs/changes.txt index 2aaa4bd2..81b80e93 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -116,6 +116,9 @@ service. Added option --batch-size to the Vantage version of wee_device. See PR #693. +Slightly faster evaluation of the tag suffix 'has_data'. +New aggregation type 'not_null'. + 4.4.0 01/30/2021 diff --git a/docs/customizing.htm b/docs/customizing.htm index 91d1cb7b..ca68f184 100644 --- a/docs/customizing.htm +++ b/docs/customizing.htm @@ -7031,6 +7031,12 @@ growing_base = 50.0, degree_F ValueTuple. + + not_null + + Returns truthy if any value over the aggregation period is non-null. + + rms The root mean square value in the aggregation period. @@ -7141,6 +7147,14 @@ growing_base = 50.0, degree_F amp amp + + group_boolean + + boolean + boolean + boolean + boolean + group_concentration no2
pm1_0
pm2_5
pm10_0