def test_cache_storage(self): """ test that a telemetry object which goes into memcached is the same as one which comes out """ seabus = Boat.all_seabuses()[0] telemetry = Telemetry.from_db_for_boat(seabus) telemetry.put_cache() cached_telemetry = Telemetry.from_cache_for_boat(seabus) assert telemetry == cached_telemetry
def listen(config): """ listen for and process incoming UDP AIS location beacons sent from the AIS Decoder process on the tuner """ host = config.get('LISTENER_HOST') port = config.get('LISTENER_PORT') update_url = config.get('LISTENER_UPDATE_URL') log.info('Listenening for AIS beacons on {}:{}'.format(host, port)) for data in read_socket(host, port): beacon = decode(data) if beacon is not None: if is_interesting(beacon): log.info('Interesting beacon type: {}'.format(beacon.get('id'))) log.info(beacon) # extract boat data from beacon, here we should get one of the following (ALL CASES ARE STORED IN DB!) # - an existing boat record from the db by checking mmsi in the beacon, regardless of beacon type # - a new boat object with mmsi but no name, dimensions, etc. because this is a telemetry beacon # - a new (or updated by this beacon) boat object with mmsi, name, dimensions, etc. because this is a type 5 static voyage data beacon boat = Boat.from_beacon(beacon) # try to extract telemetry data from beacon telemetry = Telemetry.from_beacon(beacon) # if this beacon has telemetry, mark it as belonging to source boat #TODO: call this method after checking if boat is none if telemetry is not None: telemetry.set_boat(boat) # if we know BOTH the vessel and the telemetry, it's worth recording new information if None not in (boat, telemetry): if boat.is_seabus: log.info('Seabus: {}, {}'.format(boat.name, telemetry)) # cache this telemetry for immediate use in the web app telemetry.put_cache() # notify web app that new data is available for push to clients try: resp = requests.get(update_url) except requests.exceptions.ConnectionError as e: log.error('Unable to reach /update endpoint! {}'.format(e)) if not resp.ok: log.error('Bad response code: {}, msg: {}'.format(resp.status_code, resp.text)) else: log.debug('Web app /update endpoint hit.') else: log.info('Other Vessel: {}, {}'.format(boat.name, telemetry)) # now write to db telemetry.smart_save()
def listen(config): """ listen for and process incoming UDP AIS location beacons sent from the AIS Decoder process on the tuner """ host = config.get('LISTENER_HOST') port = config.get('LISTENER_PORT') update_url = config.get('LISTENER_UPDATE_URL') log.info('Listenening for AIS beacons on {}:{}'.format(host, port)) for data in read_socket(host, port): beacon = decode(data) if beacon is not None: if is_interesting(beacon): log.info('Interesting beacon type: {}'.format( beacon.get('id'))) log.info(beacon) # extract boat data from beacon, here we should get one of the following (ALL CASES ARE STORED IN DB!) # - an existing boat record from the db by checking mmsi in the beacon, regardless of beacon type # - a new boat object with mmsi but no name, dimensions, etc. because this is a telemetry beacon # - a new (or updated by this beacon) boat object with mmsi, name, dimensions, etc. because this is a type 5 static voyage data beacon boat = Boat.from_beacon(beacon) # try to extract telemetry data from beacon telemetry = Telemetry.from_beacon(beacon) # if this beacon has telemetry, mark it as belonging to source boat #TODO: call this method after checking if boat is none if boat is not None: if telemetry is not None: telemetry.set_boat(boat) # if we know BOTH the vessel and the telemetry, it's worth recording new information if None not in (boat, telemetry): log.info('Vessel: {}, {}'.format(boat.name, telemetry)) # cache this telemetry for immediate use in the web app telemetry.put_cache() # notify web app that new data is available for push to clients try: resp = requests.get(update_url) except requests.exceptions.ConnectionError as e: log.error('Unable to reach /update endpoint! {}'.format(e)) if not resp.ok: log.error('Bad response code: {}, msg: {}'.format( resp.status_code, resp.text)) else: log.debug('Web app /update endpoint hit.') # now write to db telemetry.smart_save()
def setUp(self): db.create_all() boat_beacon = decode(self.boat_msg) pos_beacon = decode(self.pos_msg) boat = Boat.from_beacon(boat_beacon) telemetry = Telemetry.from_beacon(pos_beacon) assert boat is not None assert telemetry is not None telemetry.set_boat(boat) telemetry.smart_save()
def seabus_telemetry(): """ retrieve current seabus telemetry """ telemetry = {'boats': []} for boat in Boat.all_seabuses(): boat_telemetry = Telemetry.get_for_boat(boat) telemetry['boats'].append({ 'lat': boat_telemetry.lat, 'lon': boat_telemetry.lon, 'true_heading': boat_telemetry.true_heading, 'name': boat.name, 'id': boat.id }) return telemetry
def seabus_telemetry(): """ retrieve current seabus telemetry """ telemetry = {'boats': []} for boat in Boat.all_seabuses(): boat_telemetry = Telemetry.get_for_boat(boat) with oboe.profile_block('make_dict'): telemetry['boats'].append({ 'lat': boat_telemetry.lat, 'lon': boat_telemetry.lon, 'true_heading': boat_telemetry.true_heading, 'name': boat.name, 'id': boat.id }) return telemetry
def test_decode_sanity(self): seabus = Boat.all_seabuses()[0] assert 'BURRARD' in seabus.name