# Path: wfcommon/formula/base.py
# class AverageFormula(object):
#     '''
#     Average.
#     '''
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     sum = 0
#     count = 0
# 
#     def append(self, sample):
#         value = sample[self.index]
#         if value is not None:
#             self.sum = self.sum + value
#             self.count = self.count + 1
# 
#     def value(self):
#         if self.count==0:
#             return None
#         else:
#             return float(self.sum) / float(self.count)
# 
# Path: wfcommon/formula/base.py
# class MinFormula(object):
#     '''
#     Minimum.
#     '''
# 
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     min = sys.maxint
# 
#     def append(self, sample):
#         value = sample[self.index]
#         if value is not None:
#             self.min = min(self.min, value)
# 
#     def value(self):
#         if self.min == sys.maxint:
#             return None
#         else:
#             return self.min
# 
# Path: wfcommon/formula/base.py
# class MaxFormula(object):
#     '''
#     Maximum.
#     '''
# 
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     max = -sys.maxint
# 
#     def append(self, sample):
#         value = sample[self.index]
#         if value is not None:
#             self.max = max(self.max, value)
# 
#     def value(self):
#         if self.max == -sys.maxint:
#             return None
#         else:
#             return self.max
# 
# Path: wfcommon/formula/base.py
# class SumFormula(object):
#     '''
#     Sum.
#     '''
# 
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     sum = 0
#     empty = True
# 
#     def append(self, sample):
#         value = sample[self.index]
#         if value is not None:
#             self.empty = False
#             self.sum = self.sum + value
# 
#     def value(self):
#         if self.empty:
#             return None
#         else:
#             return self.sum
# 
# Path: wfcommon/formula/temp.py
# class WindChillMinFormula(object):
#     '''
#     Minimum WindChill temperature. Requires temperature and wind speed in Km/h.
#     '''
# 
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     min_windchill = None
# 
#     def append(self, sample):
#         value_temp = sample[self.index[0]]
#         value_wind = sample[self.index[1]]
# 
#         if value_temp is not None and value_wind is not None :
#             sample_windchill = meteo.WindChill(value_temp, meteo.msToKmh(value_wind))
#             if sample_windchill is not None:
#                 if self.min_windchill is None or self.min_windchill > sample_windchill:
#                     self.min_windchill = sample_windchill
# 
#     def value(self):
#         return self.min_windchill
# 
# Path: wfcommon/formula/temp.py
# class HeatIndexMaxFormula(object):
#     '''
#     Maximum Heat Index temperature. Requires temperature and humidity.
#     '''
# 
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     max_heatindex = None
# 
#     def append(self, sample):
#         value_temp = sample[self.index[0]]
#         value_hum = sample[self.index[1]]
# 
#         if value_temp is not None and value_hum is not None :
#             sample_heatindex = meteo.HeatIndex(value_temp, value_hum)
#             if sample_heatindex is not None:
#                 if self.max_heatindex is None or self.max_heatindex < sample_heatindex:
#                     self.max_heatindex = sample_heatindex
# 
#     def value(self):
#         return self.max_heatindex


