def setUp(self): super().setUp() # Create basic data and insert self.dd0815 = Device(address="DD0815") self.dd4711 = Device(address="DD4711") self.r01 = Receiver(name="Koenigsdf") self.r02 = Receiver(name="Bene") db.session.add(self.dd0815) db.session.add(self.dd4711) db.session.add(self.r01) db.session.add(self.r02) db.session.commit() # Create beacons and insert self.ab01 = AircraftBeacon(name="FLRDD0815", receiver_name="Koenigsdf", device_id=self.dd0815.id, receiver_id=self.r01.id, timestamp="2017-12-10 10:00:00", location_mgrs_short="89ABC1267", altitude=800) self.ab02 = AircraftBeacon(name="FLRDD0815", receiver_name="Koenigsdf", device_id=self.dd0815.id, receiver_id=self.r01.id, timestamp="2017-12-10 10:00:01", location_mgrs_short="89ABC1267", altitude=850) db.session.add(self.ab01) db.session.add(self.ab02) db.session.commit()
def setUp(self): super().setUp() # Prepare Beacons self.ab01 = AircraftBeacon(name="FLRDD4711", receiver_name="Koenigsdf", timestamp="2017-12-10 10:00:01") self.ab02 = AircraftBeacon(name="FLRDD4711", receiver_name="Koenigsdf", timestamp="2017-12-10 10:00:02") self.ab03 = AircraftBeacon(name="FLRDD4711", receiver_name="Koenigsdf", timestamp="2017-12-10 10:00:03") self.ab04 = AircraftBeacon(name="FLRDD4711", receiver_name="Koenigsdf", timestamp="2017-12-10 10:00:04") self.ab05 = AircraftBeacon(name="FLRDD4711", receiver_name="Koenigsdf", timestamp="2017-12-10 10:00:05") self.ab06 = AircraftBeacon(name="FLRDD4711", receiver_name="Koenigsdf", timestamp="2017-12-10 10:00:05") self.rb01 = ReceiverBeacon(name="Koenigsdf", receiver_name="GLIDERN1", timestamp="2017-12-10 09:55:00", altitude=601, version="0.2.5", platform="ARM") self.rb02 = ReceiverBeacon(name="Koenigsdf", receiver_name="GLIDERN1", timestamp="2017-12-10 10:00:00", altitude=601, version="0.2.7", platform="ARM") self.rb03 = ReceiverBeacon(name="Koenigsdf", receiver_name="GLIDERN1", timestamp="2017-12-10 10:05:00", altitude=601, version="0.2.6", platform="ARM") self.r01 = Receiver(name="Koenigsdf") self.r02 = Receiver(name="Bene") self.d01 = Device(address="DD4711") db.session.add(self.r01) db.session.add(self.d01) db.session.commit()
def setUp(self): super().setUp() # Prepare Beacons self.r01 = Receiver(name="Koenigsdf", location_wkt="0101000020E610000061E8FED7A6EE26407F20661C10EA4740", lastseen="2017-12-20 10:00:00", altitude=601, version="0.2.5", platform="ARM") self.r02 = Receiver(name="Bene", location_wkt="0101000020E6100000D5E76A2BF6C72640D4063A6DA0DB4740", lastseen="2017-12-20 09:45:00", altitude=609, version="0.2.7", platform="x64") self.r03 = Receiver(name="Ohlstadt", location_wkt="0101000020E6100000057E678EBF772640A142883E32D44740", lastseen="2017-12-20 10:05:00", altitude=655, version="0.2.6", platform="ARM") db.session.add(self.r01) db.session.add(self.r02) db.session.add(self.r03) db.session.commit() self.d01 = Device(address="DD4711", lastseen="2017-12-20 10:00:02") self.d02 = Device(address="DD0815", lastseen="2017-12-20 09:56:00") db.session.add(self.d01) db.session.add(self.d02) db.session.commit() self.di01 = DeviceInfo(registration="D-4711", competition="Hi", tracked=True, identified=True) db.session.add(self.di01) db.session.commit() self.ab11 = AircraftBeacon( name="FLRDD4711", receiver_name="Koenigsdf", location_wkt="0101000020E6100000211FF46C56ED26402650D7EDC6E94740", aircraft_type=AircraftType.glider_or_motor_glider, timestamp="2017-12-20 10:00:01", track=105, ground_speed=57, climb_rate=-0.5, device_id=self.d01.id, ) self.ab12 = AircraftBeacon( name="FLRDD4711", receiver_name="Koenigsdf", location_wkt="0101000020E6100000806DEA295FED2640347D898BB6E94740", aircraft_type=AircraftType.glider_or_motor_glider, timestamp="2017-12-20 10:00:02", track=123, ground_speed=55, climb_rate=-0.4, altitude=209, device_id=self.d01.id, ) self.ab21 = AircraftBeacon( name="FLRDD0815", receiver_name="Koenigsdf", location_wkt="0101000020E6100000F38B25BF58F22640448B6CE7FBE94740", aircraft_type=AircraftType.powered_aircraft, timestamp="2017-12-20 09:54:30", track=280, ground_speed=80, climb_rate=-2.9, device_id=self.d02.id, ) self.ab22 = AircraftBeacon( name="FLRDD0815", receiver_name="Bene", location_wkt="0101000020E6100000A5E8482EFFF12640DC1EAA16FEE94740", aircraft_type=AircraftType.powered_aircraft, timestamp="2017-12-20 09:56:00", track=270, ground_speed=77, climb_rate=-1.5, altitude=543, device_id=self.d02.id, ) db.session.add(self.ab11) db.session.add(self.ab12) db.session.add(self.ab21) db.session.add(self.ab22) db.session.commit() self.rc11 = ReceiverCoverage( location_mgrs_short="32TPU8312", date=date(2017, 12, 20), max_signal_quality=10, max_altitude=1000, min_altitude=600, aircraft_beacon_count=20, device_count=2, receiver=self.r01 ) self.rc12 = ReceiverCoverage( location_mgrs_short="32TPU8434", date=date(2017, 12, 20), max_signal_quality=10, max_altitude=1000, min_altitude=600, aircraft_beacon_count=20, device_count=2, receiver=self.r01 ) self.rc12 = ReceiverCoverage( location_mgrs_short="32TPU8434", date=date(2017, 12, 21), max_signal_quality=10, max_altitude=1000, min_altitude=600, aircraft_beacon_count=20, device_count=2, receiver=self.r01 ) self.rc21 = ReceiverCoverage( location_mgrs_short="32TPU8512", date=date(2017, 12, 20), max_signal_quality=10, max_altitude=1000, min_altitude=600, aircraft_beacon_count=20, device_count=2, receiver=self.r02 ) db.session.add(self.rc11) db.session.add(self.rc12) db.session.add(self.rc21) db.session.commit()
def convert(sourcefile, datestr, saver): from app.gateway.process import string_to_message from app.gateway.process_tools import AIRCRAFT_BEACON_TYPES, RECEIVER_BEACON_TYPES from datetime import datetime fin = open_file(sourcefile) # get total lines of the input file total_lines = 0 for line in fin: total_lines += 1 fin.seek(0) current_line = 0 steps = 100000 reference_date = datetime.strptime(datestr + " 12:00:00", "%Y-%m-%d %H:%M:%S") pbar = tqdm(fin, total=total_lines) for line in pbar: pbar.set_description("Importing {}".format(sourcefile)) current_line += 1 if current_line % steps == 0: saver.flush() message = string_to_message(line.strip(), reference_date=reference_date) if message is None: continue dictfilt = lambda x, y: dict([(i, x[i]) for i in x if i in set(y)]) try: if message["beacon_type"] in AIRCRAFT_BEACON_TYPES: message = dictfilt( message, ( "beacon_type", "aprs_type", "location_wkt", "altitude", "name", "dstcall", "relay", "receiver_name", "timestamp", "track", "ground_speed", "address_type", "aircraft_type", "stealth", "address", "climb_rate", "turn_rate", "signal_quality", "error_count", "frequency_offset", "gps_quality_horizontal", "gps_quality_vertical", "software_version", "hardware_version", "real_address", "signal_power", "distance", "radial", "quality", "agl", "location_mgrs", "location_mgrs_short", "receiver_id", "device_id", ), ) beacon = AircraftBeacon(**message) elif message["beacon_type"] in RECEIVER_BEACON_TYPES: if "rec_crystal_correction" in message: del message["rec_crystal_correction"] del message["rec_crystal_correction_fine"] beacon = ReceiverBeacon(**message) saver.add(beacon) except Exception as e: print(e) saver.flush() fin.close()