예제 #1
0
 public FlightPlan(int passengers, string company_name, InitialLocation initial_location, List <Segment> segments)
 {
     this.passengers       = passengers;
     this.company_name     = company_name;
     this.initial_location = initial_location;
     this.segments         = segments;
 }
        private static Location CalculateLocation(InitialLocation flightInitialLocation, TimeSpan flightTime, SegmentDto prevSegment, Segment segment)
        {
            Location location = new Location();

            if (flightTime.TotalSeconds == 0)
            {
                return(new Location {
                    Latitude = segment.Latitude, Longitude = segment.Longitude
                });
            }
            double ratio = ((segment.TimeSpanSeconds + flightTime.TotalSeconds) / (double)segment.TimeSpanSeconds);


            if (prevSegment == null)
            {
                location.Latitude = flightInitialLocation.Latitude + ratio *
                                    (segment.Latitude - flightInitialLocation.Latitude);
                location.Longitude = flightInitialLocation.Longitude + ratio *
                                     (segment.Longitude - flightInitialLocation.Longitude);
                return(location);
            }
            location.Latitude  = prevSegment.Latitude + (ratio * (segment.Latitude - prevSegment.Latitude));
            location.Longitude = prevSegment.Longitude + (ratio * (segment.Longitude - prevSegment.Longitude));
            return(location);
        }
        private async Task CreateFlight(DateTime dateTime, List <Flight> flights, FlightPlan fp)
        {
            InitialLocation initialLocation = await _context.InitialLocation.FindAsync(fp.FlightId);

            var landingTime = await LandingTime(fp);

            if (initialLocation != null && ((initialLocation.DateTime.CompareTo(dateTime) < 0 && landingTime.CompareTo(dateTime) > 0) || initialLocation.DateTime.CompareTo(dateTime) == 0))
            {
                Location location = await GetFlightLocation(fp, dateTime);

                if (location != null)
                {
                    flights.Add(new Flight
                    {
                        FlightId    = fp.FlightId,
                        Longitude   = location.Longitude,
                        Latitude    = location.Latitude,
                        Passengers  = fp.Passengers,
                        CompanyName = fp.CompanyName,
                        DateTime    = dateTime,
                        IsExternal  = false
                    });
                }
            }
        }
예제 #4
0
        public FlightPlanDB FlightsPlanById(string id)
        {
            InitialLocation initialLocation;
            FlightPlanDB    flightPlanDB = null;
            FlightPlan      flightPlan;
            string          query = $"SELECT * FROM Flight WHERE id = '{id}'";

            SQLiteCommand myCommand = new SQLiteCommand(query, databaseObject.myConnection);
            ////databaseObject.OpenConnection();
            SQLiteDataReader result = myCommand.ExecuteReader();

            // Creating a List of integers

            if (result.HasRows)
            {
                while (result.Read())
                {
                    string company   = $"{result["company"]}";
                    int    passenger = Convert.ToInt32($"{result["passengers"]}");
                    //create initial location
                    initialLocation = new InitialLocation(Convert.ToDouble(
                                                              $"{result["start_longitude"]}"),
                                                          Convert.ToDouble($"{result["start_latitude"]}"),
                                                          FromStringToDate($"{result["start_time"]}"));
                    //create flightplan
                    flightPlan = new FlightPlan(passenger, company,
                                                initialLocation, SegmentList(id));
                    flightPlanDB = new FlightPlanDB(id, flightPlan);
                }
            }
            //databaseObject.CloseConnection();


            return(flightPlanDB);
        }