コード例 #1
0
        public void PredictEndLocation()
        {
            foreach (var driver in drivers)
            {
                RoutePrediction routePrediction = new RoutePrediction(500);
                foreach (TripSummary trip in trips.Where(t => t.DriverId.Equals(driver)))
                {
                    routePrediction.AddTripSummary(trip);
                }

                double lat = 47.6583066666667;
                double lon = -122.14119;
                RoutePredictionResult predictionResult = routePrediction.PredictEndLocation(lat, lon, DateTime.Now);
                Console.WriteLine("driver: " + driver);
                Console.WriteLine("cluster level: " + predictionResult.ClusterLevel);

                foreach (var prediction in predictionResult.Predictions)
                {
                    Console.Write("Lat/Lon: " + prediction.Lat + "/" + prediction.Lon);
                    Console.Write("\tProbability: " + prediction.Probability);
                    Console.Write("\tEndpoints: " + prediction.NrOfEndPoints);
                    Console.Write("\tMatches T/D/W: " + prediction.NrOfTimeMatches);
                    Console.Write("/" + prediction.NrOfDayMatches);
                    Console.WriteLine("/" + prediction.NrOfWorkdayMatches);
                }
                Console.WriteLine();
            }
        }
コード例 #2
0
        private void PopulatePredictionViewByStop(string stopName, RoutePrediction prediction, List <string> displayedPlateNumbers)
        {
            int    secondsToArrival = prediction.EstimateTime;
            string plateNumber      = prediction.PlateNumb;

            if (plateNumber == "-1")
            {
                if (prediction.IsLastBus)
                {
                    PopulatePredictionView(stopName, MESSAGE_OUT_OF_SERVICE);
                }
                else
                {
                    PopulatePredictionView(stopName, MESSAGE_PLANNED);
                }
            }
            else if (displayedPlateNumbers.Contains(plateNumber))
            {
                PopulatePredictionView(stopName, secondsToArrival);
            }
            else
            {
                PopulatePredictionView(stopName, secondsToArrival, plateNumber);
                displayedPlateNumbers.Add(plateNumber);
            }
        }
コード例 #3
0
        private Button CreateRouteArriveButton(RoutePrediction arriveRoute, Route route, string routeUID = null)
        {
            Button button = new Button();

            if (routeUID == null)
            {
                routeUID = arriveRoute.SubRouteUID.Replace(" ", "");
            }
            RouteView.RouteViewConfig Config = new RouteView.RouteViewConfig(arriveRoute.RouteID, routeUID, arriveRoute.SubRouteName.En, route.HeadSign, FindBackSubRouteUID(routeUID, route));
            arriveRoute.EstimateTime = arriveRoute.EstimateTime / 60;
            button.Text     = string.Format("{0}\t {1}分鐘", new string[] { route.HeadSign, arriveRoute.EstimateTime.ToString() });
            button.Clicked += (object sender, EventArgs e) => { Navigation.PushAsync(new RouteView(Config)); };
            return(button);
        }
コード例 #4
0
        private void PopulateRoute(String routeID, String subRouteUID)
        {
            IEnumerable <StopOfRoute> stopsOfSingleRoute = StopOfRoute.RetrieveFromJson(string.Format(URL_STOP_OF_ROUTE, routeID))
                                                           .Where(entity => string.Equals(entity.SubRouteUID, subRouteUID));

            if (stopsOfSingleRoute.Count() == 0)
            {
                return;
            }

            IEnumerable <RoutePrediction> predictions = RoutePrediction.RetrieveFromJson(string.Format(URL_ESTIMATED_ARRIVAL, routeID, subRouteUID));
            StopArrivalPrediction         view        = new StopArrivalPrediction(stopsOfSingleRoute.First(), predictions);

            Content = new ScrollView {
                Content = view
            };
        }
コード例 #5
0
        public StopArrivalPrediction(StopOfRoute stopsOfSingleRoute, IEnumerable <RoutePrediction> predictions) : base()
        {
            Spacing = 3;
            Padding = new Thickness(20, 20, 20, 0);
            List <string> displayedPlateNumbers = new List <string>();

            foreach (StopOfRoute.Stop stop in stopsOfSingleRoute.Stops)
            {
                string stopName = stop.StopName.Zh_tw;
                IEnumerable <RoutePrediction> candidatePredictions = predictions.Where(prediction => string.Equals(stopName, prediction.StopName.Zh_tw));
                if (candidatePredictions.Count() != 1)
                {
                    continue;
                }
                RoutePrediction currentPrediction = candidatePredictions.First();
                PopulatePredictionViewByStop(stopName, currentPrediction, displayedPlateNumbers);
            }
        }