import logging
import copy
import datetime
import threading
from wfcommon.formula.base import AverageFormula
from wfcommon.formula.base import MinFormula
from wfcommon.formula.base import MaxFormula
from wfcommon.formula.base import SumFormula
from wfcommon.formula.wind import PredominantWindFormula
from wfcommon.formula.wind import WindSectorAverageFormula
from wfcommon.formula.wind import WindSectorMaxFormula
from wfcommon.formula.wind import WindSectorFrequencyFormula
from wfcommon.formula.temp import WindChillMinFormula
from wfcommon.formula.temp import HeatIndexMaxFormula
    span = 23

    format = None

    formats = { 'year': ['%y', '%Y'],
                'month': ['%m', '%Y/%m'],
                'week': ['%d/%m', '%Y/%m/%d'], 
                'day': ['%d/%m', '%Y/%m/%d'],
                'hour': ['%H', '%Y/%m/%d %H'],
                'minute': ['%H:%M', '%Y/%m/%d %H:%M'] }

    period = 120

    default_formulas = {
        'temp': { 'avg' : AverageFormula('temp'),
                   'min' : MinFormula('temp'),
                   'max' : MaxFormula('temp') },
        'dew' : { 'avg': AverageFormula('dew_point') },
        'hum' : { 'avg' : AverageFormula('hum'),
                   'min' : MinFormula('hum'),
                   'max' : MaxFormula('hum') },
        'press' : { 'avg' : AverageFormula('pressure'),
                   'min' : MinFormula('pressure'),
                   'max' : MaxFormula('pressure') },
        'wind' : { 'avg' : AverageFormula('wind'),
                   'max' : MaxFormula('wind_gust'),
                   'deg,dir' : PredominantWindFormula('wind')  },
        'sectors' : { 'avg' : WindSectorAverageFormula('wind'),
                      'max' : WindSectorMaxFormula('wind_gust'),
                      'freq' : WindSectorFrequencyFormula('wind') },

# Path: wfcommon/formula/base.py
# class AverageFormula(object):
#     '''
#     Average.
#     '''
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     sum = 0
#     count = 0
# 
#     def append(self, sample):
#         value = sample[self.index]
#         if value is not None:
#             self.sum = self.sum + value
#             self.count = self.count + 1
# 
#     def value(self):
#         if self.count==0:
#             return None
#         else:
#             return float(self.sum) / float(self.count)
# 
# Path: wfcommon/formula/base.py
# class MinFormula(object):
#     '''
#     Minimum.
#     '''
# 
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     min = sys.maxint
# 
#     def append(self, sample):
#         value = sample[self.index]
#         if value is not None:
#             self.min = min(self.min, value)
# 
#     def value(self):
#         if self.min == sys.maxint:
#             return None
#         else:
#             return self.min
# 
# Path: wfcommon/formula/base.py
# class MaxFormula(object):
#     '''
#     Maximum.
#     '''
# 
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     max = -sys.maxint
# 
#     def append(self, sample):
#         value = sample[self.index]
#         if value is not None:
#             self.max = max(self.max, value)
# 
#     def value(self):
#         if self.max == -sys.maxint:
#             return None
#         else:
#             return self.max
# 
# Path: wfcommon/formula/base.py
# class SumFormula(object):
#     '''
#     Sum.
#     '''
# 
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     sum = 0
#     empty = True
# 
#     def append(self, sample):
#         value = sample[self.index]
#         if value is not None:
#             self.empty = False
#             self.sum = self.sum + value
# 
#     def value(self):
#         if self.empty:
#             return None
#         else:
#             return self.sum
# 
# Path: wfcommon/formula/temp.py
# class WindChillMinFormula(object):
#     '''
#     Minimum WindChill temperature. Requires temperature and wind speed in Km/h.
#     '''
# 
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     min_windchill = None
# 
#     def append(self, sample):
#         value_temp = sample[self.index[0]]
#         value_wind = sample[self.index[1]]
# 
#         if value_temp is not None and value_wind is not None :
#             sample_windchill = meteo.WindChill(value_temp, meteo.msToKmh(value_wind))
#             if sample_windchill is not None:
#                 if self.min_windchill is None or self.min_windchill > sample_windchill:
#                     self.min_windchill = sample_windchill
# 
#     def value(self):
#         return self.min_windchill
# 
# Path: wfcommon/formula/temp.py
# class HeatIndexMaxFormula(object):
#     '''
#     Maximum Heat Index temperature. Requires temperature and humidity.
#     '''
# 
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     max_heatindex = None
# 
#     def append(self, sample):
#         value_temp = sample[self.index[0]]
#         value_hum = sample[self.index[1]]
# 
#         if value_temp is not None and value_hum is not None :
#             sample_heatindex = meteo.HeatIndex(value_temp, value_hum)
#             if sample_heatindex is not None:
#                 if self.max_heatindex is None or self.max_heatindex < sample_heatindex:
#                     self.max_heatindex = sample_heatindex
# 
#     def value(self):
#         return self.max_heatindex


# Path: wfrender/datasource/accumulator.py
import logging
import copy
import datetime
import threading
from wfcommon.formula.base import AverageFormula
from wfcommon.formula.base import MinFormula
from wfcommon.formula.base import MaxFormula
from wfcommon.formula.base import SumFormula
from wfcommon.formula.wind import PredominantWindFormula
from wfcommon.formula.wind import WindSectorAverageFormula
from wfcommon.formula.wind import WindSectorMaxFormula
from wfcommon.formula.wind import WindSectorFrequencyFormula
from wfcommon.formula.temp import WindChillMinFormula
from wfcommon.formula.temp import HeatIndexMaxFormula

    span = 23

    format = None

    formats = { 'year': ['%y', '%Y'],
                'month': ['%m', '%Y/%m'],
                'week': ['%d/%m', '%Y/%m/%d'], 
                'day': ['%d/%m', '%Y/%m/%d'],
                'hour': ['%H', '%Y/%m/%d %H'],
                'minute': ['%H:%M', '%Y/%m/%d %H:%M'] }

    period = 120

    default_formulas = {
        'temp': { 'avg' : AverageFormula('temp'),
                   'min' : MinFormula('temp'),
                   'max' : MaxFormula('temp') },
        'dew' : { 'avg': AverageFormula('dew_point') },
        'hum' : { 'avg' : AverageFormula('hum'),
                   'min' : MinFormula('hum'),
                   'max' : MaxFormula('hum') },
        'press' : { 'avg' : AverageFormula('pressure'),
                   'min' : MinFormula('pressure'),
                   'max' : MaxFormula('pressure') },
        'wind' : { 'avg' : AverageFormula('wind'),
                   'max' : MaxFormula('wind_gust'),
                   'deg,dir' : PredominantWindFormula('wind')  },
        'sectors' : { 'avg' : WindSectorAverageFormula('wind'),
                      'max' : WindSectorMaxFormula('wind_gust'),
                      'freq' : WindSectorFrequencyFormula('wind') },

        'rain' : { 'rate' : MaxFormula('rain_rate'),