Cheetah Rounding Values

65 views
Skip to first unread message

rich T

unread,
Apr 25, 2020, 12:28:17 AM4/25/20
to weewx-user
Is there a way cheetah can round a value to 1 decimal point or does the rounding need to be performed in an SQL statement first?

Andrew Milner

unread,
Apr 25, 2020, 1:10:23 AM4/25/20
to weewx-user
See customisation guide

Tom Keffer

unread,
Apr 25, 2020, 7:53:56 AM4/25/20
to weewx-user
See the section Formatting options in the Customizing Guide. There are also some examples in the next section.

On Fri, Apr 24, 2020 at 9:28 PM rich T <storm...@gmail.com> wrote:
Is there a way cheetah can round a value to 1 decimal point or does the rounding need to be performed in an SQL statement first?

--
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 weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/afbbb748-1673-4e1f-b651-38bdfdd1fceb%40googlegroups.com.

rich T

unread,
Apr 26, 2020, 12:29:11 AM4/26/20
to weewx-user
Thanks I tried your suggestions, but still does not round to the decimal point. I did create a new tag. Do I need to create a new search list extension to allow formatting?

Thanks 
Rich


Departure Climate Report.png

gjr80

unread,
Apr 26, 2020, 12:54:54 AM4/26/20
to weewx-user
Rich,

How you format data in a Cheetah generated report really depends on the source of the data. If you are using a WeeWX generated tag, eg $current.outTemp, then you have all the formatting and unit conversion options of a WeeWX tag available to you (as linked by Tom). If the data comes from some inline python in your Cheetah template then you are responsible for formatting the data, for example, if your template had the following:

#set $pie_temperature = 22/7

and you wanted to use $pie_temperature in your template then you would be responsible for formatting the output, you might do something like:

#set $pie_temperature_2d = round($pie_temperature, 2)

and then use $pie_temperature_2d to display $pie_temperature to two decimal places (or you might just have used #set $pie_temperature = round(22/7, 2) up front). Bottom line is, formatting/unit conversion etc is your problem, not WeeWX'

If your data comes from a Search List Extension (SLE) then it depends on what the SLE provides. Let's say the SLE provides a tag $pie_temp that is a temperature. If $pie_temp is just a number then just like $pie_temperature you need to format it yourself. However, is the SLE is a little more sophisticated and provides $pie_temp as a special WeeWX object known as a ValueHelper, then $pie_temp has all of the formatting and unit conversion abilities of a WeeWX tag such as $current.outTemp. Generally speaking it is quite easy to have a SLE return a ValueHelper(), whilst it does make the SLE code a little more complex it provides for a much more flexible output.

At the end of the day a SLE does not allow formatting per se, rather it is the type of output from a SLE that determines what formatting/unit conversion is available. Have a read of the section Defining new tags in the Customization Guide, it covers ValueHelpers and SLEs with examples.

Gary

Andrew Milner

unread,
Apr 26, 2020, 2:27:10 AM4/26/20
to weewx-user
If you are using weewx tags it would be something like
$current.outTemp.format("%.1f") for one decimal place

rich T

unread,
Apr 26, 2020, 11:35:41 AM4/26/20
to weewx-user
Thanks everyone who provided suggestions. Using Gary's suggestion and it finally works.

#set Daily_Max = $day.outTemp.max
#set Departure_Temp_Max = $Daily_Max.raw - $day.outTemp.historical_max_avg.raw
#set Departure_Temp_Max = round($Departure_Temp_Max, 1)
Climate Report.png
Reply all
Reply to author
Forward
0 new messages