public static bool IsAtMSC(VehicleState state) { Coordinate mscCircleLocation = new Coordinate(28.064380, -82.413931); //the (rough) location of the center of the MSC circle double maxDistance = 22; //the max distance from the center of the MSC circle buses can be in order to be considered "at" the msc SyncromaticsVehicle report = state.GetLatestVehicleReport(); Coordinate vehicleLocation = new Coordinate(report.Latitude, report.Longitude); return(vehicleLocation.DistanceTo(mscCircleLocation) <= maxDistance); }
internal void TriggerNewVehicleDownloaded(SyncromaticsRoute route, SyncromaticsVehicle vehicle, int i) { if (NewVehicleDownloaded != null) { index = i; NewVehicleDownloaded.Invoke(this, new VehicleDownloadedArgs() { Route = route, Vehicle = vehicle }); } }
public async Task <long> MakePrediction(Route route, SyncromaticsVehicle vehicle, VehicleState vehicleState) { //if there is sufficent historical data, use kalman //Stop currentStop = Spatial.StopResolver.GetCurrentStop(route, vehicle); //if (currentStop == null) return -1; //TODO: Partial path finding //long kalmanResult = await Kalman(route, vehicleState, currentStop, route.GetStopByIndex(vehicleState.StopIndex + 1)); //return kalmanResult; return(0); }
public VehicleState(SyncromaticsVehicle vehicleReport) { VehicleReports = new List <SyncromaticsVehicle>(); VehicleReports.Add(vehicleReport); BusNumber = int.Parse(vehicleReport.Name); Capacity = vehicleReport.APCPercentage; RouteID = vehicleReport.RouteID; ID = vehicleReport.ID; StopIndex = 0; TripIndex = 0; }
/// <summary> /// /// </summary> /// <param name="vehicle"></param> /// <returns></returns> private async Task HandleExistingVehicle(SyncromaticsVehicle vehicle) { VehicleState state = VehicleStates[vehicle.ID]; if (state.GetLatestVehicleReport().Updated.Equals(vehicle.Updated)) { return; //we aren't interested in reports that haven't been updated } if (state.GetLatestVehicleReport().RouteID != vehicle.RouteID) { //if a vehicle changes routes, remove its state and restart Console.WriteLine("route not the same"); VehicleState removedState; VehicleStates.Remove(vehicle.ID, out removedState); return; } state.AddVehicleReport(vehicle); Route route = Routes[vehicle.RouteID]; state.CurrentStopPath = SpatialMatcher.PolygonMatch(state, route); if (state.CurrentStopPath == null) { Console.WriteLine("Cannot match to stop path!"); state.OnRoute = false; failedMatches++; } /* * else if (state.CurrentStopPath != null) * { * state.OnRoute = true; * * double headway = HeadwayGenerator.CalculateHeadwayDifference(VehicleStates.Values.ToList(), route, vehicle.ID); * bool isOnBreak = BreakGenerator.IsOnBreak(state, route); * } */ await AVLProcessing.GetWebsockets().SendVehicleUpdateAsync(new WebSockets.WSVehicleUpdateMsg(state, state.CurrentStopPath, route)); }
/// <summary> /// /// </summary> /// <param name="vehicle"></param> /// <returns></returns> private void HandleNewVehicle(SyncromaticsVehicle vehicle) { Console.WriteLine("new vehicle " + vehicle.Name); VehicleState state = new VehicleState(vehicle); Route route = Routes[vehicle.RouteID]; /* * TripHistory history = new TripHistory(); * history.RouteID = vehicle.RouteID; * history.TimeLeftOrigin = DateTime.UnixEpoch; * InProgressHistories.Add(vehicle.ID, history); */ bool reslt = VehicleStates.TryAdd(vehicle.ID, state); if (!reslt) { Console.WriteLine("Not added!!!!!!"); } //we have not seen this vehicle before. let's check where it is //StopPath stopPath = SpatialMatcher.GetStopPath(route, state); }
public static StopPath GetStopPath(Route route, VehicleState state) { SyncromaticsVehicle report = state.GetLatestVehicleReport(); Coordinate vehicleLocation = new Coordinate(report.Latitude, report.Longitude); double minimum = Double.MaxValue; double superMinimum = 100;//furthest distance in meters that a coordinate should be away from the vehicle to be located. StopPath selectedPath = null; List <StopPath> paths = route.StopPaths.ToList(); for (int i = 0; i < paths.Count; i++) { StopPath x = paths[i]; for (int j = 0; j < x.Path.Count - 1; j += 2) { Coordinate firstCoord = new Coordinate(x.Path[j].Latitude, x.Path[j].Longitude); Coordinate secondCoord = new Coordinate(x.Path[j + 1].Latitude, x.Path[j + 1].Longitude); double bearing = firstCoord.GetBearingTo(secondCoord); string direction = Coordinate.DegreesToCardinal(bearing); if (direction.Equals(report.Heading)) { if (secondCoord.DistanceTo(vehicleLocation) < minimum) { minimum = secondCoord.DistanceTo(vehicleLocation); selectedPath = x; } if (firstCoord.DistanceTo(vehicleLocation) < minimum) { minimum = firstCoord.DistanceTo(vehicleLocation); selectedPath = x; } } } } bool valid = false; double min = Double.MaxValue; if (selectedPath != null) { foreach (Coordinate path in selectedPath.Path) { double distance = vehicleLocation.DistanceTo(path); if (distance <= superMinimum) { valid = true; } if (distance < min) { min = distance; } } if (!valid) { Console.WriteLine($"No valid path was found for vehicle {state.ID}, smallest value was {min}"); } } if (valid) { return(selectedPath); } else { return(null); } }
public void AddVehicleReport(SyncromaticsVehicle vehicle) { VehicleReports.Add(vehicle); }