Ejemplo n.º 1
0
        public int CalcDistance(string departure, string arrival)
        {
            var departureInfo = AirportDatabaseFile.FindAirportInfo(departure);
            var arrivalInfo   = AirportDatabaseFile.FindAirportInfo(arrival);

            if (departureInfo != null && arrivalInfo != null)
            {
                var departureCoord = new GeoCoordinate(departureInfo.Latitude, departureInfo.Longitude);
                var arrivalCoord   = new GeoCoordinate(arrivalInfo.Latitude, arrivalInfo.Longitude);

                var distMeters = departureCoord.GetDistanceTo(arrivalCoord);
                var distMiles  = (int)DataConversion.ConvertMetersToMiles(distMeters);
                return(distMiles);
            }
            return(0);
        }
Ejemplo n.º 2
0
        public ActionResult AlternativeTips(string destination, int range)
        {
            var listTips = new List <SearchJobTipsViewModel>();

            if (!string.IsNullOrEmpty(destination) && destination.Length > 2)
            {
                var destinationInfo = AirportDatabaseFile.FindAirportInfo(destination);
                if (destinationInfo == null)
                {
                    return(null);
                }

                var destCoord = new GeoCoordinate(destinationInfo.Latitude, destinationInfo.Longitude);

                foreach (var airportInfo in AirportDatabaseFile.GetAllAirportInfo().OrderByDescending(x => x.RunwaySize))
                {
                    if (airportInfo.ICAO.ToUpper() != destination.ToUpper())
                    {
                        var airportInfoCoord = new GeoCoordinate(airportInfo.Latitude, airportInfo.Longitude);
                        var distMeters       = destCoord.GetDistanceTo(airportInfoCoord);
                        var distMiles        = (int)DataConversion.ConvertMetersToMiles(distMeters);

                        if (distMiles < range)
                        {
                            var viewModel = new SearchJobTipsViewModel()
                            {
                                AirportICAO       = airportInfo.ICAO,
                                AirportName       = airportInfo.Name,
                                Distance          = distMiles,
                                AirportElevation  = airportInfo.Elevation,
                                AirportRunwaySize = airportInfo.RunwaySize,
                                AirportTrasition  = airportInfo.Trasition,
                            };
                            listTips.Add(viewModel);
                        }
                    }
                }
            }
            else
            {
                return(null);
            }
            TempData["RangeValue"] = range;
            return(PartialView("AlternativeTipsPartialView", listTips));
        }
Ejemplo n.º 3
0
        public string GetNearestLocation(double latitude, double longitude, int k)
        {
            GeoCoordinate actualCoordinate = new GeoCoordinate(latitude, longitude);

            List <LocationEntity> orderedLocations = Locations.ToList().OrderBy(entity => actualCoordinate.GetDistanceTo(entity.Coordinate)).ToList();

            List <LocationEntity> kNearest = orderedLocations.Take(k).ToList();
            List <IGrouping <string, LocationEntity> > grouped     = kNearest.GroupBy(entity => entity.GeographicalName).OrderBy(g => g.Count()).ToList();
            IGrouping <string, LocationEntity>         nearestList = grouped.First();
            LocationEntity nearest                 = nearestList.OrderBy(entity => actualCoordinate.GetDistanceTo(entity.Coordinate)).First();
            double         minDistance             = actualCoordinate.GetDistanceTo(nearest.Coordinate);
            var            nearestGeographicalName = nearestList.Key;

            double distanceInMiles = DataConversion.ConvertMetersToMiles(minDistance);
            string direction       = "";

            return($"{distanceInMiles:0.0} mi {direction} {nearestGeographicalName}");
        }