コード例 #6
0
        private Button CreateRouteArriveButton(RoutePrediction arriveRoute, IEnumerable <string> skipUID, List <string> processedRouteID)
        {
            string routeUID = arriveRoute.SubRouteUID;

            if (skipUID.Contains(routeUID))
            {
                return(null);
            }
            routeUID = routeUID.Replace(" ", "");
            Route route = RouteSQLiteRepository.Instance.Get(routeUID);

            if (!processedRouteID.Contains(route.Number))
            {
                processedRouteID.Add(route.Number);
                PageLayout.Children.Add(new Label {
                    Text = route.Number, FontSize = 20, TextColor = Color.Red
                });
            }
            return(CreateRouteArriveButton(arriveRoute, route, routeUID));
        }
コード例 #7
0
        public void TrainAndValidate()
        {
            var       clusterSizes = new int[] { 10, 100, 150, 200, 250, 300, 400, 500, 750, 1000, 2000 };
            CSVWriter csvWriter    = new CSVWriter(@"..\..\testdata\validations.csv", ";");

            Console.WriteLine("Writing validation results to validations.csv");

            foreach (var driver in drivers)
            {
                var currentTrips = trips.Where(t => t.DriverId.Equals(driver));

                for (int i = 1; i < currentTrips.Count() - 1; i++)
                {
                    List <TripSummary> trainingSet   = new List <TripSummary>();
                    List <TripSummary> validationSet = new List <TripSummary>();

                    int j = 0;
                    foreach (var trip in currentTrips)
                    {
                        if (j++ < i)
                        {
                            trainingSet.Add(trip);
                        }
                        else
                        {
                            validationSet.Add(trip);
                        }
                    }

                    foreach (var clusterSize in clusterSizes)
                    {
                        RoutePrediction routePrediction = new RoutePrediction(clusterSize);

                        RoutePredictionValidationResult result = routePrediction.TrainAndValidate(trainingSet, validationSet);
                        csvWriter.WriteRow(driver, clusterSize, trainingSet.Count(), validationSet.Count(), result.Validations);
                    }
                }
            }
            Console.WriteLine("done");
        }
コード例 #8
0
        private void PopulateArriveRoute(String stopID, String stopName)
        {
            PageLayout.Children.Add(new Label {
                Text = "即將到達路線"
            });
            IEnumerable <StopOnRoute> StopsOnSingleRoute = StopOnRouteSQLiteRepository.Instance.Retrieve(stopID);

            List <string> processedRouteUID = new List <string>();
            List <string> processedRouteID  = new List <string>();

            foreach (StopOnRoute StopOnSingleRoute in StopsOnSingleRoute)
            {
                IEnumerable <RoutePrediction> arriveRoutes = RoutePrediction.RetrieveFromJson(string.Format("http://ptx.transportdata.tw/MOTC/v2/Bus/EstimatedTimeOfArrival/InterCity?$filter=SubRouteUID%20eq%20%27{0}%27%20and%20StopName/Zh_tw%20eq%20%27{1}%27&$top=30&$format=JSON", StopOnSingleRoute.SubRouteUID, stopName));
                foreach (RoutePrediction arriveRoute in arriveRoutes)
                {
                    if (arriveRoute.PlateNumb != "-1")
                    {
                        Button routeDetails = CreateRouteArriveButton(arriveRoute, processedRouteUID, processedRouteID);
                        CheckArriveRoute = true;
                        if (routeDetails == null)
                        {
                            continue;
                        }
                        processedRouteUID.Add(arriveRoute.SubRouteUID);
                        PageLayout.Children.Add(routeDetails);
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            if (!CheckArriveRoute)
            {
                PageLayout.Children.Add(new Label {
                    Text = "本站無即將到達路線", FontSize = 20, TextColor = Color.Red, HorizontalOptions = LayoutOptions.CenterAndExpand
                });
            }
        }