Exemplo n.º 1
0
def step_impl(context):
    """
    :type context: behave.runner.Context
    """
    config = {'bits':
        {
            '0': {'key': 'winddirection', 'length': '4'},
            '1': {'key': 'windspeed', 'length': '6', 'max': '63', 'min': '0', 'step': '1'},
            '2': {'key': 'windgusts', 'length': '6', 'max': '63', 'min': '0', 'step': '1'},
            '3': {'key': 'windspeedBft', 'length': '4', 'max': '12', 'min': '1', 'step': '1'},
            '4': {'key': 'airpressure', 'length': '8', 'max': '1155', 'min': '900', 'step': '1'},
            '5': {'key': 'temperature', 'length': '10', 'max': '49.9', 'min': '-39.9', 'step': '0.1'},
            '6': {'key': 'feeltemperature', 'length': '10', 'max': '49.9', 'min': '-39.9', 'step': '0.1'},
            '7': {'key': 'humidity', 'length': '7', 'max': '100', 'min': '0', 'step': '1'},
            '8': {'key': 'stationname', 'length': '4'},
            '9': {'key': 'date', 'length': '4'},
            '10': {'key': 'visibility', 'length': '4'},
            '11': {'key': 'precipitation', 'length': '4'},
            '12': {'key': 'groundtemperature', 'length': '4'},
            '13': {'key': 'barometric_trend', 'length': '4'},
            '14': {'key': 'data_from_fallback', 'length': '4'},
            '15': {'key': 'lat', 'length': '4'},
            '16': {'key': 'lon', 'length': '4'},
            '17': {'key': 'DUMMY_BYTE', 'length': '4'},
        },
        'channel': 0,
        'extended-error-mode': False,
        'frequency': 250000,
        'interval': 300,
        'library': 'wiringPi',
        'source': 'buienradar',
        'stations': [6275]
    }
    bp = BuienradarParser(**config)
    context.result = bp.parse(data=context.weather_data_json)
Exemplo n.º 2
0
 def setUp(self):
     file_path = os.path.join(os.getcwd(), 'tests', 'buienradar.json')
     with open(file_path, 'rU', encoding='UTF-8') as f:
         data = f.read()
         config = {
             'stations': [6275, 6203],
             'bits': {
                 '0': {'key': 'wind_direction'},
                 '1': {'key': 'wind_speed'},
                 '2': {'key': 'wind_speed_max'},
                 '3': {'key': 'wind_speed_bft'},
                 '4': {'key': 'air_pressure'},
                 '5': {'key': 'temperature'},
                 '6': {'key': 'apparent_temperature'},
                 '7': {'key': 'humidity'},
                 '8': {'key': 'station_name'},
                 '9': {'key': 'latitude'},
                 '10': {'key': 'longitude'},
                 '11': {'key': 'date'},
                 '12': {'key': 'wind_direction_code'},
                 '13': {'key': 'sight_distance'},
                 '14': {'key': 'rain_mm_per_hour'},
                 '15': {'key': 'temperature_10_cm'},
                 '16': {'key': 'barometric_trend'},
                 '17': {'key': 'data_from_fallback'}
             }
         }
         bp = BuienradarParser(**config)
         self.weather_data = bp.parse(data=data)
Exemplo n.º 3
0
 def setUp(self):
     with open(os.path.join(os.getcwd(), 'tests', 'buienradar.xml'), 'rU') as f:
         data = f.read()
         config = {
             'stations':
                 {0: 6275,
                  1: 6203},
             'bits': {
                 '0': {'key': 'wind_direction'},
                 '1': {'key': 'wind_speed'},
                 '2': {'key': 'wind_speed_max'},
                 '3': {'key': 'wind_speed_bft'},
                 '4': {'key': 'air_pressure'},
                 '5': {'key': 'temperature'},
                 '6': {'key': 'apparent_temperature'},
                 '7': {'key': 'humidity'},
                 '8': {'key': 'station_name'},
                 '9': {'key': 'latitude'},
                 '10': {'key': 'longitude'},
                 '11': {'key': 'date'},
                 '12': {'key': 'wind_direction_code'},
                 '13': {'key': 'sight_distance'},
                 '14': {'key': 'rain'},
                 '15': {'key': 'temperature_10_cm'},
                 '16': {'key': 'barometric_trend'},
                 '17': {'key': 'data_from_fallback'}
             }
         }
         bp = BuienradarParser(**config)
         bp.historic_data = {
             datetime(2015, 5, 14, 13, 50, 00): 1000
         }
         self.weather_data = bp.parse(raw_xml=data, **config)
         print(self.weather_data)
