From c3d8594bca97c0d1ad879928f63acd99513fae02 Mon Sep 17 00:00:00 2001 From: jpsingleton Date: Thu, 14 May 2015 12:56:32 +0100 Subject: [PATCH] Factor out London Terminals so they can be returned by the CRS API --- src/Huxley/Controllers/CrsController.cs | 3 + src/Huxley/Controllers/DelaysController.cs | 27 +------- src/Huxley/Global.asax.cs | 26 +++++++ src/Huxley/index.html | 79 +++++++++++++++++++++- 4 files changed, 109 insertions(+), 26 deletions(-) diff --git a/src/Huxley/Controllers/CrsController.cs b/src/Huxley/Controllers/CrsController.cs index 46a0cba..8c40f41 100644 --- a/src/Huxley/Controllers/CrsController.cs +++ b/src/Huxley/Controllers/CrsController.cs @@ -32,6 +32,9 @@ public IEnumerable Get() { // GET /crs/{query} public IEnumerable Get(string query) { + if (query.Equals("London Terminals", StringComparison.InvariantCultureIgnoreCase)) { + return HuxleyApi.LondonTerminals; + } // Could use a RegEx here but putting user input into a RegEx can be dangerous var results = HuxleyApi.CrsCodes.Where(c => c.StationName.IndexOf(query, StringComparison.InvariantCultureIgnoreCase) >= 0); return results; diff --git a/src/Huxley/Controllers/DelaysController.cs b/src/Huxley/Controllers/DelaysController.cs index ee7aa8f..3152df2 100644 --- a/src/Huxley/Controllers/DelaysController.cs +++ b/src/Huxley/Controllers/DelaysController.cs @@ -65,29 +65,6 @@ public async Task Get([FromUri] StationBoardRequest request) { } } - // https://en.wikipedia.org/wiki/London_station_group - // Farringdon [ZFD] is not a London Terminal but it probably should be (maybe when Crossrail opens it will be) - var londonTerminals = new List { - "BFR", // Blackfriars - "CST", // Cannon Street - "CHX", // Charing Cross - "CTX", // City Thameslink - "EUS", // Euston - "FST", // Fenchurch Street - "KGX", // King's Cross - "LST", // Liverpool Street - "LBG", // London Bridge - "MYB", // Marylebone - "MOG", // Moorgate - "OLD", // Old Street - "PAD", // Paddington - "STP", // St. Pancras - "VXH", // Vauxhall - "VIC", // Victoria - "WAT", // Waterloo - "WAE", // Waterloo East - }; - var totalDelayMinutes = 0; var delayedTrains = new List(); @@ -113,10 +90,10 @@ public async Task Get([FromUri] StationBoardRequest request) { // Could query for every terminal or get service for every train and check calling points. Very chatty either way. switch (request.FilterType) { case FilterType.to: - trainServices = trainServices.Where(ts => ts.destination.Any(d => londonTerminals.Contains(d.crs.ToUpperInvariant()))).ToArray(); + trainServices = trainServices.Where(ts => ts.destination.Any(d => HuxleyApi.LondonTerminals.Any(lt => lt.CrsCode == d.crs.ToUpperInvariant()))).ToArray(); break; case FilterType.from: - trainServices = trainServices.Where(ts => ts.origin.Any(d => londonTerminals.Contains(d.crs.ToUpperInvariant()))).ToArray(); + trainServices = trainServices.Where(ts => ts.origin.Any(o => HuxleyApi.LondonTerminals.Any(lt => lt.CrsCode == o.crs.ToUpperInvariant()))).ToArray(); break; default: throw new ArgumentOutOfRangeException(); diff --git a/src/Huxley/Global.asax.cs b/src/Huxley/Global.asax.cs index ca71002..0f72c5f 100644 --- a/src/Huxley/Global.asax.cs +++ b/src/Huxley/Global.asax.cs @@ -37,6 +37,9 @@ public class HuxleyApi : HttpApplication { // Singleton to store the station name to CRS lookup public static IList CrsCodes { get; private set; } + // Singleton to store the London Terminals CRS lookup + public static IList LondonTerminals { get; private set; } + // Singleton to store the Huxley settings public static HuxleySettings Settings { get; private set; } @@ -59,6 +62,29 @@ protected void Application_Start() { // Set the CRS dictionary passing in embedded CRS path CrsCodes = GetCrsCodes(Server.MapPath("~/RailReferences.csv")).Result; + + // https://en.wikipedia.org/wiki/London_station_group + // Farringdon [ZFD] is not a London Terminal but it probably should be (maybe when Crossrail opens it will be) + LondonTerminals = new List { + new CrsRecord {CrsCode = "BFR", StationName = "London Blackfriars",}, + new CrsRecord {CrsCode = "CST", StationName = "London Cannon Street",}, + new CrsRecord {CrsCode = "CHX", StationName = "London Charing Cross",}, + new CrsRecord {CrsCode = "CTX", StationName = "City Thameslink",}, + new CrsRecord {CrsCode = "EUS", StationName = "London Euston",}, + new CrsRecord {CrsCode = "FST", StationName = "London Fenchurch Street",}, + new CrsRecord {CrsCode = "KGX", StationName = "London Kings Cross",}, + new CrsRecord {CrsCode = "LST", StationName = "London Liverpool Street",}, + new CrsRecord {CrsCode = "LBG", StationName = "London Bridge",}, + new CrsRecord {CrsCode = "MYB", StationName = "London Marylebone",}, + new CrsRecord {CrsCode = "MOG", StationName = "Moorgate",}, + new CrsRecord {CrsCode = "OLD", StationName = "Old Street",}, + new CrsRecord {CrsCode = "PAD", StationName = "London Paddington",}, + new CrsRecord {CrsCode = "STP", StationName = "London St Pancras International",}, + new CrsRecord {CrsCode = "VXH", StationName = "Vauxhall",}, + new CrsRecord {CrsCode = "VIC", StationName = "London Victoria",}, + new CrsRecord {CrsCode = "WAT", StationName = "London Waterloo",}, + new CrsRecord {CrsCode = "WAE", StationName = "London Waterloo East",}, + }; } protected void Application_BeginRequest(object sender, EventArgs e) { diff --git a/src/Huxley/index.html b/src/Huxley/index.html index 26e683a..18edb45 100644 --- a/src/Huxley/index.html +++ b/src/Huxley/index.html @@ -136,7 +136,7 @@

Delays

}

