There is an API for calculating these things: XTypes
<https://github.com/weewx/weewx/wiki/WeeWX-V4-user-defined-types>. It will
automatically calculate using the daily summaries if it can. No need to do
the SQL queries directly.
It would look something like this. (NOT TESTED; highly schematic, parts
missing):
import weeutil.weeutil
import weewx.units
import weewx.xtypes
import weewx.restx
class WnsThread(weewx.restx.RESTThread):
...
def get_record(self, record, dbmanager):
# run parent class
_datadict = super(WnsThread, self).get_record(record, dbmanager)
# actual time stamp
_time_ts = _datadict['dateTime']
# Get the midnight-to-midnight time span:
timespan = weeutil.weeutil.archiveDaySpan(_time_ts)
# Use XTypes to calculate the aggregate. The result will be a
ValueTuple
temp_min_vt = weewx.xtypes.get_aggregate('outTemp', timespan,
'min', dbmanager)
temp_max_vt = weewx.xtypes.get_aggregate('outTemp', timespan,
'max', dbmanager)
# Convert to the same unit system as the incoming record. The
result of the conversion
# will be a ValueTuple. The first element of the tuple (subscript
'0') will be the actual
# value.
_datadict['outTempDayMin'] = weewx.units.convertStd(temp_min_vt,
record['usUnits'])[0]
_datadict['outTempDayMax'] = weewx.units.convertStd(temp_max_vt,
record['usUnits'])[0]
return _datadict
On Fri, Oct 30, 2020 at 7:57 AM Vince Skahan <[email protected]> wrote:
> On Friday, October 30, 2020 at 7:46:14 AM UTC-7, Karen K wrote:
>
>> I only wonder why those summeries are calculated, then. To no purpose? I
>> don't know.
>>
>>
> Pre-calculated info you can query much faster than aggregating the
> low-level archive data.
>
> Think of the NOAA reports. If you wanted to look back to see the
> hi/lo/ave info for a date in time, would you just look at the pre-computed
> info in those reports (which already has the info you want), or would you
> do a complicated db query to figure it out and do totals/averages/min/max
> calculations ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "weewx-development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-development/1729b30f-48cd-47c7-bfdc-c1efc7505f23o%40googlegroups.com
> <https://groups.google.com/d/msgid/weewx-development/1729b30f-48cd-47c7-bfdc-c1efc7505f23o%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
You received this message because you are subscribed to the Google Groups
"weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-development/CAPq0zEDaut%2B%2ByySrc6FP8t8YAMVoLyzMOwJfTDQwKoooF-sB8g%40mail.gmail.com.