[weewx-user] how to define new optional formatting tag (like ordinal_compass for windDir)?

2020-11-02 Thread Graham Eddy
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?

-- 
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+unsubscr...@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.


Re: [weewx-user] how to define new optional formatting tag (like ordinal_compass for windDir)?

2020-11-02 Thread Tom Keffer
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

On Mon, Nov 2, 2020 at 1:12 AM Graham Eddy  wrote:

> 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?
>
> --
> 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+unsubscr...@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
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/CAPq0zEA-biYRcrTk__y2-Avam%2BcW9U0-z0iDjxc%2BdW%3DH-dkq1g%40mail.gmail.com.


Re: [weewx-user] how to define new optional formatting tag (like ordinal_compass for windDir)?

2020-11-03 Thread Graham Eddy
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...

> On 2 Nov 2020, at 11:14 pm, Tom Keffer  wrote:
> 
> 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
> 
> On Mon, Nov 2, 2020 at 1:12 AM Graham Eddy  > wrote:
> 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?
> 
> -- 
> 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+unsubscr...@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
>  
> .
> 
> -- 
> 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+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/weewx-user/CAPq0zEA-biYRcrTk__y2-Avam%2BcW9U0-z0iDjxc%2BdW%3DH-dkq1g%40mail.gmail.com
>  
> .

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/B6BE9719-0EC9-4DF2-A68A-A34A272CF1DA%40gmail.com.


Re: [weewx-user] how to define new optional formatting tag (like ordinal_compass for windDir)?

2020-11-03 Thread Tom Keffer
That's wise. :-)

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

The air quality is $aq_category($current.aqi_pm2_51.raw)


That's not so bad.

-tk

On Tue, Nov 3, 2020 at 4:49 AM Graham Eddy  wrote:

> 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...
>
> On 2 Nov 2020, at 11:14 pm, Tom Keffer  wrote:
>
> 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
>
> On Mon, Nov 2, 2020 at 1:12 AM Graham Eddy  wrote:
>
>> 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?
>>
>> --
>> 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+unsubscr...@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
>> .
>>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-user/CAPq0zEA-biYRcrTk__y2-Avam%2BcW9U0-z0iDjxc%2BdW%3DH-dkq1g%40mail.gmail.com
> 
> .
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-user/B6BE9719-0EC9-4DF2-A68A-A34A272CF1DA%40gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/CAPq0zEB6ZVNDCi52gSehYfEn%2BwLv5vw%3DSK%2BMEe_FbRrecW0Paw%40mail.gmail.com.