def run_sensordata(reader): measure = next(reader.read_entries(skip=0)) sensor, stream_code = sensor_and_streamcode_for_data(measure) if sensor is None or stream_code is None: print_red( "Unable to get sensor id and streamCode, they are not provided by " "document or filename and they cannot be created by 'Name' field.") return sensor_data = { 'location': { 'positions': [{ 'lat': float(measure['Location'][0]), 'lon': float(measure['Location'][1]), 'ele': float(measure['Location'][2]) }], 'exposure': 'outdoor', 'disposition': 'fixed' if measure['Type'].lower() == 'sensor' else 'mobile', }, 'id': sensor, 'name': measure['Name'], 'model': measure['Model'], 'description': measure['Description'], 'supply': 'network' if measure['Supply'].lower() == 'none' else 'auto', 'status': 'active', 'category': 'smart', 'version': '1.0' } stream_data = { 'id': stream_code, 'sensor': sensor, 'visibility': 'public', 'fps': frequency2fps(measure['Frequency']), 'domain': 'IoTNet', 'license': 'CC BY 4.0', 'copyright': 'Copyright (C) 2014, CSP Innovazione nelle ICT. All rights reserved.', 'components': [{ 'id': 'value', 'unit': measure['Unit'], 'allowance': float(measure['Allowance']), 'type': 'float', 'event': measure['ObservedProperty'], }], 'tags': [] } print_red('SENSOR DATA') pprint.pprint(sensor_data, width=100) print('') print_red('STREAM DATA') pprint.pprint(stream_data, width=100)
def test_zero_means_zero(self): frequency2fps('0') == 0
def test_zero_value_means_zero(self): frequency2fps('0sec') == 0
def test_invalid_unit(self): frequency2fps('10lightyear')
def test_invalid_value(self): frequency2fps(u'0x300sec')
def test_invalid_mesaure(self): frequency2fps('invalid')
def test_measure_minute(self): converted_value = frequency2fps('10min') assert converted_value == 1.0 / (10.0 * 60.0), converted_value
def test_measure_sec(self): sample_frequency = 1.0 / 300.0 # All measures in test file are 300fps for measure in islice(self.samples.values(), 10): assert frequency2fps( measure['Frequency']) == sample_frequency, measure