public static List <string> GetScheduleHeader(GTFSFeed feed, string route, DirectionType?dir, TimepointStrategy strat) { IEnumerable <string> timepointList; if (strat == TimepointStrategy.SpecifiedTimepoints) { timepointList = TimepointFinder.DataTimepoints(feed, route, dir, true) .Select(x => x.Item1); } else if (strat == TimepointStrategy.NullTimepoints) { timepointList = TimepointFinder.DataTimepoints(feed, route, dir, true) .Select(x => x.Item1); } else { timepointList = TimepointFinder.FirstAndLastStopList(feed, route, dir); } var timepointsOrdered = from stops in StopLister.GetStopOrder(feed, route, dir) join timepoints in timepointList on stops.Id equals timepoints select stops.Id; return(timepointsOrdered.ToList()); }
public BlockPropertyCondition(PropertyType?property, DirectionType?direction, PrimitiveComparator comparator, Variable comparisonValue) { this.property = property; this.comparator = comparator; this.comparisonValue = comparisonValue; this.direction = direction; }
private void UpdateSample() { if (dirtySampleAnimation.HasValue && dirtySampleAnimation.Value == sampleAnimation && dirtySampleType.HasValue && dirtySampleType.Value == sampleDirection) { return; } dirtySampleAnimation = sampleAnimation; dirtySampleType = sampleDirection; switch (sampleAnimation) { case SampleAnimation.Idle: Play(idleAnimation2D, sampleDirection); break; case SampleAnimation.Move: Play(moveAnimation2D, sampleDirection); break; case SampleAnimation.Dead: Play(deadAnimation2D, sampleDirection); break; case SampleAnimation.DefaultAttack: Play(defaultAttackAnimation2D, sampleDirection); break; case SampleAnimation.DefaultSkillCast: Play(defaultSkillCastAnimation2D, sampleDirection); break; } }
private void DetermineNeighbours(IGame game, GridPoint point) { if (game.Grid[point] == BimaruValue.SHIP_MIDDLE) { DirectionType?shipDirection = GetShipMiddleDirection(game, point); if (shipDirection.HasValue) { SetShipMiddleNeighbours(game, point, shipDirection.Value); } } }
public static IEnumerable <string> LastStops(GTFSFeed feed, string route, DirectionType?dir) { return (from stopTimesUG in feed.StopTimes join trips in feed.Trips on stopTimesUG.TripId equals trips.Id where trips.RouteId == route && trips.Direction == dir orderby stopTimesUG.StopSequence group stopTimesUG by stopTimesUG.TripId into stopTimes select stopTimes.Last().StopId); }
/// <summary> /// The CSV item constructor. /// </summary> /// <param name="item">The CSV row item.</param> public Trip(CSVRowItem item) { mRouteID = item.ValidateNotEmptyOrNull("route_id"); mServiceID = item.ValidateNotEmptyOrNull("service_id"); mTripID = item.ValidateNotEmptyOrNull("trip_id"); mHeadSign = item["trip_headsign"]; mShortName = item["trip_short_name"]; mDirectionID = item["direction_id"].ToDirectionType(); mBlockID = item["block_id"]; mShapeID = item["shape_id"]; }
private void UpdatePendingDirection() { if (m_pendingDirection.HasValue) { return; } var direction = GetCurrentDirection(); if (!direction.HasValue) { return; } m_pendingDirection = direction.Value; }
/// <summary> /// Writes a direction type. /// </summary> /// <param name="name"></param> /// <param name="fieldName"></param> /// <param name="value"></param> /// <returns></returns> private string WriteFieldDirectionType(string name, string fieldName, DirectionType?value) { if (value.HasValue) { //0 - travel in one direction (e.g. outbound travel) //1 - travel in the opposite direction (e.g. inbound travel) switch (value.Value) { case DirectionType.OneDirection: return("0"); case DirectionType.OppositeDirection: return("1"); } } return(string.Empty); }
/// <summary> /// This is the struct constructor. /// </summary> /// <param name="ID"></param> /// <param name="RouteID"></param> /// <param name="ServiceID"></param> /// <param name="HeadSign"></param> /// <param name="ShortName"></param> /// <param name="DirectionID"></param> /// <param name="BlockID"></param> /// <param name="ShapeID"></param> public Trip( string TripID, string RouteID, string ServiceID, string HeadSign, string ShortName, DirectionType?DirectionID, string BlockID, string ShapeID ) { mTripID = TripID; mRouteID = RouteID; mServiceID = ServiceID; mHeadSign = HeadSign; mShortName = ShortName; mDirectionID = DirectionID; mBlockID = BlockID; mShapeID = ShapeID; }
private DirectionInfo GetDirectionInfo() { var directionInfo = new DirectionInfo(); DirectionType?lastDirection = null; var lastDirectionSize = 0; for (var i = 0; i < SequencedBaseDirectionMap.Length; i++) { var direction = SequencedBaseDirectionMap[i]; if (!lastDirection.HasValue) // first time, just set it { lastDirection = direction; lastDirectionSize++; } else { if (direction == lastDirection) { lastDirectionSize++; } else { directionInfo.Directions.Add(new DirectionOp() { Direction = lastDirection.Value, Length = lastDirectionSize }); lastDirection = direction; lastDirectionSize = 1; } } } directionInfo.Directions.Add(new DirectionOp() { Direction = lastDirection.Value, Length = lastDirectionSize }); return(directionInfo); }
public void TurnRight() { switch (Direction) { case DirectionType.EAST: Direction = DirectionType.SOUTH; break; case DirectionType.WEST: Direction = DirectionType.NORTH; break; case DirectionType.NORTH: Direction = DirectionType.EAST; break; case DirectionType.SOUTH: Direction = DirectionType.WEST; break; } }
private void ExecuteTest(AlleleCategory variantType, DirectionType?expectedDirection, ReadCoverageSummary readSummary, int variantPosition = 10) { var calculator = new ExactCoverageCalculator(); var allele = new CalledAllele(variantType) { Coordinate = variantPosition }; switch (allele.Type) { case AlleleCategory.Insertion: allele.Reference = "A"; allele.Alternate = "ATTTT"; break; case AlleleCategory.Deletion: allele.Alternate = "A"; allele.Reference = "ATTTT"; break; default: allele.Reference = "AAAA"; allele.Alternate = "TTTT"; break; } var source = new Mock <IAlleleSource>(); source.Setup(s => s.GetSpanningReadSummaries(It.IsAny <int>(), It.IsAny <int>())) .Returns(new List <ReadCoverageSummary> { readSummary }); calculator.Compute(allele, source.Object); for (var i = 0; i < allele.EstimatedCoverageByDirection.Length; i++) { Assert.Equal(expectedDirection.HasValue && i == (int)expectedDirection ? 1 : 0, allele.EstimatedCoverageByDirection[i]); } }
public static IEnumerable <Tuple <string, bool> > DataTimepoints(GTFSFeed feed, string route, DirectionType?dir, bool strict = false) { var routeStopTimes = from stopTimes in feed.StopTimes join trips in feed.Trips on stopTimes.TripId equals trips.Id where trips.RouteId == route && trips.Direction == dir select stopTimes; return (from stopTimesUngrouped in routeStopTimes group stopTimesUngrouped by stopTimesUngrouped.StopId into stopTimes where stopTimes.Any(x => x.TimepointType == TimePointType.Exact || (!strict && x.TimepointType == TimePointType.None && x.ArrivalTime != null)) select new Tuple <string, bool>( stopTimes.First().StopId, stopTimes.All(x => x.TimepointType == TimePointType.Exact || (!strict && x.TimepointType == TimePointType.None && x.ArrivalTime != null)) )); }
/// <summary> /// This is the struct constructor. /// </summary> /// <param name="ID"></param> /// <param name="RouteID"></param> /// <param name="ServiceID"></param> /// <param name="HeadSign"></param> /// <param name="ShortName"></param> /// <param name="DirectionID"></param> /// <param name="BlockID"></param> /// <param name="ShapeID"></param> public Trip( string TripID, string RouteID, string ServiceID, string HeadSign, string ShortName, DirectionType? DirectionID, string BlockID, string ShapeID ) { mTripID = TripID; mRouteID= RouteID; mServiceID= ServiceID; mHeadSign = HeadSign; mShortName = ShortName; mDirectionID = DirectionID; mBlockID= BlockID; mShapeID= ShapeID; }
public static Tuple <List <string>, List <Tuple <string, Dictionary <string, TimeOfDay> > > > GetSchedule(GTFSFeed feed, string route, DirectionType?dir, string serviceId, List <string> stopOrder, Dictionary <string, int> sortTimes) { var filteredTrips = from trips in feed.Trips where trips.RouteId == route && trips.Direction == dir && trips.ServiceId == serviceId select trips.Id; List <Tuple <string, Dictionary <string, TimeOfDay>, int> > tripSchedules = new List <Tuple <string, Dictionary <string, TimeOfDay>, int> >(); foreach (string tripId in filteredTrips) { var tripTimes = (from times in feed.StopTimes where times.TripId == tripId && stopOrder.Contains(times.StopId) group times by new { times.TripId, times.StopId } into times2 select new { times2.First().StopId, times2.First().DepartureTime }).ToDictionary(x => x.StopId, x => x.DepartureTime.Value); int sortTime = 0; foreach (string stopId in stopOrder) { if (tripTimes.ContainsKey(stopId)) { sortTime = tripTimes[stopId].TotalSeconds - sortTimes[stopId]; break; } } tripSchedules.Add(new Tuple <string, Dictionary <string, TimeOfDay>, int>(tripId, tripTimes, sortTime)); } List <Tuple <string, Dictionary <string, TimeOfDay> > > allTrips = (from tripScheds in tripSchedules orderby tripScheds.Item3 select new Tuple <string, Dictionary <string, TimeOfDay> >(tripScheds.Item1, tripScheds.Item2)).ToList(); return(new Tuple <List <string>, List <Tuple <string, Dictionary <string, TimeOfDay> > > >(stopOrder, allTrips)); }
public static Dictionary <string, int> GetSortTimes(GTFSFeed feed, string route, DirectionType?dir, List <string> timepoints) { Dictionary <string, int> times = new Dictionary <string, int>(); times[timepoints[0]] = 0; List <string> checkedTimes = new List <string>(); bool failedLoop = true; while (times.Count < timepoints.Count) { foreach (string stopFrom in timepoints.Intersect(times.Keys).Except(checkedTimes)) { failedLoop = false; foreach (string stopTo in timepoints.Except(times.Keys)) { var differences = from stopTimesUG in feed.StopTimes join trips in feed.Trips on stopTimesUG.TripId equals trips.Id where trips.RouteId == route && trips.Direction == dir group stopTimesUG by stopTimesUG.TripId into stopTimes where stopTimes.Any(x => x.StopId == stopFrom) && stopTimes.Any(x => x.StopId == stopTo) select stopTimes.Where(x => x.StopId == stopTo).First().ArrivalTime.Value.TotalSeconds - stopTimes.Where(x => x.StopId == stopFrom).First().ArrivalTime.Value.TotalSeconds; if (differences.Any()) { times[stopTo] = (int)differences.Average() + times[stopFrom]; } } checkedTimes.Add(stopFrom); } if (failedLoop) { times[timepoints.Except(checkedTimes).First()] = 0; } } return(times); }
public static IEnumerable <Tuple <string, bool> > DataTimepoints(GTFSFeed feed, Route route, DirectionType?dir, bool strict = false) => DataTimepoints(feed, route.Id, dir, strict);
public static Tuple <List <string>, List <Tuple <string, Dictionary <string, TimeOfDay> > > > GetSchedule(GTFSFeed feed, string route, DirectionType?dir, string serviceId, TimepointStrategy strat) { var stops = GetScheduleHeader(feed, route, dir, strat); var times = GetSortTimes(feed, route, dir, stops); return(GetSchedule(feed, route, dir, serviceId, stops, times)); }
/// <summary> /// Lists the stops along a route, in order. /// </summary> /// <param name="feed">The GTFS feed to use.</param> /// <param name="route">The ID of the route to get stops for.</param> /// <param name="direction"> /// The direction of trips to get. Must exactly match the direction /// provided in GTFS; <c>null</c> here does not match "any direction" /// in the data. /// </param> public static IEnumerable <Stop> GetStopOrder(GTFSFeed feed, string route, DirectionType?direction = null) { var routeStopTimes = from stopTimes in feed.StopTimes join trips in feed.Trips on stopTimes.TripId equals trips.Id where trips.RouteId == route && trips.Direction == direction select stopTimes; // If it's empty, return empty list. Though that shouldn't be possible in well-formed GTFS. if (routeStopTimes.Count() == 0) { return(Enumerable.Empty <Stop>()); } // First, we'll need a listing of every trip, how many stops it has, and how many of those we've already listed. var stopsOnTrips = from rstListingUngrouped in routeStopTimes group rstListingUngrouped by rstListingUngrouped.TripId into rstListingGrouped let stopCount = rstListingGrouped.Count() orderby stopCount descending select new { rstListingGrouped.First().TripId, Stops = stopCount, FoundStops = 0 }; List <string> outStops = new List <string>(); while (stopsOnTrips.Count() > 0) { // First take the first trip with "unlisted" stops string newTrip = stopsOnTrips.First().TripId; var newStops = (from rstListing in routeStopTimes where rstListing.TripId == newTrip orderby rstListing.StopSequence select rstListing.StopId).Distinct(); // Handling for first trip searched if (outStops.Count == 0) { outStops = newStops.Distinct().ToList(); } else { // Now merge the listings List <string> foundStops = new List <string>(outStops); List <string> addingStops = new List <string>(); string lastFoundStop = null; foreach (string stop in newStops) { int foundIndex = foundStops.IndexOf(stop); if (foundIndex != -1) { // Remove the found stop and all preceding stops from the found-stops list foundStops.RemoveRange(0, foundIndex + 1); // If there were unfound stops, add them to the output too if (addingStops.Count > 0) { int outIndex = outStops.IndexOf(stop); outStops.InsertRange(outIndex, addingStops); addingStops.Clear(); } // Also, set the last found stop to this one lastFoundStop = stop; } else { addingStops.Add(stop); } } // Add stray stops just after the last found stop if (lastFoundStop != null) { outStops.InsertRange(outStops.IndexOf(lastFoundStop) + 1, addingStops); } else { // Or on the end if the two segments are, somehow, not linked outStops.AddRange(addingStops); } // Make sure outStops only contains items once outStops = outStops.Distinct().ToList(); } // Now we need to update stopsOnTrips stopsOnTrips = from rstListingUngrouped in routeStopTimes group rstListingUngrouped by rstListingUngrouped.TripId into rstListingGrouped let stopCount = rstListingGrouped.Count() let foundStopCount = rstListingGrouped.Count(x => outStops.Contains(x.StopId)) where foundStopCount < stopCount orderby Math.Sign(stopCount) descending, stopCount - foundStopCount descending, stopCount select new { rstListingGrouped.First().TripId, Stops = rstListingGrouped.Count(), FoundStops = rstListingGrouped.Count(x => outStops.Contains(x.StopId)) }; } return (from stops in outStops join feedStops in feed.Stops on stops equals feedStops.Id select feedStops); }
public static string GetStringValue(DirectionType?dirn) => dirn.HasValue ? GetStringValue(dirn.Value) : "";
public static IEnumerable <string> FirstAndLastStopList(GTFSFeed feed, Route route, DirectionType?dir) => FirstAndLastStopList(feed, route.Id, dir);
public void TestGetStringValueNullableNull() { DirectionType?dirn = null; DirectionConverter.GetStringValue(dirn).Should().Be(""); }
public static IEnumerable <string> LastStops(GTFSFeed feed, Route route, DirectionType?dir) => LastStops(feed, route.Id, dir);
public void Convert_DirectionInput_ReturnsCorrectDirectionType(char directionInput, DirectionType?expectedDirectionType) { DirectionType?directionType = Direction.ParseInputToDirectionType(directionInput); Assert.Equal(expectedDirectionType, directionType); }
public void Place(int x, int y, DirectionType direction) { X = x; Y = y; Direction = direction; }
public static List <string> GetScheduleHeader(GTFSFeed feed, string route, DirectionType?dir) => GetScheduleHeader(feed, route, dir, TimepointFinder.GetTimepointStrategy(feed));
/// <summary> /// Lists the stops along a route, in order. /// </summary> /// <param name="feed">The GTFS feed to use.</param> /// <param name="route">The Route to get stops for.</param> /// <param name="direction"> /// The direction of trips to get. Must exactly match the direction /// provided in GTFS; <c>null</c> here does not match "any direction" /// in the data. /// </param> public static IEnumerable <Stop> GetStopOrder(GTFSFeed feed, Route route, DirectionType?direction = null) => GetStopOrder(feed, route.Id, direction);
private void ResetDetectors() { m_topDetectorTripped = false; m_bottomDetectorTripped = false; m_pendingDirection = null; }
public static Tuple <List <string>, List <Tuple <string, Dictionary <string, TimeOfDay> > > > GetSchedule(GTFSFeed feed, string route, DirectionType?dir, string serviceId) => GetSchedule(feed, route, dir, serviceId, TimepointFinder.GetTimepointStrategy(feed));
public void TestGetStringValueNullableValue() { DirectionType?dirn = DirectionType.Rtl; DirectionConverter.GetStringValue(dirn).Should().Be("rtl"); }
public static IEnumerable <string> FirstAndLastStopList(GTFSFeed feed, string route, DirectionType?dir) { List <string> ret = new List <string>(); foreach (Tuple <string, string> pair in FirstAndLastStopPairs(feed, route, dir)) { ret.Add(pair.Item1); ret.Add(pair.Item2); } return(ret.Distinct()); }