Example #1
0
    def update_flight_path(flight):
        from skylines.lib.xcsoar_ import flight_path
        from skylines.lib.datetime import from_seconds_of_day

        # Now populate the FlightPathChunks table with the (full) flight path
        path_detailed = flight_path(flight.igc_file,
                                    max_points=3000,
                                    qnh=flight.qnh)
        if len(path_detailed) < 2:
            return False

        # Number of points in each chunck.
        num_points = 100

        # Interval of the current chunck: [i, j] (-> path_detailed[i:j + 1])
        i = 0
        j = min(num_points - 1, len(path_detailed) - 1)

        # Ensure that the last chunk contains at least two fixes
        if j == len(path_detailed) - 2:
            j = len(path_detailed) - 1

        FlightPathChunks.query().filter(
            FlightPathChunks.flight == flight).delete()
        date_utc = flight.igc_file.date_utc

        while True:
            flight_path = FlightPathChunks(flight=flight)

            # Save the timestamps of the coordinates
            flight_path.timestamps = \
                [from_seconds_of_day(date_utc, c.seconds_of_day) for c in path_detailed[i:j + 1]]

            flight_path.start_time = path_detailed[i].datetime
            flight_path.end_time = path_detailed[j].datetime

            # Convert the coordinate into a list of tuples
            coordinates = [(c.location['longitude'], c.location['latitude'])
                           for c in path_detailed[i:j + 1]]

            # Create a shapely LineString object from the coordinates
            linestring = LineString(coordinates)

            # Save the new path as WKB
            flight_path.locations = from_shape(linestring, srid=4326)

            db.session.add(flight_path)

            if j == len(path_detailed) - 1:
                break
            else:
                i = j + 1
                j = min(j + num_points, len(path_detailed) - 1)

                if j == len(path_detailed) - 2:
                    j = len(path_detailed) - 1

        db.session.commit()

        return True
Example #2
0
def near(flight_id):
    flight = get_requested_record(Flight,
                                  flight_id,
                                  joinedload=[Flight.igc_file])

    current_user = User.get(request.user_id) if request.user_id else None
    if not flight.is_viewable(current_user):
        return jsonify(), 404

    try:
        latitude = float(request.args['lat'])
        longitude = float(request.args['lon'])
        time = float(request.args['time'])

    except (KeyError, ValueError):
        abort(400)

    location = Location(latitude=latitude, longitude=longitude)
    time = from_seconds_of_day(flight.takeoff_time, time)

    flights = _get_near_flights(flight, location, time, 1000)

    def add_flight_path(flight):
        trace = _get_flight_path(flight, threshold=0.0001, max_points=10000)
        trace['additional'] = dict(registration=flight.registration,
                                   competition_id=flight.competition_id)

        return trace

    return jsonify(flights=map(add_flight_path, flights))
Example #3
0
    def update_flight_path(self):
        from skylines.lib.xcsoar_ import flight_path
        from skylines.lib.datetime import from_seconds_of_day

        # Run the IGC file through the FlightPath utility
        path = flight_path(self.igc_file, qnh=self.qnh)
        if len(path) < 2:
            return False

        # Save the timestamps of the coordinates
        date_utc = self.igc_file.date_utc
        self.timestamps = \
            [from_seconds_of_day(date_utc, c.seconds_of_day) for c in path]

        # Convert the coordinate into a list of tuples
        coordinates = [(c.location['longitude'], c.location['latitude'])
                       for c in path]

        # Create a shapely LineString object from the coordinates
        linestring = LineString(coordinates)

        # Save the new path as WKB
        self.locations = from_shape(linestring, srid=4326)

        return True
Example #4
0
    def update_flight_path(self):
        from skylines.lib.xcsoar_ import flight_path
        from skylines.lib.datetime import from_seconds_of_day

        # Run the IGC file through the FlightPath utility
        path = flight_path(self.igc_file, qnh=self.qnh)
        if len(path) < 2:
            return False

        # Save the timestamps of the coordinates
        date_utc = self.igc_file.date_utc
        self.timestamps = [
            from_seconds_of_day(date_utc, c.seconds_of_day) for c in path
        ]

        # Convert the coordinate into a list of tuples
        coordinates = [(c.location["longitude"], c.location["latitude"]) for c in path]

        # Create a shapely LineString object from the coordinates
        linestring = LineString(coordinates)

        # Save the new path as WKB
        self.locations = from_shape(linestring, srid=4326)

        return True