def test_merge_with_fallback():
    """Tests whether the data can be retrieved from another station if the primary is lacking a specific field"""
    weather_data = {
        1: {'luchtdruk': None},
        2: {'luchtdruk': 1001}
    }

    bp = BuienradarParser()
    merged_data = bp.merge(weather_data, [1, 2])
    assert merged_data == {'data_from_fallback': True, 'error': False, 'luchtdruk': 1001}
def test_merge_without_fallback():
    """Tests whether data from the primary station is always used when it is present"""
    weather_data = {
        1: {'luchtdruk': 1000},
        2: {'luchtdruk': 1001}
    }

    bp = BuienradarParser()
    merged_data = bp.merge(weather_data, [1, 2])
    assert merged_data == {'data_from_fallback': False, 'error': False, 'luchtdruk': 1000}
def test_single_station():
    """Tests whether, if no fallback stations are selected, the data from the primary station is returned even if it
       is missing"""
    weather_data = {
        1: {'luchtdruk': None},
        2: {'luchtdruk': 1001}
    }

    bp = BuienradarParser()
    merged_data = bp.merge(weather_data, [1])
    assert merged_data == {'data_from_fallback': False, 'error': False, 'luchtdruk': None}
Exemplo n.º 7
0
def test_merge_with_fallback():
    """Tests whether the data can be retrieved from another station if the primary is lacking a specific field"""
    weather_data = {1: {'luchtdruk': None}, 2: {'luchtdruk': 1001}}

    bp = BuienradarParser()
    merged_data = bp.merge(weather_data, [1, 2],
                           required_fields=[{
                               'key': 'luchtdruk'
                           }])
    assert merged_data == {
        'data_from_fallback': True,
        'error': False,
        'luchtdruk': 1001
    }
Exemplo n.º 8
0
def test_merge_without_fallback():
    """Tests whether data from the primary station is always used when it is present"""
    weather_data = {1: {'luchtdruk': 1000}, 2: {'luchtdruk': 1001}}

    bp = BuienradarParser()
    merged_data = bp.merge(weather_data, [1, 2],
                           required_fields=[{
                               'key': 'luchtdruk'
                           }])
    assert merged_data == {
        'data_from_fallback': False,
        'error': False,
        'luchtdruk': 1000
    }
Exemplo n.º 9
0
def test_single_station():
    """Tests whether, if no fallback stations are selected, the data from the primary station is returned even if it
       is missing"""
    weather_data = {1: {'luchtdruk': None}, 2: {'luchtdruk': 1001}}

    bp = BuienradarParser()
    merged_data = bp.merge(weather_data, [1],
                           required_fields=[{
                               'key': 'luchtdruk'
                           }])
    assert merged_data == {
        'data_from_fallback': False,
        'error': False,
        'luchtdruk': None
    }
Exemplo n.º 10
0
def complete_weather_data():
    file_path = os.path.join(os.getcwd(), 'tests', 'buienradar.json')
    with open(file_path, 'r', encoding='UTF-8') as f:
        data = f.read()
        config = {
            'stations': [6275],
            'bits': [{
                'key': 'winddirection'
            }, {
                'key': 'windspeed'
            }, {
                'key': 'windgusts'
            }, {
                'key': 'windspeedBft'
            }, {
                'key': 'airpressure'
            }, {
                'key': 'temperature'
            }, {
                'key': 'feeltemperature'
            }, {
                'key': 'humidity'
            }, {
                'key': 'stationname'
            }, {
                'key': 'lat'
            }, {
                'key': 'lon'
            }, {
                'key': 'winddirection'
            }, {
                'key': 'visibility'
            }, {
                'key': 'precipitation'
            }, {
                'key': 'groundtemperature'
            }, {
                'key': 'barometric_trend'
            }, {
                'key': 'data_from_fallback'
            }, {
                'key': 'rainFallLastHour'
            }, {
                'key': 'rainFallLast24Hour'
            }]
        }
        bp = BuienradarParser(**config)
        return {'data': bp.parse(data=data), 'config': config}
Exemplo n.º 11
0
def fetch_weather_data(conn, *args, **kwargs):
    data = get_weather_string_with_retries()

    if data:
        bp = BuienradarParser(*args, **kwargs)
        try:
            wd = bp.parse(data)
        except Exception:
            logging.error('Data parsing failed. Cannot send good data. Setting error.')
            wd = DEFAULT_WEATHER_DATA
    else:
        logging.error('Retrieving data failed several times. Setting error.')
        wd = DEFAULT_WEATHER_DATA

    conn.send(wd)
    conn.close()
