예제 #1
0
        // return "arr" or "x min" of bus reaching next stop
        // to show on bus on road
        public static string GetArrivalTiming(string vehiclePlate)
        {
            BusOnRoad bor         = ActiveBuses [vehiclePlate];
            BusSvc    svc         = BusSvcs [bor.routeName];
            string    busStopCode = (string)bor.nextStopEnumerator.Current;

            // get diff of distance travelled by bus and distance between stops for the service
            var diffDist = svc.distanceBetweenStops [bor.stopCounter] - bor.distanceTravelled;
            var time     = (int)((diffDist / bor.avgSpeed) / 60);         // in min

            // if arrived bus stop
            if (diffDist < MARGIN_OF_ERROR &&
                ((string)bor.nextStopEnumerator.Current).Equals(busStopCode))
            {
                // shift next stop indicator
                // if no more stop, finish service
                // else, keep counting
                if (!bor.nextStopEnumerator.MoveNext())
                {
                    bor.finished = true;
                }
                else
                {
                    bor.stopCounter++;
                }
            }

            // generate display string (give +- 1 allowance)
            return((time == 0 || time == -1) ? "Arr" : ((time > 60 || time < -1) ? "--" : time + " min"));
        }
예제 #2
0
        // add bus when bus starts to ply on road
        public static void AddBusOnRoad(string vehiclePlate, string routeName)
        {
            var svc      = BusSvcs[routeName];
            var stopEnum = svc.stops.GetEnumerator();

            // start from the second bus stop for next stop
            if (!stopEnum.MoveNext())
            {
                return;
            }
            stopEnum.MoveNext();

            // construct bor object
            var bor = new BusOnRoad {
                vehiclePlate       = vehiclePlate,
                routeName          = routeName,
                firstStop          = svc.firstStop,
                lastStop           = svc.lastStop,
                loopStop           = svc.loopStop,
                stopCounter        = 0,
                nextStopEnumerator = stopEnum,
                // take firstStop position as initial bus position
                latitude          = BusStops[svc.firstStop].latitude,
                longitude         = BusStops[svc.firstStop].longitude,
                avgSpeed          = 5.0,
                currSpeed         = 5.0,
                distanceTravelled = 0.0,
                finished          = false
            };

            ActiveBuses.Add(vehiclePlate, bor);

            // start/restart timer dispatch
            StartTimerDispatch(svc);
        }
예제 #3
0
        public static void GoToNextCheckpoint(BusOnRoad bor)
        {
            var svc = BusHelper.BusSvcs [bor.routeName];

            if (bor.nextCheckpointEnumerator == null)
            {
                bor.nextCheckpointEnumerator = svc.checkpoints.GetEnumerator();
            }

            double longitude = BusHelper.BusStops [svc.firstStop].longitude;
            double latitude  = BusHelper.BusStops [svc.firstStop].latitude;

            // update position based on checkpoint
            if (bor.nextCheckpointEnumerator.MoveNext())
            {
                longitude = (double)bor.nextCheckpointEnumerator.Current;
            }
            else
            {
                BusHelper.RemoveBusOnRoad(bor.vehiclePlate);
                return;
            }
            if (bor.nextCheckpointEnumerator.MoveNext())
            {
                latitude = (double)bor.nextCheckpointEnumerator.Current;
            }

            bor.longitude = longitude;
            bor.latitude  = latitude;
        }
예제 #4
0
        // TODO: helper methods to extract specific bus data

        // add bus when bus starts to ply on road
        public static void AddBusOnRoad(string vehiclePlate, string routeName)
        {
            var svc      = BusSvcs[routeName];
            var stopEnum = svc.stops.GetEnumerator();

            stopEnum.MoveNext();

            var bus = new BusOnRoad {
                vehiclePlate       = vehiclePlate,
                routeName          = routeName,
                firstStop          = svc.firstStop,
                lastStop           = svc.lastStop,
                nextStopEnumerator = stopEnum,
                // take firstStop position as initial bus position
                latitude  = BusStops[svc.firstStop].latitude,
                longitude = BusStops[svc.firstStop].longitude,
                speed     = 5.0
            };

            ActiveBuses.Add(vehiclePlate, bus);
        }
예제 #5
0
        // simulate bus moving along the route (via checkpoints on route)
        public static void GoToNextCheckpoint(BusOnRoad bor)
        {
            // init if needed
            BusSvc svc = BusHelper.BusSvcs [bor.routeName];

            if (bor.nextCheckpointEnumerator == null)
            {
                bor.nextCheckpointEnumerator = svc.checkpoints.GetEnumerator();
            }
            else if (bor.nextDistanceEnumerator == null)
            {
                bor.nextDistanceEnumerator = svc.distanceBetweenCheckpoints.GetEnumerator();
            }

            // default position at first stop
            double longitude = BusHelper.BusStops [svc.firstStop].longitude;
            double latitude  = BusHelper.BusStops [svc.firstStop].latitude;

            // update position and distance based on checkpoint
            if (bor.nextCheckpointEnumerator.MoveNext())
            {
                longitude = (double)bor.nextCheckpointEnumerator.Current;
            }
            if (bor.nextCheckpointEnumerator.MoveNext())
            {
                latitude = (double)bor.nextCheckpointEnumerator.Current;
            }
            if (bor.nextDistanceEnumerator != null && bor.nextDistanceEnumerator.MoveNext())
            {
                bor.distanceTravelled += (double)bor.nextDistanceEnumerator.Current;
            }

            // update bus position
            bor.longitude = longitude;
            bor.latitude  = latitude;
        }