how to define new optional formatting tag (like ordinal_compass for windDir)?

58 views
Skip to first unread message

Graham Eddy

unread,
Nov 2, 2020, 4:12:33 AM11/2/20
to weewx...@googlegroups.com
there is an existing optional formatting tag ‘ordinal_compass’ for data_type ‘windDir’
eg. where $current.windDir.raw = 45, $current.windDir.ordinal_compass = “NE"

i would like to create a new optional formatting tag ‘category’ for new xtype ‘aqi_pm2_51’ (air quality index derived PM2.5)
e.g. where $current.aqi_pm2_51.raw = 75, $current.aqi_pm2_51.category = “Moderate”

how do i create the new optional formatting tag?
so far all i have found is to extend weewx.units.ValueHelper - i guess a function called “catgeory” would be picked up to do the formatting. but this would require changing rather than extending weewx codebase.
have i missed something obvious?

Tom Keffer

unread,
Nov 2, 2020, 7:14:58 AM11/2/20
to weewx-user
I can't think of any elegant way to do it, but an inelegant way is to monkey patch ValueHelper.

import weewx.units

def category(vh):
  if vh.raw is None:
    result = "N/A"
  elif vh.raw < 50:
    result = "good"
  elif vh.raw < 100:
    result = "moderate"
  else:
    result = "bad"
  return result

weewx.units.ValueHelper.category = category

The ValueHelper class has been pretty stable for a long time, so you're unlikely to break things in an upgrade. But, there's no guarantees!

-tk

--
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/487EFABB-872F-449C-A685-8BB5FD83EF98%40gmail.com.

Graham Eddy

unread,
Nov 3, 2020, 7:49:31 AM11/3/20
to weewx...@googlegroups.com
thanks (i think).
if i use this - and i have yet to come up with a feasible alternative - i think i’ll bury it under a pile of leaves at the bottom of the file...

Tom Keffer

unread,
Nov 3, 2020, 8:09:07 AM11/3/20
to weewx-user
That's wise. :-)

The alternative is a search list extension, dedicated to producing the proper string. Its use would look like

<p>The air quality is $aq_category($current.aqi_pm2_51.raw)</p>

That's not so bad.

-tk

Reply all
Reply to author
Forward
0 new messages