Ejemplo n.º 4
0
        public ActionResult ArrivalTips(string departure)
        {
            var listTips = new List <SearchJobTipsViewModel>();

            if (!string.IsNullOrEmpty(departure) && departure.Length > 2)
            {
                /*  Get destinations from current departure user jobs */
                var departureInfo = AirportDatabaseFile.FindAirportInfo(departure);
                if (departureInfo == null)
                {
                    return(null);
                }

                var departureCoord   = new GeoCoordinate(departureInfo.Latitude, departureInfo.Longitude);
                var dbContext        = new ApplicationDbContext();
                var user             = dbContext.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
                var allUserJobs      = FilterJobs(user, "");
                var filteredUserJobs = FilterJobs(user, departure);
                foreach (var job in filteredUserJobs)
                {
                    var jobAirportInfo = AirportDatabaseFile.FindAirportInfo(job.ArrivalICAO);
                    listTips.Add(new SearchJobTipsViewModel()
                    {
                        IdJob             = job.Id,
                        AirportICAO       = job.ArrivalICAO,
                        Cargo             = job.Cargo,
                        Pax               = job.Pax,
                        Pay               = job.Pay,
                        Payload           = job.Payload,
                        AirportName       = jobAirportInfo.Name,
                        AirportElevation  = jobAirportInfo.Elevation,
                        AirportRunwaySize = jobAirportInfo.RunwaySize,
                        AirportTrasition  = jobAirportInfo.Trasition,
                        Distance          = job.Dist
                    });
                }

                var countRandon = new Random();
                var indexRandon = new Random();

                if (allUserJobs.Count() > 1)
                {
                    var index = indexRandon.Next(1, allUserJobs.Count() - 1);

                    var count = countRandon.Next(1, allUserJobs.Count() - index);

                    /*  Get destinations from all user jobs */
                    foreach (var job in allUserJobs.GetRange(index, count).Take(7))
                    {
                        if (!listTips.Exists(x => x.AirportICAO == job.ArrivalICAO) &&
                            job.ArrivalICAO != departure)
                        {
                            var jobArrivalAirportInfo = AirportDatabaseFile.FindAirportInfo(job.ArrivalICAO);

                            var arrivalCoord = new GeoCoordinate(jobArrivalAirportInfo.Latitude, jobArrivalAirportInfo.Longitude);
                            var distMeters   = departureCoord.GetDistanceTo(arrivalCoord);
                            var distMiles    = (int)DataConversion.ConvertMetersToMiles(distMeters);

                            listTips.Add(new SearchJobTipsViewModel()
                            {
                                AirportICAO       = job.ArrivalICAO,
                                AirportName       = jobArrivalAirportInfo.Name,
                                AirportElevation  = jobArrivalAirportInfo.Elevation,
                                AirportRunwaySize = jobArrivalAirportInfo.RunwaySize,
                                AirportTrasition  = jobArrivalAirportInfo.Trasition,
                                Distance          = distMiles
                            });
                        }
                    }
                }

                /*  Random jobs */
                var tempListTips = new List <SearchJobTipsViewModel>();
                foreach (var airportInfo in AirportDatabaseFile.GetAllAirportInfo())
                {
                    if (airportInfo.ICAO.ToUpper() != departureInfo.ICAO.ToUpper())
                    {
                        var airportInfoCoord = new GeoCoordinate(airportInfo.Latitude, airportInfo.Longitude);
                        var distMeters       = departureCoord.GetDistanceTo(airportInfoCoord);
                        var distMiles        = (int)DataConversion.ConvertMetersToMiles(distMeters);

                        if (distMiles < 600)
                        {
                            var viewModel = new SearchJobTipsViewModel()
                            {
                                AirportICAO       = airportInfo.ICAO,
                                AirportName       = airportInfo.Name,
                                Distance          = distMiles,
                                AirportElevation  = airportInfo.Elevation,
                                AirportRunwaySize = airportInfo.RunwaySize,
                                AirportTrasition  = airportInfo.Trasition,
                            };
                            tempListTips.Add(viewModel);
                        }
                    }
                }
                var random         = new Random();
                var randomListTips = new List <SearchJobTipsViewModel>();
                for (int i = tempListTips.Count - 1; i >= 1; i--)
                {
                    int other = random.Next(0, i + 1);
                    randomListTips.Add(tempListTips[other]);
                }
                listTips.AddRange(randomListTips.Take(10));
            }
            else
            {
                return(null);
            }

            return(PartialView("ArrivalTipsPartialView", listTips));
        }
