From c87cf2a0767689a344cea702cc9c67f9229f17f9 Mon Sep 17 00:00:00 2001 From: Jordi Puigsegur Date: Sun, 26 Aug 2012 16:43:05 +0000 Subject: [PATCH] Support for solar radiation sensors. Based on patch submitted by lulek2007. --- database/db-firebird-0.9.sql | 5 ++++- database/db-mysql-0.9.sql | 5 ++++- wfcommon/storage/base.py | 2 +- wflogger/collector/aggregator.py | 14 ++++++++++++- wflogger/collector/base.py | 3 +++ wflogger/collector/xmlfile.py | 4 +++- .../config/default/chart_accumulator.yaml | 8 ++++++-- wfrender/config/default/charts.yaml | 20 +++++++++++++------ .../config/default/table_accumulator.yaml | 8 ++++++-- wfrender/templates/default/main.html | 20 +++++++++++++++++-- 10 files changed, 72 insertions(+), 17 deletions(-) diff --git a/database/db-firebird-0.9.sql b/database/db-firebird-0.9.sql index 94c51a2..44aab07 100644 --- a/database/db-firebird-0.9.sql +++ b/database/db-firebird-0.9.sql @@ -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), diff --git a/database/db-mysql-0.9.sql b/database/db-mysql-0.9.sql index face801..56148a6 100644 --- a/database/db-mysql-0.9.sql +++ b/database/db-mysql-0.9.sql @@ -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), diff --git a/wfcommon/storage/base.py b/wfcommon/storage/base.py index b9079bb..bb24511 100644 --- a/wfcommon/storage/base.py +++ b/wfcommon/storage/base.py @@ -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'] diff --git a/wflogger/collector/aggregator.py b/wflogger/collector/aggregator.py index 0276d86..4ff7bd1 100644 --- a/wflogger/collector/aggregator.py +++ b/wflogger/collector/aggregator.py @@ -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') @@ -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, @@ -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): @@ -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) diff --git a/wflogger/collector/base.py b/wflogger/collector/base.py index e444de8..7ccec18 100644 --- a/wflogger/collector/base.py +++ b/wflogger/collector/base.py @@ -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 diff --git a/wflogger/collector/xmlfile.py b/wflogger/collector/xmlfile.py index 8fc8a9f..94d548f 100644 --- a/wflogger/collector/xmlfile.py +++ b/wflogger/collector/xmlfile.py @@ -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') diff --git a/wfrender/config/default/chart_accumulator.yaml b/wfrender/config/default/chart_accumulator.yaml index a75a9bc..bb76eea 100644 --- a/wfrender/config/default/chart_accumulator.yaml +++ b/wfrender/config/default/chart_accumulator.yaml @@ -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 } diff --git a/wfrender/config/default/charts.yaml b/wfrender/config/default/charts.yaml index 0b95853..2c3d017 100644 --- a/wfrender/config/default/charts.yaml +++ b/wfrender/config/default/charts.yaml @@ -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: diff --git a/wfrender/config/default/table_accumulator.yaml b/wfrender/config/default/table_accumulator.yaml index b318fc5..867d789 100644 --- a/wfrender/config/default/table_accumulator.yaml +++ b/wfrender/config/default/table_accumulator.yaml @@ -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 } diff --git a/wfrender/templates/default/main.html b/wfrender/templates/default/main.html index d60f1b4..1f7e621 100644 --- a/wfrender/templates/default/main.html +++ b/wfrender/templates/default/main.html @@ -581,6 +581,12 @@
#end if + #if $chart.has_key("solar_rad") +
+
Solar radiation

+
+
+ #end if