Liz - I dont think any offense was meant, what you posted works and quick
simple fixes are often fine. When you start having to cut n paste identical
or similar code into multiple places (for different templates or records)
then software geeks start getting stressed !
anyway..mine if not yet complete or perfect, but is working fine, I am
posting here for some feedback from Tom? please
My skin.conf contains :
[IndexColors]
# My attempt at extension for colorising indexes
# TODO Dont understand what units these are in or how used
# Colors can be yellow #00ff00 rgb(255,0,255), Also optionally in ""
[[heatindex]]
obs_type = heatindex
maxvalues = 80, 90, 105, 131, 999
colors = "", "#ffff00", "#ffbf00", "#ff8000", "#ff0000"
text1 = "", Caution, Extreme Caution, Danger, Extreme Danger
[[humidex]]
obs_type = humidex
maxvalues = 20, 30, 40, 45, 999
colors = "", green, yellow, orange, red
text1 = "", "Little to no discomfort", Some discomfort, Great
discomfort avoid exertion, Dangerous heat stroke quite possible
[[wbgtTemp]]
obs_type = wbgtTemp
maxvalues = 78, 82, 85, 88, 90, 999
colors = white, green, yellow, red, black, unknown
text1 = "","","","","",""
[[uv]]
maxvalues = 2, 5, 7, 10, 999
colors = white, green, yellow, red, black, unknown
text1 = green, yellow, orange, red, purple
text2 = No protection required You can safely stay outside,
Protection required When spending long periods in the sun, Protection
essential Slip slop slap and wrap, Seek shade between 11am and 4pm Slip
slop slap and wrap Re-apply sunscreen regularly,Reschedule outdoor
activities for early morning/evening Shade essential between 11am and 4pm
Re-apply sunscreen regularly
My index.html.tmpl snippet is :
<tr>
<td class="stats_label">Humidity Index</td>
<td class="stats_data">$current.humidex <b
style="$decorator_color('humidex', $current.humidex.raw)"
title="$decorator_text('humidex',
$current.humidex.raw)">   </b></td>
</tr>
<tr>
<td class="stats_label">WBGT</td>
<td class="stats_data">$current.wbgtTemp <b
style="$decorator_color('wbgtTemp', $current.wbgtTemp.raw)"
title="$decorator_text('wbgtTemp',
$current.wbgtTemp.raw)">   </b></td>
</tr>
My searchlist extension is attached
This currently just places a coloured box (by printing a few blank spaces)
after the values in the web page. It also allows a mouse-over popup text
using an html title.
The $decorator_color can be easily placed inside the <td> element to colour
the whole box, but that then means you have to fiddle with text colours
also and didnt look great.
It would be easy to extend this to reference a url or other html magic or
even script. I am thinking I would make an <img> field call up a small
coloured flag image when needed.
*Tom* :
any feedback appreciated
In particular I am not quite sure how different units would operate here ie
metric/imperial. What will my extension get passed ? the units defined in
StdConvert/target_unit = xxxxx. how do I know what ive been passed so I can
do the correct metric-imperial conversions.
A quick hint or point at a similar use in another bit of code should suffice
Thanks
Neil
--
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.
from weewx.cheetahgenerator import SearchList
import weeutil.weeutil
class MyDecorator(SearchList):
"""My search list extension"""
def __init__(self, generator):
SearchList.__init__(self, generator)
self.table_dict = generator.skin_dict['IndexColors']
def decoratorColorStub(self, type, value):
table_options = weeutil.weeutil.accumulateLeaves(self.table_dict[type])
table = zip(table_options['maxvalues'], table_options['colors'])
value = self.lookup(value, table)
if value == "" :
htmlLine = ""
else :
htmlLine ="background-color:%s" % value
return htmlLine
def decoratorTextStub(self, type, value):
table_options = weeutil.weeutil.accumulateLeaves(self.table_dict[type])
table = zip(table_options['maxvalues'], table_options['text1'])
htmlLine = self.lookup(value, table)
return htmlLine
def get_extension_list(self, timespan, db_lookup):
print "get_extension_list"
# Now create a small dictionary with keys 'UV_color' and 'UV_text':
search_list_extension = {'decorator_color' : self.decoratorColorStub,
'decorator_text' : self.decoratorTextStub}
# Finally, return our extension as a list:
return [search_list_extension]
def lookup(self, value, table):
# print table
if value is not None:
for c in table:
if (value <= int(c[0])):
retval = c[1]
break
else:
retval = "#error2" # WHITE TODO decide what we return here ?
return retval