Skip to content

Commit

Permalink
Support for solar radiation sensors. Based on patch submitted by lule…
Browse files Browse the repository at this point in the history
…k2007.
  • Loading branch information
jpuigsegur committed Aug 26, 2012
1 parent 8f5d1a1 commit c87cf2a
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 17 deletions.
5 changes: 4 additions & 1 deletion database/db-firebird-0.9.sql
Expand Up @@ -38,7 +38,10 @@ CREATE TABLE METEO
RAIN Numeric(4,1),
RAIN_RATE Numeric(4,1),
PRESSURE Numeric(5,1),
UV_INDEX Smallint,
-- Uncomment to record UV Index
-- UV_INDEX Smallint,
-- Uncomment to record Solar Radiation sensor
-- SOLAR_RAD Numeric(5,1)
-- Uncomment to record additional TEMP/HUM sensors
-- TEMP2 Numeric(3,1),
-- HUM2 Numeric(3,1),
Expand Down
5 changes: 4 additions & 1 deletion database/db-mysql-0.9.sql
Expand Up @@ -37,7 +37,10 @@ CREATE TABLE METEO
RAIN Numeric(4,1),
RAIN_RATE Numeric(4,1),
PRESSURE Numeric(5,1),
UV_INDEX Smallint,
-- Uncomment to record UV Index
-- UV_INDEX Smallint,
-- Uncomment to record Solar Radiation sensor
-- SOLAR_RAD Numeric(5,1)
-- Uncomment to record additional TEMP/HUM sensors
-- TEMP2 Numeric(3,1),
-- HUM2 Numeric(3,1),
Expand Down
2 changes: 1 addition & 1 deletion wfcommon/storage/base.py
Expand Up @@ -31,7 +31,7 @@ class DatabaseStorage(object):

