Slightly faster evaluation of the tag suffix 'has_data'.

New aggregation type 'not_null'.
New unit 'boolean'.
New unit group 'group_boolean'.
This commit is contained in:
Tom Keffer
2021-09-25 09:27:28 -07:00
parent ebd6d6e1ca
commit 9b69bb063d
9 changed files with 58 additions and 7 deletions

View File

@@ -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"

View File

@@ -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,

View File

@@ -458,7 +458,15 @@
<td>Test tag "has_data" with existent type that has data $day.outTemp.has_data</td>
<td>TRUE</td>
</tr>
<tr>
<tr>
<td>Test tag "not_null" with existent type that has no data $day.UV.not_null</td>
<td>0</td>
</tr>
<tr>
<td>Test tag "not_null" with existent type that has data $day.outTemp.not_null</td>
<td>1</td>
</tr>
<tr>
<td>Test for a bad observation type on a $day tag: $day.foobar.min</td>
<td>$day.foobar.min</td>
</tr>

View File

@@ -458,7 +458,15 @@
<td>Test tag "has_data" with existent type that has data $day.outTemp.has_data</td>
<td>TRUE</td>
</tr>
<tr>
<tr>
<td>Test tag "not_null" with existent type that has no data $day.UV.not_null</td>
<td>0</td>
</tr>
<tr>
<td>Test tag "not_null" with existent type that has data $day.outTemp.not_null</td>
<td>1</td>
</tr>
<tr>
<td>Test for a bad observation type on a $day tag: $day.foobar.min</td>
<td>$day.foobar.min</td>
</tr>

View File

@@ -458,7 +458,15 @@ FALSE#slurp
<td>Test tag "has_data" with existent type that has data \$day.outTemp.has_data</td>
<td>$emit_boolean($day.outTemp.has_data)</td>
</tr>
<tr>
<tr>
<td>Test tag "not_null" with existent type that has no data \$day.UV.not_null</td>
<td>$day.UV.not_null</td>
</tr>
<tr>
<td>Test tag "not_null" with existent type that has data \$day.outTemp.not_null</td>
<td>$day.outTemp.not_null</td>
</tr>
<tr>
<td>Test for a bad observation type on a \$day tag: \$day.foobar.min</td>
<td>$day.foobar.min</td>
</tr>

View File

@@ -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",

View File

@@ -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])

View File

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

View File

@@ -7031,6 +7031,12 @@ growing_base = 50.0, degree_F</pre>
<a href="#ValueTuple"><span class="code">ValueTuple</span></a>.
</td>
</tr>
<tr>
<td class="first_col code">not_null</td>
<td>
Returns truthy if any value over the aggregation period is non-null.
</td>
</tr>
<tr>
<td class="first_col code">rms</td>
<td>The root mean square value in the aggregation period.
@@ -7141,6 +7147,14 @@ growing_base = 50.0, degree_F</pre>
<td>amp</td>
<td>amp</td>
</tr>
<tr>
<td class="first_col">group_boolean</td>
<td></td>
<td>boolean</td>
<td>boolean</td>
<td>boolean</td>
<td>boolean</td>
</tr>
<tr>
<td class="first_col">group_concentration</td>
<td>no2<br/>pm1_0<br/>pm2_5<br/>pm10_0</td>