- Additionally, this action will accept LON or London as a filter CRS to find trains going to or coming from any London terminal. + Additionally, this action will accept LON or London as a filter CRS to find trains going to or coming from any of the London Terminals.

You can also pass in a comma separated list of 24 hour train times to filter on (e.g. /delays/btn/to/lon/50/0729,0744,0748). @@ -161,6 +161,83 @@

CRS Station Codes

"crsCode": "LZB" } ] + +

/crs/london terminals returns all codes in the London station group.

+
+[
+  {
+    "stationName": "London Blackfriars",
+    "crsCode": "BFR"
+  },
+  {
+    "stationName": "London Cannon Street",
+    "crsCode": "CST"
+  },
+  {
+    "stationName": "London Charing Cross",
+    "crsCode": "CHX"
+  },
+  {
+    "stationName": "City Thameslink",
+    "crsCode": "CTX"
+  },
+  {
+    "stationName": "London Euston",
+    "crsCode": "EUS"
+  },
+  {
+    "stationName": "London Fenchurch Street",
+    "crsCode": "FST"
+  },
+  {
+    "stationName": "London Kings Cross",
+    "crsCode": "KGX"
+  },
+  {
+    "stationName": "London Liverpool Street",
+    "crsCode": "LST"
+  },
+  {
+    "stationName": "London Bridge",
+    "crsCode": "LBG"
+  },
+  {
+    "stationName": "London Marylebone",
+    "crsCode": "MYB"
+  },
+  {
+    "stationName": "Moorgate",
+    "crsCode": "MOG"
+  },
+  {
+    "stationName": "Old Street",
+    "crsCode": "OLD"
+  },
+  {
+    "stationName": "London Paddington",
+    "crsCode": "PAD"
+  },
+  {
+    "stationName": "London St Pancras International",
+    "crsCode": "STP"
+  },
+  {
+    "stationName": "Vauxhall",
+    "crsCode": "VXH"
+  },
+  {
+    "stationName": "London Victoria",
+    "crsCode": "VIC"
+  },
+  {
+    "stationName": "London Waterloo",
+    "crsCode": "WAT"
+  },
+  {
+    "stationName": "London Waterloo East",
+    "crsCode": "WAE"
+  }
+]
 

Service

/service/[Service ID]?accessToken=[Your GUID token]