Exemplo n.º 12
0
def fetch_weather_data(conn, *args, **kwargs):
    data = get_weather_string_with_retries()

    if data:
        bp = BuienradarParser(*args, **kwargs)
        try:
            wd = bp.parse(data)
        except:
            logging.error('Data parsing failed. Cannot send good data. Setting error.')
            wd = DEFAULT_WEATHER_DATA
    else:
        logging.error('Retrieving data failed several times. Setting error.')
        wd = DEFAULT_WEATHER_DATA

    conn.send(wd)
    conn.close()
Exemplo n.º 13
0
def step_impl(context):
    """
    :type context: behave.runner.Context
    """
    config = {'bits':
        {
            '0': {'key': 'wind_direction', 'length': '4'},
            '1': {'key': 'wind_speed', 'length': '6', 'max': '63', 'min': '0', 'step': '1'},
            '2': {'key': 'wind_speed_max', 'length': '6', 'max': '63', 'min': '0', 'step': '1'},
            '3': {'key': 'wind_speed_bft', 'length': '4', 'max': '12', 'min': '1', 'step': '1'},
            '4': {'key': 'air_pressure', 'length': '8', 'max': '1155', 'min': '900', 'step': '1'},
            '5': {'key': 'temperature', 'length': '10', 'max': '49.9', 'min': '-39.9', 'step': '0.1'},
            '6': {'key': 'apparent_temperature', 'length': '10', 'max': '49.9', 'min': '-39.9', 'step': '0.1'},
            '7': {'key': 'humidity', 'length': '7', 'max': '100', 'min': '0', 'step': '1'},
            '8': {'key': 'station_name', 'length': '4'},
            '9': {'key': 'date', 'length': '4'},
            '10': {'key': 'wind_direction_code', 'length': '4'},
            '11': {'key': 'sight_distance', 'length': '4'},
            '12': {'key': 'rain_mm_per_hour', 'length': '4'},
            '13': {'key': 'temperature_10_cm', 'length': '4'},
            '14': {'key': 'barometric_trend', 'length': '4'},
            '15': {'key': 'data_from_fallback', 'length': '4'},
            '16': {'key': 'latitude', 'length': '4'},
            '17': {'key': 'longitude', 'length': '4'},
            '18': {'key': 'DUMMY_BYTE', 'length': '4'},
        },
        'channel': 0,
        'extended-error-mode': False,
        'frequency': 250000,
        'interval': 300,
        'library': 'wiringPi',
        'source': 'buienradar',
        'stations': [6275]
    }
    bp = BuienradarParser(**config)
    context.result = bp.parse(data=context.weather_data_json)
Exemplo n.º 14
0
               'min': '0',
               'step': '1'},
              {'key': 'service_byte', 'length': '5'},
              {'key': 'DUMMY_BYTE', 'length': '4'}],
     'channel': 0,
     'extended-error-mode': False,
     'frequency': 250000,
     'interval': 300,
     'library': 'wiringPi',
     'source': 'buienradar',
     'stations': [6320, 6321, 6310, 6312, 6308, 6311, 6331, 6316]
     }

file_path = os.path.join(os.getcwd(), 'tests', 'buienradar.json')

with open(file_path, 'r', encoding='utf-8') as f:  # rU opens file with line endings from different platforms correctly
    data = f.read()
    bp = BuienradarParser(**a)
    wd = bp.parse(data=data)

bits = a['bits']
fmt = ''
for i, data in enumerate(bits):
    formatting = bits[i]
    s = "hex:{0}, ".format(formatting['length'])
    fmt += s
hexstring = fmt[:-1]

if __name__ == '__main__':
    print(hexstring)
Exemplo n.º 15
0
                    'step': '0.1'},
              '7': {'key': 'humidity',
                    'length': '7',
                    'max': '100',
                    'min': '0',
                    'step': '1'},
              '8': {'key': 'service_byte', 'length': '5'},
              '9': {'key': 'DUMMY_BYTE', 'length': '4'}},
     'channel': 0,
     'extended-error-mode': False,
     'frequency': 250000,
     'interval': 300,
     'library': 'wiringPi',
     'source': 'buienradar',
     'stations': [6320, 6321, 6310, 6312, 6308, 6311, 6331, 6316]
     }

file_path = os.path.join(os.getcwd(), 'tests', 'buienradar.json')

with open(file_path, 'rU', encoding='utf-8') as f:  # rU opens file with line endings from different platforms correctly
    data = f.read()
    bp = BuienradarParser(**a)
    wd = bp.parse(data=data)

bits = a['bits']
fmt = ''
for i, data in enumerate(bits):
    formatting = bits[str(i)]
    s = "hex:{0}, ".format(formatting['length'])
    fmt += s
hexstring = fmt[:-1]