Ejemplo n.º 5
0
        internal IList <JobListModel> GenerateBoardJobs(JobSerachModel model, StatisticsDbModel statistics)
        {
            IList <JobListModel> listBoardJobs = new List <JobListModel>();

            try
            {
                var weightUnit = GetWeightUnit(Request);
                var dep        = AirportDatabaseFile.FindAirportInfo(model.Departure);
                var arrival    = AirportDatabaseFile.FindAirportInfo(model.Arrival);

                var  depCoord      = new GeoCoordinate(dep.Latitude, dep.Longitude);
                var  randomPob     = new Random();
                var  randomCargo   = new Random();
                int  id            = 0;
                bool validGaProfit = false;

                var arrCoord   = new GeoCoordinate(arrival.Latitude, arrival.Longitude);
                var distMeters = depCoord.GetDistanceTo(arrCoord);
                var distMiles  = (int)DataConversion.ConvertMetersToMiles(distMeters);

                //                    if (distMiles >= model.MinRange && distMiles <= model.MaxRange && arrival.ICAO.ToUpper() != dep.ICAO.ToUpper() &&
                //                        arrival.ICAO.ToUpper() == model.Arrival.ToUpper())

                if (arrival.ICAO.ToUpper() != dep.ICAO.ToUpper() &&
                    arrival.ICAO.ToUpper() == model.Arrival.ToUpper())
                {
                    var customCapacity = model.CustomPlaneCapacity;

                    if (GetWeightUnit(Request) == DataConversion.UnitPounds)
                    {
                        customCapacity.CustomCargoCapacityWeight = DataConversion.ConvertPoundsToKilograms(customCapacity.CustomCargoCapacityWeight);
                    }

                    int index = randomPob.Next(14, 25);
                    if (model.AviationType == "GeneralAviation" && model.UseCustomPlaneCapacity)
                    {
                        validGaProfit = customCapacity.CustomCargoCapacityWeight < 3000 && customCapacity.CustomPassengerCapacity < 30;
                    }

                    long gePobCount = 0, auxCargoCount = 0;

                    for (int i = 0; i < index; i++)
                    {
                        long pob          = 0;
                        long cargo        = 0;
                        long profit       = 0;
                        bool isFisrtClass = Convert.ToBoolean(randomPob.Next(2));

                        var  flightType     = model.AviationType.Trim();
                        int  alternateCargo = randomPob.Next(2);
                        bool isCargo        = alternateCargo == 0 || flightType == "Cargo";
                        if (isCargo)
                        {
                            int minCargo = 5;
                            int maxCargo = 160;
                            if (flightType == "AirTransport")
                            {
                                minCargo = 100; maxCargo = 3000;
                            }
                            ;
                            if (flightType == "Cargo")
                            {
                                minCargo = 80; maxCargo = 3500;
                            }
                            if (flightType == "HeavyAirTransport")
                            {
                                minCargo = 800; maxCargo = 6000;
                            }

                            if (model.UseCustomPlaneCapacity)
                            {
                                var cargoCapacity = customCapacity.CustomCargoCapacityWeight;
                                if (cargoCapacity < minCargo)
                                {
                                    cargoCapacity = minCargo + 1;
                                }
                                cargo = randomCargo.Next(minCargo, cargoCapacity);
                                if (auxCargoCount + cargo > cargoCapacity)
                                {
                                    cargo = cargoCapacity - auxCargoCount;
                                    if (cargo == 0)
                                    {
                                        continue;
                                    }
                                    auxCargoCount = cargoCapacity;
                                }
                                else
                                {
                                    auxCargoCount += cargo;
                                }
                            }
                            else
                            {
                                cargo = randomCargo.Next(minCargo, maxCargo);
                            }

                            if (flightType == "GeneralAviation")
                            {
                                if (validGaProfit)
                                {
                                    profit  = Convert.ToInt32(taxCargoGE * distMiles * cargo);
                                    profit += (140 / customCapacity.CustomCargoCapacityWeight);
                                }
                                else
                                {
                                    profit = Convert.ToInt32(taxCargo * distMiles * cargo);
                                }
                            }
                            else if (flightType == "AirTransport")
                            {
                                profit = Convert.ToInt32(taxCargo * distMiles * cargo);
                            }
                            else if (flightType == "Cargo")
                            {
                                profit = Convert.ToInt32((taxCargo + 0.0005) * distMiles * cargo);
                            }
                            else // HeavyAirTransport
                            {
                                profit = Convert.ToInt32(taxCargo * distMiles * cargo);
                            }
                        }
                        else
                        {
                            int minPob = 1;
                            int maxPob = 12;
                            if (flightType == "AirTransport")
                            {
                                minPob = 10; maxPob = 80;
                            }
                            ;
                            if (flightType == "HeavyAirTransport")
                            {
                                minPob = 50; maxPob = 140;
                            }

                            if (model.UseCustomPlaneCapacity)
                            {
                                if (customCapacity.CustomPassengerCapacity < minPob)
                                {
                                    customCapacity.CustomPassengerCapacity = minPob + 1;
                                }
                                pob = randomPob.Next(minPob, customCapacity.CustomPassengerCapacity);
                                if (gePobCount + pob > customCapacity.CustomPassengerCapacity)
                                {
                                    pob = customCapacity.CustomPassengerCapacity - gePobCount;
                                    if (pob == 0)
                                    {
                                        continue;
                                    }
                                    gePobCount = customCapacity.CustomPassengerCapacity;
                                }
                                else
                                {
                                    gePobCount += pob;
                                }
                            }
                            else
                            {
                                pob = randomPob.Next(minPob, maxPob);
                            }

                            if (flightType == "GeneralAviation")
                            {
                                isFisrtClass = true; /// Always premium for GA
                                if (validGaProfit)
                                {
                                    profit  = Convert.ToInt32(taxFirstGE * distMiles * pob);
                                    profit += ((distMiles * 2) / customCapacity.CustomPassengerCapacity);
                                }
                                else
                                {
                                    profit = Convert.ToInt32(taxFirstC * distMiles * pob);
                                }
                            }
                            else if (flightType == "AirTransport")
                            {
                                profit = isFisrtClass ? Convert.ToInt32(taxFirstC * distMiles * pob) : Convert.ToInt32(taxEcon * distMiles * pob);
                            }
                            else // HeavyAirTransport
                            {
                                profit = isFisrtClass ? Convert.ToInt32(taxFirstC * distMiles * pob) : Convert.ToInt32(taxEcon * distMiles * pob);
                            }
                        }

                        cargo = GetWeight(Request, cargo, statistics);

                        listBoardJobs.Add(new JobListModel()
                        {
                            Id           = id++,
                            Departure    = dep,
                            Arrival      = arrival,
                            Dist         = distMiles,
                            Pax          = pob,
                            Cargo        = cargo,
                            PayloadLabel = (isCargo) ? "[Cargo] " : (isFisrtClass) ? "[Full price] " : "[Promo] ",
                            PayloadView  = (isCargo) ? cargo + weightUnit : (isFisrtClass) ? pob + " Pax" : pob + " Pax",
                            Pay          = profit,
                            FirstClass   = isFisrtClass,
                            AviationType = model.AviationType,
                            IsCargo      = isCargo
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("error", ex.Message);
            }

            return(listBoardJobs.OrderBy(j => j.Arrival).ThenBy(x => x.PayloadLabel).ToList());
        }