# Path: wfcommon/formula/base.py
# class LastFormula(object):
#     '''
#     Keeps last sample value.
#     '''
# 
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     last = None
# 
#     def append(self, sample):
#         value = sample[self.index]
#         if value is not None:
#             self.last = value
# 
#     def value(self):
#         return self.last
# 
# 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/units.py
# def HPaToInHg(value):
#     return value * 0.02953 if value != None else None
# 
# Path: wfcommon/units.py
# def CToF(value): 
#     return  ((value * 9.0) / 5.0) + 32.0 if value != None else None
# 
# Path: wfcommon/units.py
# def MmToIn(value): 
#     return value / 25.4 if value != None else None
# 
# Path: wfcommon/units.py
# def MpsToMph(value): 
#     return value * 2.2445 if value != None else None


import math
import logging
import sys
import time
import wfcommon.database
            import weather.services
from wfcommon.formula.base import LastFormula
from wfcommon.formula.base import SumFormula
    from wfrender.datasource.accumulator import AccumulatorDatasource
    from datasource.accumulator import AccumulatorDatasource
from wfcommon.units import HPaToInHg
from wfcommon.units import CToF
from wfcommon.units import MmToIn
from wfcommon.units import MpsToMph
                accu = AccumulatorDatasource()
                accu.slice = 'day'
                accu.span = 1
                accu.storage = self.storage
                accu.formulas = {'current': {
                     'temp' : LastFormula('temp'),
                     'dew_point': LastFormula('dew_point'),
                     'hum' : LastFormula('hum'),
                     'pressure' : LastFormula('pressure'),
                     'wind' : LastFormula('wind'),
                     'wind_deg' : LastFormula('wind_dir'),
                     'gust' : LastFormula('wind_gust'),
                     'gust_deg' : LastFormula('wind_gust_dir'),
                     'rain_rate' : LastFormula('rain_rate'),
                     'rain_fall' : SumFormula('rain'), 
                     'utctime' : LastFormula('utctime') } }

                while self.alive:
                    try:
                        data = accu.execute()['current']['series']
                        index = len(data['lbl'])-1

                        params = {
                            # <float> pressure: in inches of Hg
                            'pressure' : HPaToInHg(data['pressure'][index]),
                            # <float> dewpoint: in Fahrenheit
                            'dewpoint' : CToF(data['dew_point'][index]),
                            # <float> humidity: between 0.0 and 100.0 inclusive
                            'humidity' : data['hum'][index],
                            # <float> tempf: in Fahrenheit

# Path: wfcommon/formula/base.py
# class LastFormula(object):
#     '''
#     Keeps last sample value.
#     '''
# 
#     def __init__(self, index):
#         self.index = index
# 
#     index = None
#     last = None
# 
#     def append(self, sample):
#         value = sample[self.index]
#         if value is not None:
#             self.last = value
# 
#     def value(self):
#         return self.last
# 
# 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/units.py
# def HPaToInHg(value):
#     return value * 0.02953 if value != None else None
# 
# Path: wfcommon/units.py
# def CToF(value): 
#     return  ((value * 9.0) / 5.0) + 32.0 if value != None else None
# 
# Path: wfcommon/units.py
# def MmToIn(value): 
#     return value / 25.4 if value != None else None
# 
# Path: wfcommon/units.py
# def MpsToMph(value): 
#     return value * 2.2445 if value != None else None


# Path: wfrender/renderer/wunderground.py
import math
import logging
import sys
import time
import wfcommon.database
            import weather.services
from wfcommon.formula.base import LastFormula
from wfcommon.formula.base import SumFormula
    from wfrender.datasource.accumulator import AccumulatorDatasource
    from datasource.accumulator import AccumulatorDatasource
from wfcommon.units import HPaToInHg
from wfcommon.units import CToF
from wfcommon.units import MmToIn
from wfcommon.units import MpsToMph

                accu = AccumulatorDatasource()
                accu.slice = 'day'
                accu.span = 1
                accu.storage = self.storage
                accu.formulas = {'current': {
                     'temp' : LastFormula('temp'),
                     'dew_point': LastFormula('dew_point'),
                     'hum' : LastFormula('hum'),
                     'pressure' : LastFormula('pressure'),
                     'wind' : LastFormula('wind'),
                     'wind_deg' : LastFormula('wind_dir'),
                     'gust' : LastFormula('wind_gust'),
                     'gust_deg' : LastFormula('wind_gust_dir'),
                     'rain_rate' : LastFormula('rain_rate'),
                     'rain_fall' : SumFormula('rain'), 
                     'utctime' : LastFormula('utctime') } }

                while self.alive:
                    try:
                        data = accu.execute()['current']['series']
                        index = len(data['lbl'])-1

                        params = {
                            # <float> pressure: in inches of Hg
                            'pressure' : HPaToInHg(data['pressure'][index]),
                            # <float> dewpoint: in Fahrenheit
                            'dewpoint' : CToF(data['dew_point'][index]),
                            # <float> humidity: between 0.0 and 100.0 inclusive
                            'humidity' : data['hum'][index],
                            # <float> tempf: in Fahrenheit

                            'tempf' : CToF(data['temp'][index]),