On Friday, 29 March 2019 09:09:17 UTC+10, p q wrote:
>
> What do you mean in-line python in a template? Do you mean change the skin
> to do the calculation when displaying the data? I'm mostly concerned about
> having erroneous high temps in my historical data.
>
In a WeeWX template (.tmpl file) you will tend to see a lot of literal text
and WeeWX tags. After being processed by the Cheetah templating engine a
file is produced from each template where the literal text remains and the
WeeWX tags are substituted with the applicable statistical data, for
example something like:
The temperature is: $current.outTemp
might result in:
The temperature is: 23.4CEnter code here
You can actually embed python code in-line in the template and Cheetah will
execute the code, so something like (untested):
#import datetime
#if int(datetime.utcfromtimestamp($current.dateTime.raw).strftime('%H')) >16
#set $temp = $current.outTemp
#else
#set $temp = $current.extraTemp1
The temperature is: $temp
would display the string 'The temperature is: ' but display $current.outTemp
from midnight to 5pm and $current.extraTemp1 from 5pm to midnight.
In-line code uses most of the python vocabulary but things like indenting
are not required, each line starts with a # and 'variables' start with a $.
Its handy for fine tuning what is displayed in the report. No reason you
couldn't touch the database but I would say it is almost always easier to
do that elsewhere.
If you have a hard and fast requirement to create a composite field in your
database then in-line template code is not the way to go. If you are
getting to the stage where you need to modify the core WeeWX code then
maybe you should consider writing a custom service to do what you want. The
beauty of a custom service is that it survives across upgrades, the
downside is its a bit more work but in your case I would expect it could
easily be done in 15-20 lines of code. Or of course you live with having to
patch the core code after an upgrade.
Gary
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.