From a304c24b32c0327436bbd8c2853e60668e161b42 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Mon, 29 Dec 2025 00:41:52 +0100 Subject: Rename a lot of stuff, add Santiago real time --- .../Queries/ArrivalsAtStop.cs | 217 ------------------ .../Queries/PlanConnectionContent.cs | 245 --------------------- .../Queries/RouteDetailsContent.cs | 112 ---------- .../Queries/RoutesListContent.cs | 66 ------ .../Queries/StopTile.cs | 76 ------- .../Queries/StopsInfo.cs | 57 ----- 6 files changed, 773 deletions(-) delete mode 100644 src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/ArrivalsAtStop.cs delete mode 100644 src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/PlanConnectionContent.cs delete mode 100644 src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RouteDetailsContent.cs delete mode 100644 src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RoutesListContent.cs delete mode 100644 src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/StopTile.cs delete mode 100644 src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/StopsInfo.cs (limited to 'src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries') diff --git a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/ArrivalsAtStop.cs b/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/ArrivalsAtStop.cs deleted file mode 100644 index bce35a2..0000000 --- a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/ArrivalsAtStop.cs +++ /dev/null @@ -1,217 +0,0 @@ -using System.Globalization; -using System.Text.Json.Serialization; -using Costasdev.Busurbano.Sources.OpenTripPlannerGql; - -namespace Costasdev.Busurbano.Sources.OpenTripPlannerGql.Queries; - -public class ArrivalsAtStopContent : IGraphRequest -{ - public record Args(string Id, bool Reduced); - - public static string Query(Args args) - { - var startTime = DateTimeOffset.UtcNow.AddMinutes(-75); - var startTimeUnix = startTime.ToUnixTimeSeconds(); - var geometryField = args.Reduced ? "" : @"tripGeometry { points }"; - - return string.Create(CultureInfo.InvariantCulture, $@" - query Query {{ - stop(id:""{args.Id}"") {{ - code - name - lat - lon - routes {{ - gtfsId - shortName - color - textColor - }} - arrivals: stoptimesWithoutPatterns(numberOfDepartures: 100, startTime: {startTimeUnix}, timeRange: 14400) {{ - headsign - scheduledDeparture - serviceDay - pickupType - - trip {{ - gtfsId - serviceId - routeShortName - route {{ - gtfsId - color - textColor - longName - }} - departureStoptime {{ - scheduledDeparture - }} - arrivalStoptime {{ - stop {{ - gtfsId - }} - }} - {geometryField} - stoptimes {{ - stop {{ - name - lat - lon - }} - scheduledDeparture - }} - }} - }} - }} - }} - "); - } -} - -public class ArrivalsAtStopResponse : AbstractGraphResponse -{ - [JsonPropertyName("stop")] public required StopItem Stop { get; set; } - - public class StopItem - { - [JsonPropertyName("code")] public required string Code { get; set; } - - [JsonPropertyName("name")] public required string Name { get; set; } - - [JsonPropertyName("lat")] public double Lat { get; set; } - - [JsonPropertyName("lon")] public double Lon { get; set; } - - [JsonPropertyName("routes")] public List Routes { get; set; } = []; - - [JsonPropertyName("arrivals")] public List Arrivals { get; set; } = []; - } - - public class Arrival - { - [JsonPropertyName("headsign")] public required string Headsign { get; set; } - - [JsonPropertyName("scheduledDeparture")] - public int ScheduledDepartureSeconds { get; set; } - - [JsonPropertyName("serviceDay")] - public long ServiceDay { get; set; } - - [JsonPropertyName("pickupType")] public required string PickupTypeOriginal { get; set; } - - public PickupType PickupTypeParsed => PickupType.Parse(PickupTypeOriginal); - - [JsonPropertyName("trip")] public required TripDetails Trip { get; set; } - } - - public class TripDetails - { - [JsonPropertyName("gtfsId")] public required string GtfsId { get; set; } - - [JsonPropertyName("serviceId")] public required string ServiceId { get; set; } - - [JsonPropertyName("routeShortName")] public required string RouteShortName { get; set; } - - [JsonPropertyName("departureStoptime")] - public required DepartureStoptime DepartureStoptime { get; set; } - - [JsonPropertyName("arrivalStoptime")] - public required ArrivalStoptime ArrivalStoptime { get; set; } - - [JsonPropertyName("route")] public required RouteDetails Route { get; set; } - - [JsonPropertyName("tripGeometry")] public GeometryDetails? Geometry { get; set; } - - [JsonPropertyName("stoptimes")] public List Stoptimes { get; set; } = []; - } - - public class GeometryDetails - { - [JsonPropertyName("points")] public string? Points { get; set; } - } - - public class StoptimeDetails - { - [JsonPropertyName("stop")] public required StopDetails Stop { get; set; } - [JsonPropertyName("scheduledDeparture")] public int ScheduledDeparture { get; set; } - } - - public class StopDetails - { - [JsonPropertyName("name")] public required string Name { get; set; } - [JsonPropertyName("lat")] public double Lat { get; set; } - [JsonPropertyName("lon")] public double Lon { get; set; } - } - - public class DepartureStoptime - { - [JsonPropertyName("scheduledDeparture")] - public int ScheduledDeparture { get; set; } - } - - public class ArrivalStoptime - { - [JsonPropertyName("stop")] public ArrivalStoptimeStop Stop { get; set; } - } - - public class ArrivalStoptimeStop - { - [JsonPropertyName("gtfsId")] public required string GtfsId { get; set; } - } - - public class RouteDetails - { - [JsonPropertyName("gtfsId")] public required string GtfsId { get; set; } - public string GtfsIdValue => GtfsId.Split(':', 2)[1]; - - [JsonPropertyName("shortName")] public string? ShortName { get; set; } - - [JsonPropertyName("color")] public string? Color { get; set; } - - [JsonPropertyName("textColor")] public string? TextColor { get; set; } - - [JsonPropertyName("longName")] public string? LongName { get; set; } - } - - public class PickupType - { - private readonly string _value; - - private PickupType(string value) - { - _value = value; - } - - public static PickupType Parse(string value) - { - return value switch - { - "SCHEDULED" => Scheduled, - "NONE" => None, - "CALL_AGENCY" => CallAgency, - "COORDINATE_WITH_DRIVER" => CoordinateWithDriver, - _ => throw new ArgumentException("Unsupported pickup type ", value) - }; - } - - public static readonly PickupType Scheduled = new PickupType("SCHEDULED"); - public static readonly PickupType None = new PickupType("NONE"); - public static readonly PickupType CallAgency = new PickupType("CALL_AGENCY"); - public static readonly PickupType CoordinateWithDriver = new PickupType("COORDINATE_WITH_DRIVER"); - - public override bool Equals(object? other) - { - if (other is not PickupType otherPt) - { - return false; - } - - return otherPt._value == _value; - } - - public override int GetHashCode() - { - return _value.GetHashCode(); - } - } -} diff --git a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/PlanConnectionContent.cs b/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/PlanConnectionContent.cs deleted file mode 100644 index db3de49..0000000 --- a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/PlanConnectionContent.cs +++ /dev/null @@ -1,245 +0,0 @@ -using System.Globalization; -using System.Text.Json.Serialization; - -namespace Costasdev.Busurbano.Sources.OpenTripPlannerGql.Queries; - -#pragma warning disable CS8618 - -public class PlanConnectionContent : IGraphRequest -{ - public record Args( - double StartLatitude, - double StartLongitude, - double EndLatitude, - double EndLongitude, - DateTimeOffset ReferenceTime, - bool ReferenceIsArrival = false - ); - - public static string Query(Args args) - { - var madridTz = TimeZoneInfo.FindSystemTimeZoneById("Europe/Madrid"); - - // Treat incoming DateTime as Madrid local wall-clock time - var localMadridTime = - DateTime.SpecifyKind(args.ReferenceTime.UtcDateTime, DateTimeKind.Unspecified); - - var offset = madridTz.GetUtcOffset(localMadridTime); - - var dateTimeToUse = new DateTimeOffset(args.ReferenceTime.DateTime + offset, offset); - - var dateTimeParameter = args.ReferenceIsArrival ? $"latestArrival:\"{dateTimeToUse:O}\"" : $"earliestDeparture:\"{dateTimeToUse:O}\""; - - return string.Create(CultureInfo.InvariantCulture, - $$""" - query Query { - planConnection( - first: 4 - origin: { - location:{ - coordinate:{ - latitude:{{args.StartLatitude}} - longitude:{{args.StartLongitude}} - } - } - } - destination:{ - location:{ - coordinate:{ - latitude:{{args.EndLatitude}} - longitude:{{args.EndLongitude}} - } - } - } - dateTime:{ - {{dateTimeParameter}} - } - searchWindow:"PT5H" - ) { - edges { - node { - duration - start - end - walkTime - walkDistance - waitingTime - legs { - start { - scheduledTime - } - end { - scheduledTime - } - mode - route { - gtfsId - shortName - longName - agency { - name - } - color - textColor - } - from { - name - lat - lon - stop { - gtfsId - code - name - lat - lon - zoneId - } - } - to { - name - lat - lon - stop { - gtfsId - code - name - lat - lon - zoneId - } - } - stopCalls { - stopLocation { - ... on Stop { - gtfsId - code - name - lat - lon - } - } - } - legGeometry { - points - } - steps { - distance - relativeDirection - streetName - absoluteDirection - lat - lon - } - headsign - distance - } - } - } - } - } - """); - } -} - -public class PlanConnectionResponse : AbstractGraphResponse -{ - public PlanConnectionItem PlanConnection { get; set; } - - public class PlanConnectionItem - { - [JsonPropertyName("edges")] - public Edge[] Edges { get; set; } - } - - public class Edge - { - [JsonPropertyName("node")] - public Node Node { get; set; } - } - - public class Node - { - [JsonPropertyName("duration")] public int DurationSeconds { get; set; } - [JsonPropertyName("start")] public string Start8601 { get; set; } - [JsonPropertyName("end")] public string End8601 { get; set; } - [JsonPropertyName("walkTime")] public int WalkSeconds { get; set; } - [JsonPropertyName("walkDistance")] public double WalkDistance { get; set; } - [JsonPropertyName("waitingTime")] public int WaitingSeconds { get; set; } - [JsonPropertyName("legs")] public Leg[] Legs { get; set; } - } - - public class Leg - { - [JsonPropertyName("start")] public ScheduledTimeContainer Start { get; set; } - [JsonPropertyName("end")] public ScheduledTimeContainer End { get; set; } - [JsonPropertyName("mode")] public string Mode { get; set; } // TODO: Make enum, maybe - [JsonPropertyName("route")] public TransitRoute? Route { get; set; } - [JsonPropertyName("from")] public LegPosition From { get; set; } - [JsonPropertyName("to")] public LegPosition To { get; set; } - [JsonPropertyName("stopCalls")] public StopCall[] StopCalls { get; set; } - [JsonPropertyName("legGeometry")] public LegGeometry LegGeometry { get; set; } - [JsonPropertyName("steps")] public Step[] Steps { get; set; } - [JsonPropertyName("headsign")] public string? Headsign { get; set; } - [JsonPropertyName("distance")] public double Distance { get; set; } - } - - public class TransitRoute - { - [JsonPropertyName("gtfsId")] public string GtfsId { get; set; } - [JsonPropertyName("shortName")] public string ShortName { get; set; } - [JsonPropertyName("longName")] public string LongName { get; set; } - [JsonPropertyName("agency")] public AgencyNameContainer Agency { get; set; } - [JsonPropertyName("color")] public string Color { get; set; } - [JsonPropertyName("textColor")] public string TextColor { get; set; } - } - - public class LegPosition - { - [JsonPropertyName("name")] public string Name { get; set; } - [JsonPropertyName("lat")] public double Latitude { get; set; } - [JsonPropertyName("lon")] public double Longitude { get; set; } - [JsonPropertyName("stop")] public StopLocation Stop { get; set; } - } - - public class ScheduledTimeContainer - { - [JsonPropertyName("scheduledTime")] - public string ScheduledTime8601 { get; set; } - } - - public class AgencyNameContainer - { - [JsonPropertyName("name")] public string Name { get; set; } - } - - public class StopCall - { - [JsonPropertyName("stopLocation")] - public StopLocation StopLocation { get; set; } - } - - public class StopLocation - { - [JsonPropertyName("gtfsId")] public string GtfsId { get; set; } - [JsonPropertyName("code")] public string Code { get; set; } - [JsonPropertyName("name")] public string Name { get; set; } - [JsonPropertyName("lat")] public double Latitude { get; set; } - [JsonPropertyName("lon")] public double Longitude { get; set; } - [JsonPropertyName("zoneId")] public string? ZoneId { get; set; } - } - - public class Step - { - [JsonPropertyName("distance")] public double Distance { get; set; } - [JsonPropertyName("relativeDirection")] public string RelativeDirection { get; set; } - [JsonPropertyName("streetName")] public string StreetName { get; set; } // TODO: "sidewalk", "path" or actual street name - [JsonPropertyName("absoluteDirection")] public string AbsoluteDirection { get; set; } - [JsonPropertyName("lat")] public double Latitude { get; set; } - [JsonPropertyName("lon")] public double Longitude { get; set; } - } - - public class LegGeometry - { - [JsonPropertyName("points")] public string? Points { get; set; } - } -} diff --git a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RouteDetailsContent.cs b/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RouteDetailsContent.cs deleted file mode 100644 index 1ba85fa..0000000 --- a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RouteDetailsContent.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System.Globalization; -using System.Text.Json.Serialization; - -namespace Costasdev.Busurbano.Sources.OpenTripPlannerGql.Queries; - -public class RouteDetailsContent : IGraphRequest -{ - public record Args(string Id, string ServiceDate); - - public static string Query(Args args) - { - return string.Create(CultureInfo.InvariantCulture, $$""" - query Query { - route(id: "{{args.Id}}") { - gtfsId - shortName - longName - color - textColor - agency { - name - } - - patterns { - id - name - headsign - directionId - code - semanticHash - - patternGeometry { - points - } - - stops { - gtfsId - code - name - lat - lon - } - - tripsForDate(serviceDate: "{{args.ServiceDate}}") { - stoptimes { - scheduledDeparture - } - } - } - } - } - """); - } -} - -public class RouteDetailsResponse : AbstractGraphResponse -{ - [JsonPropertyName("route")] public RouteItem? Route { get; set; } - - public class RouteItem - { - [JsonPropertyName("gtfsId")] public string? GtfsId { get; set; } - [JsonPropertyName("shortName")] public string? ShortName { get; set; } - [JsonPropertyName("longName")] public string? LongName { get; set; } - [JsonPropertyName("color")] public string? Color { get; set; } - [JsonPropertyName("textColor")] public string? TextColor { get; set; } - [JsonPropertyName("agency")] public AgencyItem? Agency { get; set; } - [JsonPropertyName("patterns")] public List Patterns { get; set; } = []; - } - - public class AgencyItem - { - [JsonPropertyName("name")] public string? Name { get; set; } - } - - public class PatternItem - { - [JsonPropertyName("id")] public required string Id { get; set; } - [JsonPropertyName("name")] public string? Name { get; set; } - [JsonPropertyName("headsign")] public string? Headsign { get; set; } - [JsonPropertyName("directionId")] public int DirectionId { get; set; } - [JsonPropertyName("code")] public string? Code { get; set; } - [JsonPropertyName("semanticHash")] public string? SemanticHash { get; set; } - [JsonPropertyName("patternGeometry")] public GeometryItem? PatternGeometry { get; set; } - [JsonPropertyName("stops")] public List Stops { get; set; } = []; - [JsonPropertyName("tripsForDate")] public List TripsForDate { get; set; } = []; - } - - public class GeometryItem - { - [JsonPropertyName("points")] public string? Points { get; set; } - } - - public class StopItem - { - [JsonPropertyName("gtfsId")] public required string GtfsId { get; set; } - [JsonPropertyName("code")] public string? Code { get; set; } - [JsonPropertyName("name")] public required string Name { get; set; } - [JsonPropertyName("lat")] public double Lat { get; set; } - [JsonPropertyName("lon")] public double Lon { get; set; } - } - - public class TripItem - { - [JsonPropertyName("stoptimes")] public List Stoptimes { get; set; } = []; - } - - public class StoptimeItem - { - [JsonPropertyName("scheduledDeparture")] public int ScheduledDeparture { get; set; } - } -} diff --git a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RoutesListContent.cs b/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RoutesListContent.cs deleted file mode 100644 index fc69452..0000000 --- a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/RoutesListContent.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Globalization; -using System.Text.Json.Serialization; - -namespace Costasdev.Busurbano.Sources.OpenTripPlannerGql.Queries; - -public class RoutesListContent : IGraphRequest -{ - public record Args(string[] Feeds, string ServiceDate); - - public static string Query(Args args) - { - var feedsStr = string.Join(", ", args.Feeds.Select(f => $"\"{f}\"")); - return string.Create(CultureInfo.InvariantCulture, $$""" - query Query { - routes(feeds: [{{feedsStr}}]) { - gtfsId - shortName - longName - color - textColor - sortOrder - agency { - name - } - patterns { - tripsForDate(serviceDate: "{{args.ServiceDate}}") { - id - } - } - } - } - """); - } -} - -public class RoutesListResponse : AbstractGraphResponse -{ - [JsonPropertyName("routes")] public List Routes { get; set; } = []; - - public class RouteItem - { - [JsonPropertyName("gtfsId")] public required string GtfsId { get; set; } - [JsonPropertyName("shortName")] public string? ShortName { get; set; } - [JsonPropertyName("longName")] public string? LongName { get; set; } - [JsonPropertyName("color")] public string? Color { get; set; } - [JsonPropertyName("textColor")] public string? TextColor { get; set; } - [JsonPropertyName("sortOrder")] public int? SortOrder { get; set; } - [JsonPropertyName("agency")] public AgencyItem? Agency { get; set; } - [JsonPropertyName("patterns")] public List Patterns { get; set; } = []; - } - - public class AgencyItem - { - [JsonPropertyName("name")] public string? Name { get; set; } - } - - public class PatternItem - { - [JsonPropertyName("tripsForDate")] public List TripsForDate { get; set; } = []; - } - - public class TripItem - { - [JsonPropertyName("id")] public string? Id { get; set; } - } -} diff --git a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/StopTile.cs b/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/StopTile.cs deleted file mode 100644 index 792d19e..0000000 --- a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/StopTile.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System.Globalization; -using System.Text.Json.Serialization; - -namespace Costasdev.Busurbano.Sources.OpenTripPlannerGql.Queries; - -public class StopTileRequestContent : IGraphRequest -{ - public record Bbox(double MinLon, double MinLat, double MaxLon, double MaxLat); - - public static string Query(Bbox bbox) - { - return string.Create(CultureInfo.InvariantCulture, $@" - query Query {{ - stopsByBbox( - minLat: {bbox.MinLat:F6} - minLon: {bbox.MinLon:F6} - maxLon: {bbox.MaxLon:F6} - maxLat: {bbox.MaxLat:F6} - ) {{ - gtfsId - code - name - lat - lon - routes {{ - gtfsId - shortName - color - textColor - }} - }} - }} - "); - } -} - -public class StopTileResponse : AbstractGraphResponse -{ - [JsonPropertyName("stopsByBbox")] - public List? StopsByBbox { get; set; } - - public record Stop - { - [JsonPropertyName("gtfsId")] - public required string GtfsId { get; set; } - - [JsonPropertyName("code")] - public string? Code { get; set; } - - [JsonPropertyName("name")] - public required string Name { get; set; } - - [JsonPropertyName("lat")] - public required double Lat { get; set; } - - [JsonPropertyName("lon")] - public required double Lon { get; set; } - - [JsonPropertyName("routes")] - public List? Routes { get; set; } - } - - public record Route - { - [JsonPropertyName("gtfsId")] - public required string GtfsId { get; set; } - [JsonPropertyName("shortName")] - public required string ShortName { get; set; } - - [JsonPropertyName("color")] - public string? Color { get; set; } - - [JsonPropertyName("textColor")] - public string? TextColor { get; set; } - } -} diff --git a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/StopsInfo.cs b/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/StopsInfo.cs deleted file mode 100644 index ce6a8c7..0000000 --- a/src/Costasdev.Busurbano.Sources.OpenTripPlannerGql/Queries/StopsInfo.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Globalization; -using System.Text.Json.Serialization; - -namespace Costasdev.Busurbano.Sources.OpenTripPlannerGql.Queries; - -public class StopsInfoContent : IGraphRequest -{ - public record Args(IEnumerable Ids); - - public static string Query(Args args) - { - var idsString = string.Join("\",\"", args.Ids); - return string.Create(CultureInfo.InvariantCulture, $@" - query Query {{ - stops(ids: [""{idsString}""]) {{ - gtfsId - code - name - lat - lon - routes {{ - shortName - color - textColor - }} - }} - }} - "); - } -} - -public class StopsInfoResponse : AbstractGraphResponse -{ - [JsonPropertyName("stops")] public List? Stops { get; set; } - - public class StopItem - { - [JsonPropertyName("gtfsId")] public required string GtfsId { get; set; } - - [JsonPropertyName("code")] public string? Code { get; set; } - - [JsonPropertyName("name")] public required string Name { get; set; } - - [JsonPropertyName("lat")] public double Lat { get; set; } - - [JsonPropertyName("lon")] public double Lon { get; set; } - - [JsonPropertyName("routes")] public List Routes { get; set; } = []; - } - - public class RouteDetails - { - [JsonPropertyName("shortName")] public string? ShortName { get; set; } - [JsonPropertyName("color")] public string? Color { get; set; } - [JsonPropertyName("textColor")] public string? TextColor { get; set; } - } -} -- cgit v1.3