Example #5
0
def near(flight_id):
    flight = get_requested_record(Flight, flight_id, joinedload=[Flight.igc_file])

    current_user = User.get(request.user_id) if request.user_id else None
    if not flight.is_viewable(current_user):
        return jsonify(), 404

    try:
        latitude = float(request.args["lat"])
        longitude = float(request.args["lon"])
        time = float(request.args["time"])

    except (KeyError, ValueError):
        abort(400)

    location = Location(latitude=latitude, longitude=longitude)
    time = from_seconds_of_day(flight.takeoff_time, time)

    flights = _get_near_flights(flight, location, time, 1000)

    def add_flight_path(flight):
        trace = _get_flight_path(flight, threshold=0.0001, max_points=10000)
        trace["additional"] = dict(registration=flight.registration, competition_id=flight.competition_id)

        return trace

    return jsonify(flights=map(add_flight_path, flights))
Example #6
0
    def update_flight_path(flight):
        from skylines.lib.xcsoar_ import flight_path
        from skylines.lib.datetime import from_seconds_of_day

        # Now populate the FlightPathChunks table with the (full) flight path
        path_detailed = flight_path(flight.igc_file, max_points=3000, qnh=flight.qnh)
        if len(path_detailed) < 2:
            return False

        # Number of points in each chunck.
        num_points = 100

        # Interval of the current chunck: [i, j] (-> path_detailed[i:j + 1])
        i = 0
        j = min(num_points - 1, len(path_detailed) - 1)

        # Ensure that the last chunk contains at least two fixes
        if j == len(path_detailed) - 2:
            j = len(path_detailed) - 1

        FlightPathChunks.query().filter(FlightPathChunks.flight == flight).delete()
        date_utc = flight.igc_file.date_utc

        while True:
            flight_path = FlightPathChunks(flight=flight)

            # Save the timestamps of the coordinates
            flight_path.timestamps = \
                [from_seconds_of_day(date_utc, c.seconds_of_day) for c in path_detailed[i:j + 1]]

            flight_path.start_time = path_detailed[i].datetime
            flight_path.end_time = path_detailed[j].datetime

            # Convert the coordinate into a list of tuples
            coordinates = [(c.location['longitude'], c.location['latitude']) for c in path_detailed[i:j + 1]]

            # Create a shapely LineString object from the coordinates
            linestring = LineString(coordinates)

            # Save the new path as WKB
            flight_path.locations = from_shape(linestring, srid=4326)

            db.session.add(flight_path)

            if j == len(path_detailed) - 1:
                break
            else:
                i = j + 1
                j = min(j + num_points, len(path_detailed) - 1)

                if j == len(path_detailed) - 2:
                    j = len(path_detailed) - 1

        db.session.commit()

        return True
Example #7
0
def near():
    try:
        latitude = float(request.args['lat'])
        longitude = float(request.args['lon'])
        time = float(request.args['time'])

    except (KeyError, ValueError):
        abort(400)

    location = Location(latitude=latitude, longitude=longitude)
    time = from_seconds_of_day(g.flight.takeoff_time, time)

    flights = _get_near_flights(g.flight, location, time, 1000)

    def add_flight_path(flight):
        trace = _get_flight_path(flight, threshold=0.0001, max_points=10000)
        trace['additional'] = dict(registration=flight.registration,
                                   competition_id=flight.competition_id)

        return trace

    return jsonify(flights=map(add_flight_path, flights))
Example #8
0
def near():
    try:
        latitude = float(request.args['lat'])
        longitude = float(request.args['lon'])
        time = float(request.args['time'])

    except (KeyError, ValueError):
        abort(400)

    location = Location(latitude=latitude, longitude=longitude)
    time = from_seconds_of_day(g.flight.takeoff_time, time)

    flights = _get_near_flights(g.flight, location, time, 1000)

    def add_flight_path(flight):
        trace = _get_flight_path(flight, threshold=0.0001, max_points=10000)
        trace['additional'] = dict(
            registration=flight.registration,
            competition_id=flight.competition_id)

        return trace

    return jsonify(flights=map(add_flight_path, flights))
Example #9
0
    def near(self, **kwargs):
        try:
            latitude = float(kwargs['lat'])
            longitude = float(kwargs['lon'])
            time = float(kwargs['time'])

        except (KeyError, ValueError):
            raise HTTPBadRequest

        location = Location(latitude=latitude,
                            longitude=longitude)
        time = from_seconds_of_day(self.flight.takeoff_time, time)

        flights = get_near_flights(self.flight, location, time, 1000)

        def add_flight_path(flight):
            trace = get_flight_path(flight, threshold=0.0001, max_points=10000)
            trace['additional'] = dict(
                registration=flight.registration,
                competition_id=flight.competition_id)

            return trace

        return dict(flights=map(add_flight_path, flights))
Example #10
0
def read_time_of_day(turnpoint, flight):
    if 'time' not in turnpoint:
        return None

    return from_seconds_of_day(flight.takeoff_time.date(),
                               int(turnpoint['time']))
Example #11
0
def read_time_of_day(turnpoint, flight):
    if "time" not in turnpoint:
        return None

    return from_seconds_of_day(flight.takeoff_time.date(), int(turnpoint["time"]))