Beispiel #1
0
    def save_profile(self, profileinstance):
        delete_list = list()
        sequences_db_instances = dict()

        try:
            with db.atomic():
                profile = ProfileModel.create(
                    name=profileinstance.profilename,
                    aircraft=profileinstance.aircraft)
        except IntegrityError:
            profile = ProfileModel.get(
                ProfileModel.name == profileinstance.profilename)
        profile.aircraft = profileinstance.aircraft

        for waypoint in profile.waypoints:
            delete_list.append(waypoint)

        for sequence in profile.sequences:
            delete_list.append(sequence)

        self.logger.debug(
            f"Attempting to save profile {profileinstance.profilename}")
        for sequencenumber in profileinstance.sequences:
            sequence_db_instance = SequenceModel.create(
                identifier=sequencenumber, profile=profile)
            sequences_db_instances[sequencenumber] = sequence_db_instance

        for wp_type, wp_list in profileinstance.waypoints.items():
            if wp_type != "MSN":
                for waypoint in wp_list:
                    sequence = sequences_db_instances.get(waypoint.sequence)
                    WaypointModel.create(
                        name=waypoint.name,
                        latitude=waypoint.position.lat.decimal_degree,
                        longitude=waypoint.position.lon.decimal_degree,
                        elevation=waypoint.elevation,
                        profile=profile,
                        sequence=sequence,
                        wp_type=waypoint.wp_type)
            else:
                for station, station_wps in wp_list.items():
                    for waypoint in station_wps:
                        WaypointModel.create(
                            name=waypoint.name,
                            latitude=waypoint.position.lat.decimal_degree,
                            longitude=waypoint.position.lon.decimal_degree,
                            elevation=waypoint.elevation,
                            profile=profile,
                            wp_type=waypoint.wp_type,
                            station=station)

        for instance in delete_list:
            instance.delete_instance()
        profile.save()
Beispiel #2
0
    def save(self, profilename=None):
        delete_list = list()
        if profilename is not None:
            self.profilename = profilename

        try:
            with db.atomic():
                profile = ProfileModel.create(name=self.profilename,
                                              aircraft=self.aircraft)
        except IntegrityError:
            profile = ProfileModel.get(ProfileModel.name == self.profilename)
        profile.aircraft = self.aircraft

        for waypoint in profile.waypoints:
            delete_list.append(waypoint)

        for sequence in profile.sequences:
            delete_list.append(sequence)

        sequences_db_instances = dict()
        for sequencenumber in self.sequences:
            sequence_db_instance = SequenceModel.create(
                identifier=sequencenumber, profile=profile)
            sequences_db_instances[sequencenumber] = sequence_db_instance

        for waypoint in self.waypoints:
            if not isinstance(waypoint, MSN):
                sequence = sequences_db_instances.get(waypoint.sequence)
                WaypointModel.create(
                    name=waypoint.name,
                    latitude=waypoint.position.lat.decimal_degree,
                    longitude=waypoint.position.lon.decimal_degree,
                    elevation=waypoint.elevation,
                    profile=profile,
                    sequence=sequence,
                    wp_type=waypoint.wp_type)
            else:
                WaypointModel.create(
                    name=waypoint.name,
                    latitude=waypoint.position.lat.decimal_degree,
                    longitude=waypoint.position.lon.decimal_degree,
                    elevation=waypoint.elevation,
                    profile=profile,
                    wp_type=waypoint.wp_type,
                    station=waypoint.station)

        for instance in delete_list:
            instance.delete_instance()
        profile.save()
Beispiel #3
0
    def delete(profile_name):
        profile = ProfileModel.get(name=profile_name)

        for waypoint in profile.waypoints:
            waypoint.delete_instance()

        profile.delete_instance(recursive=True)
Beispiel #4
0
    def load(profile_name):
        profile = ProfileModel.get(ProfileModel.name == profile_name)
        aircraft = profile.aircraft

        wps = list()
        for waypoint in profile.waypoints:
            try:
                sequence = waypoint.sequence.identifier
            except AttributeError:
                sequence = 0

            if waypoint.wp_type != "MSN":
                wp = Waypoint(LatLon(Latitude(waypoint.latitude),
                                     Longitude(waypoint.longitude)),
                              elevation=waypoint.elevation,
                              name=waypoint.name,
                              sequence=sequence,
                              wp_type=waypoint.wp_type)
            else:
                wp = MSN(LatLon(Latitude(waypoint.latitude),
                                Longitude(waypoint.longitude)),
                         elevation=waypoint.elevation,
                         name=waypoint.name,
                         sequence=sequence,
                         wp_type=waypoint.wp_type,
                         station=waypoint.station)
            wps.append(wp)

        profile = Profile(profile_name, waypoints=wps, aircraft=aircraft)
        profile.update_waypoint_numbers()
        logger.debug(
            f"Fetched {profile_name} from DB, with {len(wps)} waypoints")
        return profile
Beispiel #5
0
    def get_profile(self, profilename):
        profile = ProfileModel.get(ProfileModel.name == profilename)
        aircraft = profile.aircraft

        wps = dict()
        for waypoint in profile.waypoints:
            if waypoint.wp_type == "MSN":
                wps_list = wps.get(waypoint.wp_type,
                                   dict()).get(waypoint.station, list())
            else:
                wps_list = wps.get(waypoint.wp_type, list())

            if waypoint.sequence:
                sequence = waypoint.sequence.identifier
            else:
                sequence = None

            wp = Wp(LatLon(Latitude(waypoint.latitude),
                           Longitude(waypoint.longitude)),
                    elevation=waypoint.elevation,
                    name=waypoint.name,
                    sequence=sequence,
                    wp_type=waypoint.wp_type,
                    station=waypoint.station)

            if waypoint.wp_type == "MSN":
                stations = wps.get("MSN", dict())
                station = stations.get(waypoint.station, list())
                station.append(wp)
                stations[waypoint.station] = station
                wps["MSN"] = stations
            else:
                wps_list.append(wp)
                wps[waypoint.wp_type] = wps_list

        self.logger.debug(
            f"Fetched {profilename} from DB, with {len(wps)} waypoints")
        return wps, aircraft
Beispiel #6
0
 def list_all():
     return list(ProfileModel.select())
Beispiel #7
0
 def get_profile_names():
     return [profile.name for profile in ProfileModel.select()]