mandatory_storage_fields = ['TEMP', 'HUM', 'DEW_POINT', 'WIND', 'WIND_DIR', 'WIND_GUST',
'WIND_GUST_DIR', 'RAIN', 'RAIN_RATE', 'PRESSURE']
optional_storage_fields = ['UV_INDEX', 'TEMPINT', 'HUMINT', 'TEMP2', 'HUM2',
optional_storage_fields = ['UV_INDEX', 'SOLAR_RAD', 'TEMPINT', 'HUMINT', 'TEMP2', 'HUM2',
'TEMP3', 'HUM3', 'TEMP4', 'HUM4', 'TEMP5', 'HUM5',
'TEMP6', 'HUM6', 'TEMP7', 'HUM7', 'TEMP8', 'HUM8',
'TEMP9', 'HUM9']
Expand Down
14 changes: 13 additions & 1 deletion wflogger/collector/aggregator.py
Expand Up @@ -76,6 +76,8 @@ def _new_period(self):
self._pressure = []
## UV
self._uv_index = None
## Solar Rad
self._solar_rad = []
## Log
self._timestamp_last = None
self.logger.info ('New period')
Expand Down Expand Up @@ -110,6 +112,10 @@ def _report_uv(self, uv_index):
if self._uv_index == None or self._uv_index < uv_index:
self._uv_index = uv_index

def _report_solar_rad(self, solar_rad):
self._solar_rad.append(solar_rad)


def get_data(self):
data = {
'temp': None,
Expand All @@ -122,7 +128,8 @@ def get_data(self):
'rain': None,
'rain_rate': None,
'uv_index' : None,
'dew_point' : None
'dew_point' : None,
'solar_rad' : None
}

for sensor in xrange(MAX_TH_SENSORS):
Expand Down Expand Up @@ -185,6 +192,11 @@ def get_data(self):
if self._uv_index != None:
data['uv_index'] = int(self._uv_index)

## Solar rad
if len(self._solar_rad) > 0:
solar_rad = round(sum(self._solar_rad)/len(self._solar_rad), 1)
data['solar_rad'] = solar_rad

data['localtime'] = self._timestamp_last

self.logger.debug('data = %s', data)
Expand Down
3 changes: 3 additions & 0 deletions wflogger/collector/base.py
Expand Up @@ -68,6 +68,9 @@ def send_event(self, event, context={}):
self._hum_last = event.value
elif event._type == 'uv':
self._report_uv(event.value)
elif event._type == 'rad':
self._report_solar_rad(event.value)


def _get_mean_temp(self, current_temp, context): # Last 12 hours mean temp

Expand Down
4 changes: 3 additions & 1 deletion wflogger/collector/xmlfile.py
Expand Up @@ -87,10 +87,12 @@ def _report_humidity(self, humidity, sensor):

element(hum_elt, 'humidity').text = str(humidity)


def _report_uv(self, uv_index):
return

def _report_solar_rad(self, solar_rad):
return

def flush(self, context={}):

time_elt = element(self.doc, 'time')
Expand Down
8 changes: 6 additions & 2 deletions wfrender/config/default/chart_accumulator.yaml
Expand Up @@ -122,6 +122,10 @@ source: !accumulator
rain:
rate: !max { index: rain_rate }
fall: !sum { index: rain }
uv:
index: !max { index: uv_index }
## Uncomment to display UV Index (modify also charts.yaml)
#uv:
# index: !max { index: uv_index }
## Uncomment to display Solar radiation (modify also charts.yaml)
#solar_rad:
# max: !max { index: solar_rad }

20 changes: 14 additions & 6 deletions wfrender/config/default/charts.yaml
Expand Up @@ -252,12 +252,20 @@ renderer: !multi
rain.rate: {}
labels: rain.lbl
ymargin: [ 0, 10 ]
uv: !chart
interpolate: $interpolate
series:
uv.index: {}
labels: uv.lbl
ymargin: [ 0, 1 ]
## Uncomment to display UV Index (modify also chart_accumulator.yaml)
#uv: !chart
# interpolate: $interpolate
# series:
# uv.index: {}
# labels: uv.lbl
# ymargin: [ 0, 1 ]
## Uncomment to display Solar radiation (modify also chart_accumulator.yaml)
#solar_rad: !chart
# interpolate: $interpolate
# series:
# solar_rad.max: {}
# labels: solar_rad.lbl
# ymargin: [ 0, 1 ]
wind: !chart
interpolate: $interpolate
series:
Expand Down
8 changes: 6 additions & 2 deletions wfrender/config/default/table_accumulator.yaml
Expand Up @@ -113,6 +113,10 @@ source: !accumulator
rain:
rate: !max { index: rain_rate }
fall: !sum { index: rain }
uv:
index: !max { index: uv_index }
## Uncomment to display UV Index (modify also charts.yaml)
#uv:
# index: !max { index: uv_index }
## Uncomment to display Solar radiation (modify also charts.yaml)
#solar_rad:
# max: !max { index: solar_rad }

20 changes: 18 additions & 2 deletions wfrender/templates/default/main.html
Expand Up @@ -581,6 +581,12 @@
<div><img src="$chart.uv"/></div>
</div>
#end if
#if $chart.has_key("solar_rad")
<div class="bordered cell graph">
<div class="leftCell">Solar radiation</div><br/>
<div><img src="$chart.solar_rad"/></div>
</div>
#end if
</div>
</div>
<div class="bordered cell graph" style="clear: both; display: none;" id="details">
Expand Down Expand Up @@ -646,10 +652,17 @@
#if $value.has_key("hum9_max")
${" Humidity 9 %"}#slurp
#end if
${" Pressure %s Rain %s Wind %s UV " % (
${" Pressure %s Rain %s Wind %s" % (
$unitstr('press',$units.press).rstrip(),
$unitstr('rain',$units.rain).rstrip(),
$unitstr('wind',$units.wind).rstrip() ) }
$unitstr('wind',$units.wind).rstrip() ) }#slurp
#if $value.has_key("uv_index")
${" UV%"}#slurp
#end if
#if $value.has_key("solar_rad_max")
${" Solar W/m2"}#slurp
#end if

${" " * len($indexes[0])}#slurp
#if $value.has_key("tempint_max")
${" max min avg"}#slurp
Expand Down Expand Up @@ -819,6 +832,9 @@
#if $value.has_key("uv_index")
${"%5d" % $value.uv_index if $value.uv_index != None else " -"}#slurp
#end if
#if $value.has_key("solar_rad_max")
${"%7d" % $value.solar_rad_max if $value.solar_rad_max != None else " -"}#slurp
#end if

#end if
#end for
Expand Down

0 comments on commit c87cf2a

Please sign in to comment.