/// <summary> /// Given the origin and destination, query the available data source /// </summary> /// <returns>The available data sources, origin info and dest info.</returns> static public string QueryRouteAvailableDataSource(string origin, string dest, string locale) { Airport originAirport = AirportData.Query(origin, locale); Airport destAirport = AirportData.Query(dest, locale); if (originAirport == null || destAirport == null) { return(""); } List <string> lstResult = new List <string>(); foreach (KeyValuePair <string, ADataSourceMetaData> pair in DataSourceRegister.Register) { if (RouteAvialabilityActor.QueryRouteAvailableInTable(origin, dest, pair.Value.SummaryTableName)) { lstResult.Add(pair.Key); } } Dictionary <string, object> res = new Dictionary <string, object>() { { "origin", originAirport.CastToJsonDict(locale) }, { "dest", destAirport.CastToJsonDict(locale) }, { "dataSrc", lstResult } }; return(new JavaScriptSerializer().Serialize(res)); }
private static string DestRankToJson(List <KeyValuePair <string, int> > rank, string locale) { JavaScriptSerializer jsoner = new JavaScriptSerializer(); string res = ""; for (int i = 0; i < MaxAirportNumberInRank && i < rank.Count; i++) { Dictionary <string, string> item = new Dictionary <string, string>(); Airport airport = AirportData.Query(rank[i].Key, locale); item["code"] = rank[i].Key; item["flow"] = rank[i].Value.ToString(); item["iata"] = airport.Iata; item["icao"] = airport.Icao; item["city"] = airport.ServeCity[0]; item["country"] = airport.Country; item["serveCityL"] = City.LocalizeCountryAndSubdiv(locale, airport.ServeCity[0]); item["displayName"] = airport.DisplayName; if (i != 0) { res += ", "; } res += jsoner.Serialize(item); } return("[" + res + "]"); }
public static string QueryByRoute(string year, string origin, string dest, string locale) { Airport originAirport = AirportData.Query(origin); Airport destAirport = AirportData.Query(dest); if (originAirport == null || destAirport == null) { return(""); } double distKm, distMile, distNm; Utils.GetDistanceByUnits(originAirport, destAirport, out distKm, out distMile, out distNm); string res = ""; QueryByRouteInternal("ConnectionData", year, origin, dest, ref res); res = "\"routes\":[" + res + "],"; res += "\"distKm\":" + distKm.ToString() + ","; res += "\"distMile\":" + distMile.ToString() + ","; res += "\"distNm\":" + distNm.ToString(); res = "{" + res + "}"; return(res); }
// TODO: Query the AirportAvailability table public static string QueryAvailableAirportByGeometry(double x1, double y1, double x2, double y2, string returnType, string locale) { NpgsqlConnection conn = null; try { conn = new NpgsqlConnection(ASTDatabase.connStr2); conn.Open(); string sql = string.Format("SELECT DISTINCT \"CODE\" FROM \"AirportAvailability\" WHERE \"GEOM\" && ST_MakeEnvelope({0}, {1}, {2}, {3}, 4326)", x1, y1, x2, y2); NpgsqlCommand command = new NpgsqlCommand(sql, conn); NpgsqlDataReader dr = command.ExecuteReader(); while (dr.Read()) { string code = dr["CODE"].ToString(); Airport airport = AirportData.Query(code, locale); if (airport == null) { return(""); } if (returnType == "code") { return(airport.Code); } else { return(new JavaScriptSerializer().Serialize(airport)); } } } finally { conn.Close(); } return(""); }
public static string QueryByRoute(string year, string origin, string dest, string locale) { NpgsqlConnection conn = null; string res = ""; Airport originAirport = AirportData.Query(origin); Airport destAirport = AirportData.Query(dest); if (originAirport == null || destAirport == null) { return(""); } double distKm = Utils.DistEarth(originAirport.Geometry.x, originAirport.Geometry.y, destAirport.Geometry.x, destAirport.Geometry.y); double distMile = Math.Round(distKm * 0.621371, 0); double distNm = Math.Round(distKm * 0.539957, 0); distKm = Math.Round(distKm, 0); try { conn = new NpgsqlConnection(ASTDatabase.connStr2); conn.Open(); string where = ASTDatabase.MakeWhere(year, "", origin, dest); string[] fields = new string[] { Utils.DoubleQuoteStr("AIRLINE"), Utils.DoubleQuoteStr("DEPARTURE"), Utils.DoubleQuoteStr("PAX"), Utils.DoubleQuoteStr("MONTH_DEPARTURE"), Utils.DoubleQuoteStr("MONTH_PAX") }; string fieldStr = String.Join(",", fields); string sql = string.Format(@"SELECT {0} FROM ""{1}"" WHERE {2}", fieldStr, MetaData.SummaryTableName, where); NpgsqlCommand command = new NpgsqlCommand(sql, conn); NpgsqlDataReader dr = command.ExecuteReader(); while (dr.Read()) { if (res != "") { res += ","; } Dictionary <string, string> item = new Dictionary <string, string>(); IDataRecord record = ( IDataRecord )dr; for (int i = 0; i < record.FieldCount; i++) { item.Add(record.GetName(i), record[i].ToString()); } Airline carrier = AirlineData.Query(item["AIRLINE"], locale); item.Add("AIRLINE_NAME", carrier.FullName); string json = new JavaScriptSerializer().Serialize(item); res += json; } } catch (NpgsqlException e) { } finally { conn.Close(); } res = "\"routes\":[" + res + "],"; res += "\"distKm\":" + distKm.ToString() + ","; res += "\"distMile\":" + distMile.ToString() + ","; res += "\"distNm\":" + distNm.ToString(); res = "{" + res + "}"; return(res); }
public static List <DestInfo> QueryDestByOrigin(string year, string origin, string dest, string airline, string dataSource, string locale) { HashSet <string> validSrc = new HashSet <string>(dataSource.Split(',')); List <DestInfo> res = new List <DestInfo>(); NpgsqlConnection conn = null; try { conn = new NpgsqlConnection(ASTDatabase.connStr2); conn.Open(); // Query T100 Data string where = ASTDatabase.MakeWhere(year, airline, origin, dest); string groupby = " \"GEOM\", " + (origin != "" ? "\"DEST\"" : "\"ORIGIN\""); string fields = origin != "" ? "\"DEST\"" : "\"ORIGIN\""; fields += ", ST_AsText(\"GEOM\") AS \"GEOM\", SUM(\"PAX\") AS \"SUM_PAX\", SUM(\"FREIGHT\") AS \"SUM_FREIGHT\" "; string sql = string.Format(@"SELECT {0} FROM ""{1}"" WHERE {2} GROUP BY {3}", fields, MetaData.SummaryTableName, where, groupby); NpgsqlCommand command = new NpgsqlCommand(sql, conn); NpgsqlDataReader dr = command.ExecuteReader(); while (dr.Read()) { DestInfo destInfo = new DestInfo(); destInfo.Airport = dr[origin != "" ? "DEST" : "ORIGIN"].ToString(); destInfo.TotalPax = Convert.ToInt32(dr["SUM_PAX"].ToString()); destInfo.TotalFreight = Convert.ToInt32(dr["SUM_FREIGHT"].ToString()); // Determine the dataSource of airport Airport airport1 = AirportData.Query(destInfo.Airport); Airport airport2 = AirportData.Query(origin != "" ? origin : dest); destInfo.RouteGeometry = Utils.ProcessWktGeometryString(dr["GEOM"].ToString()); if (airport1.Country != DataSourceRegister.GetDataSrc("T100Data").Country&& airport2.Country != DataSourceRegister.GetDataSrc("T100Data").Country) { destInfo.PartialData = true; destInfo.DataSource = "T100FF"; } else { destInfo.DataSource = "T100Data"; } if (validSrc.Contains(destInfo.DataSource) || dataSource == "") { res.Add(destInfo); } } } finally { conn.Close(); } return(res); }
public static string MatchAirport(string input, string locale) { int limit = 10; NpgsqlConnection conn = null; List <string> lstAirport = new List <string>(); try { conn = new NpgsqlConnection(ASTDatabase.connStr2); conn.Open(); string sqlIata = @"SELECT DISTINCT ""CODE"" FROM ""AirportAvailability"" WHERE ""CODE"" ILIKE @CODE"; NpgsqlCommand commandIata = new NpgsqlCommand(sqlIata, conn); commandIata.Parameters.Add("@CODE", input + '%'); NpgsqlDataReader drIata = commandIata.ExecuteReader(); while (drIata.Read()) { lstAirport.Add(drIata["CODE"].ToString()); } if (input.Length >= 3) { string sqlCity = @"SELECT DISTINCT ""CODE"" FROM ""AirportAvailability"" WHERE ""CITY"" ILIKE @CITY"; NpgsqlCommand commandCity = new NpgsqlCommand(sqlCity, conn); commandCity.Parameters.Add("@CITY", input + '%'); NpgsqlDataReader drCity = commandCity.ExecuteReader(); while (drCity.Read()) { if (!lstAirport.Contains(drCity["CODE"].ToString()) && lstAirport.Count < limit) { lstAirport.Add(drCity["CODE"].ToString()); } } } } finally { conn.Close(); } List <string[]> lstRes = new List <string[]>(); foreach (string code in lstAirport) { Airport airport = AirportData.Query(code, locale); if (airport == null) { continue; } lstRes.Add(new string[2] { airport.Code, City.LocalizeCountryAndSubdiv(locale, airport.ServeCity[0]) }); } string res = new JavaScriptSerializer().Serialize(lstRes); return(res); }
/// <summary> /// Create the dest rank for the given region. /// </summary> private static string CreateRankByRegion(List <RouteStat> routes, string region, ADataSourceMetaData meteData, string locale) { Dictionary <string, int> dictPaxDest = new Dictionary <string, int>(); Dictionary <string, int> dictFreightDest = new Dictionary <string, int>(); Dictionary <string, int> dictPaxAirline = new Dictionary <string, int>(); Dictionary <string, int> dictFreightAirline = new Dictionary <string, int>(); foreach (RouteStat route in routes) { Airport airport = AirportData.Query(route.Dest, locale); if (region == "International" && airport.Country != meteData.Country || region == "Domestic" && airport.Country == meteData.Country || region == "All") { AddFlowToDict(dictPaxDest, dictPaxAirline, route, item => item.Pax); AddFlowToDict(dictFreightDest, dictFreightAirline, route, item => item.Freight); } } List <KeyValuePair <string, int> > lstPaxDest = dictPaxDest.ToList(); List <KeyValuePair <string, int> > lstFreightDest = dictFreightDest.ToList(); List <KeyValuePair <string, int> > lstPaxAirline = dictPaxAirline.ToList(); List <KeyValuePair <string, int> > lstFreightAirline = dictFreightAirline.ToList(); lstPaxDest.Sort(ASTDatabase.CmpRankItem); lstFreightDest.Sort(ASTDatabase.CmpRankItem); lstPaxAirline.Sort(ASTDatabase.CmpRankItem); lstFreightAirline.Sort(ASTDatabase.CmpRankItem); // Create the destination rank for passenger and freight string paxDestRank = DestRankToJson(lstPaxDest, locale); string freightDestRank = DestRankToJson(lstFreightDest, locale); // Create the airline rank for passenger and freight int totalPax = lstPaxAirline.Sum(item => item.Value); string paxAirlineRank = meteData.HasAirlineInfo ? AirlineRankToJson(lstPaxAirline, totalPax, locale) : "[]"; int totalFreight = lstFreightAirline.Sum(item => item.Value); string freightAirlineRank = meteData.HasAirlineInfo ? AirlineRankToJson(lstFreightAirline, totalFreight, locale) : "[]"; return(string.Format(@"{{""paxDestRank"" : {0}, ""freightDestRank"" : {1}, ""paxAirlineRank"" : {2}, ""freightAirlineRank"" : {3}, ""totalPax"" : {4}, ""totalFreight"" : {5} }}", paxDestRank, freightDestRank, paxAirlineRank, freightAirlineRank, Utils.DoubleQuoteStr(Utils.FormatLargeNumber(totalPax, locale)), Utils.DoubleQuoteStr(Utils.FormatLargeNumber(totalFreight, locale)))); }
/// <summary> /// Query the available data sources of an aiport, regardless year. /// </summary> public static string QueryAirportAvailableDataSource(string airportCode, string locale) { Airport airport = AirportData.Query(airportCode, locale); if (airport == null) { return(""); } NpgsqlConnection conn = null; try { conn = new NpgsqlConnection(ASTDatabase.connStr2); conn.Open(); string sql = string.Format(@"SELECT ""DATA_SOURCE"" FROM ""AirportAvailability"" WHERE ""CODE"" = {0}", Utils.SingleQuoteStr(airportCode)); NpgsqlCommand command = new NpgsqlCommand(sql, conn); NpgsqlDataReader dr = command.ExecuteReader(); List <string> lstResult = new List <string>(); // Determine the primate data source of the given airport string primaryDataSrc = DataSourceRegister.QueryCountryByDataSrc(airport.Country); if (primaryDataSrc != "") { lstResult.Add(primaryDataSrc); } while (dr.Read()) { string dataSrc = dr["DATA_SOURCE"].ToString(); if (dataSrc == "ConnectionData") { continue; //TODO } if (dataSrc != primaryDataSrc) { lstResult.Add(dataSrc); } } return(new JavaScriptSerializer().Serialize(lstResult)); } finally { conn.Close(); } return(""); }
// TODO: Pay attention to T100FF data public static string QueryAirportYearAvailability(string airportCode, string codeType, string dataSrc, string locale) { NpgsqlConnection conn = null; try { conn = new NpgsqlConnection(ASTDatabase.connStr2); conn.Open(); string sql = string.Format(@"SELECT ""AVAILABILITY"" FROM ""AirportAvailability"" WHERE ""CODE"" = '{0}' AND ""DATA_SOURCE"" ='{1}'", airportCode, dataSrc); NpgsqlCommand command = new NpgsqlCommand(sql, conn); NpgsqlDataReader dr = command.ExecuteReader(); Airport airport = AirportData.Query(airportCode, locale); if (airport == null) { return(""); } while (dr.Read()) { Dictionary <string, object> res = new Dictionary <string, object>() { { "iata", airport.Iata }, { "icao", airport.Icao }, { "country", airport.Country }, { "city", airport.ServeCity[0] }, { "countryL", CountryData.QueryCountry(locale, airport.Country).Name }, { "serveCityL", City.LocalizeCountryAndSubdiv(locale, airport.ServeCity[0]) }, { "name", airport.FullName }, { "note", airport.Note }, { "nameEn", airport.FullName }, // TODO { "cityEn", airport.ServeCity[0] }, // TODO { "yearAvailability", dr["AVAILABILITY"].ToString() } }; return(new JavaScriptSerializer().Serialize(res)); } } finally { conn.Close(); } return(""); }
public Dictionary <string, object> CastToDict(string locale) { Dictionary <string, object> dict = new Dictionary <string, object>(); dict["Code"] = this.Code; dict["Icao"] = this.Icao; dict["Iata"] = this.Iata; dict["FullName"] = this.FullName; dict["DisplayName"] = this.DisplayName; dict["City"] = this.ServeCity[0]; dict["Geometry"] = this.Geometry.x.ToString() + ", " + this.Geometry.y.ToString(); dict["X"] = this.Geometry.x; dict["Y"] = this.Geometry.y; if (locale != "ENUS") { Airport airportEn = AirportData.Query(this.Code, "ENUS"); dict["FullNameEn"] = airportEn.FullName; dict["ServeCity1En"] = City.LocalizeCountryAndSubdiv("ENUS", airportEn.ServeCity[0]); } return(dict); }
static public string QueryAirportJson(string code, string locale) { Airport airport = AirportData.Query(code, locale); if (airport == null) { return(""); } Dictionary <string, object> json = new Dictionary <string, object>() { { "code", airport.Code }, { "icao", airport.Icao }, { "iata", airport.Iata }, { "country", airport.Country }, { "city", airport.ServeCity }, { "name", airport.FullName }, { "geom", airport.Geometry }, { "note", airport.Note } }; string jsonStr = new JavaScriptSerializer().Serialize(json); return(jsonStr); }
public Dictionary <string, object> CastToJsonDict(string locale) { Dictionary <string, object> dict = new Dictionary <string, object>(); dict["code"] = this.Code; dict["icao"] = this.Icao; dict["iata"] = this.Iata; dict["fullName"] = this.FullName; dict["country"] = this.Country; dict["serveCityL"] = City.LocalizeCountryAndSubdiv(locale, this.ServeCity[0]); dict["geometry"] = new Dictionary <string, double> { { "x", this.Geometry.x }, { "y", this.Geometry.y } }; if (locale != "ENUS") { Airport airportEn = AirportData.Query(this.Code, "ENUS"); dict["fullNameEn"] = airportEn.FullName; dict["serveCity1En"] = City.LocalizeCountryAndSubdiv("ENUS", airportEn.ServeCity[0]); } return(dict); }
public string MatchAirport(string input, string locale) { return(AirportData.MatchAirport(input, locale)); }
public static string QueryByAirlines(string year, string airline, string region, string locale, int limit = 100) { NpgsqlConnection conn = null; string currentCountry = DataSourceRegister.GetDataSrc("T100Data").Country; try { string res = ""; conn = new NpgsqlConnection(ASTDatabase.connStr2); conn.Open(); JavaScriptSerializer jsoner = new JavaScriptSerializer(); string where = ASTDatabase.MakeWhere(year, airline, "", ""); Airline carrier = AirlineData.Query(airline, locale); if (carrier == null) { return(""); } string flowField = carrier.Type == "Passenger" ? "PAX" : "FREIGHT"; // TODO: Fix table name string[] fields = new string[] { Utils.DoubleQuoteStr("ORIGIN"), Utils.DoubleQuoteStr("DEST"), Utils.DoubleQuoteStr(flowField), Utils.DoubleQuoteStr("DEPARTURE"), @"ST_AsText(""T100DataSummary"".""GEOM"") AS ""GEOM""", @"""AP1"".""COUNTRY"" as ""ORIGIN_COUNTRY""", @"""AP2"".""COUNTRY"" as ""DEST_COUNTRY""" }; string fieldStr = String.Join(",", fields); if (region == "US") { where += string.Format(@" AND ( ""AP1"".""COUNTRY"" = '{0}' AND ""AP2"".""COUNTRY"" = '{1}' ) ", currentCountry, currentCountry); } else if (region == "Intl") { where += string.Format(@" AND ( ""AP1"".""COUNTRY"" <> '{0}' OR ""AP2"".""COUNTRY"" <> '{1}' ) ", currentCountry, currentCountry); } where += " AND \"AP1\".\"CODE\" = \"T100DataSummary\".\"ORIGIN\" AND \"AP2\".\"CODE\" = \"T100DataSummary\".\"DEST\" "; string sql = string.Format(@"SELECT {0} FROM ""T100DataSummary"" , ""CommonData_Airport"" AS ""AP1"", ""CommonData_Airport"" AS ""AP2"" WHERE {1} ORDER BY ""{2}"" DESC LIMIT {3}", fieldStr, where, flowField, limit); NpgsqlCommand command = new NpgsqlCommand(sql, conn); NpgsqlDataReader dr = command.ExecuteReader(); while (dr.Read()) { Dictionary <string, object> route = new Dictionary <string, object>(); Airport oAirport = AirportData.Query(dr["ORIGIN"].ToString(), locale); Airport dAirport = AirportData.Query(dr["DEST"].ToString(), locale); int flow = Convert.ToInt32(dr[flowField]); if (flow == 0) { continue; } route["origin"] = dr["ORIGIN"].ToString(); route["originCity"] = oAirport.ServeCity[0]; route["originCountry"] = oAirport.Country; route["originGeom"] = oAirport.Geometry; route["dest"] = dr["DEST"].ToString(); route["destCity"] = dAirport.ServeCity[0]; route["destCountry"] = dAirport.Country; route["destGeom"] = dAirport.Geometry; route["flow"] = Convert.ToInt32(dr[flowField]); route["departure"] = dr["DEPARTURE"].ToString(); string geom = dr["GEOM"].ToString(); geom = geom.Replace("MULTILINESTRING", ""); geom = geom.Replace("(", "["); geom = geom.Replace(")", "]"); route["geom"] = geom; if (res != "") { res += ","; } res += jsoner.Serialize(route); } return("[" + res + "]"); } finally { conn.Close(); } return(""); }
static public string QueryRouteAircraftStat(string year, string origin, string dest, string locale) { NpgsqlConnection conn = null; JavaScriptSerializer jsoner = new JavaScriptSerializer(); try { int totalPax = 0; int totalFreight = 0; conn = new NpgsqlConnection(ASTDatabase.connStr2); conn.Open(); string where = ASTDatabase.MakeWhere(year, "", origin, dest); string[] fields = new string[] { Utils.DoubleQuoteStr("AIRLINE"), Utils.DoubleQuoteStr("AIRCRAFT_PAX"), Utils.DoubleQuoteStr("AIRCRAFT_FREIGHT"), Utils.DoubleQuoteStr("AIRCRAFT_DEPARTURE"), Utils.DoubleQuoteStr("PAX"), Utils.DoubleQuoteStr("FREIGHT"), Utils.DoubleQuoteStr("DEPARTURE") }; string fieldStr = String.Join(",", fields); string sql = "SELECT " + fieldStr + " FROM \"T100DataSummary\" WHERE " + where; NpgsqlCommand command = new NpgsqlCommand(sql, conn); NpgsqlDataReader dr = command.ExecuteReader(); Dictionary <string, int> paxSummary = new Dictionary <string, int>(); Dictionary <string, int> freightSummary = new Dictionary <string, int>(); Dictionary <string, int> departureSummary = new Dictionary <string, int>(); Dictionary <string, object> dictRouteRes = new Dictionary <string, object>(); Dictionary <string, Aircraft> aircraftDict = new Dictionary <string, Aircraft>(); while (dr.Read()) { Dictionary <string, object> route = new Dictionary <string, object>(); route["airline"] = dr["AIRLINE"].ToString(); Airline carrier = AirlineData.Query(dr["AIRLINE"].ToString(), locale); route["airlineName"] = carrier.FullName; route["aircraftPax"] = ProcessAirlineItem(paxSummary, jsoner.Deserialize <Dictionary <string, int> >(dr["AIRCRAFT_PAX"].ToString())); route["aircraftFreight"] = ProcessAirlineItem(freightSummary, jsoner.Deserialize <Dictionary <string, int> >(dr["AIRCRAFT_FREIGHT"].ToString())); route["aircraftDeparture"] = ProcessAirlineItem(departureSummary, jsoner.Deserialize <Dictionary <string, int> >(dr["AIRCRAFT_DEPARTURE"].ToString())); totalPax += Convert.ToInt32(dr["PAX"]); totalFreight += Convert.ToInt32(dr["FREIGHT"]); Dictionary <string, int> localAircraft = jsoner.Deserialize <Dictionary <string, int> >(dr["AIRCRAFT_DEPARTURE"].ToString()); foreach (KeyValuePair <string, int> item in localAircraft) { string aircraft = item.Key; if (aircraft != "Other") { aircraftDict[aircraft] = AircraftData.Query(aircraft, locale); } } dictRouteRes[dr["AIRLINE"].ToString()] = route; } Dictionary <string, object> total = new Dictionary <string, object>(); total["airline"] = "All"; total["airlineName"] = ""; total["aircraftPax"] = ProcessSummaryDict(paxSummary); total["aircraftFreight"] = ProcessSummaryDict(freightSummary); total["aircraftDeparture"] = ProcessSummaryDict(departureSummary); dictRouteRes["All"] = total; Airport originAirport = AirportData.Query(origin, locale); Airport destAirport = AirportData.Query(dest, locale); Dictionary <string, object> dictRes = new Dictionary <string, object>() { { "routes", dictRouteRes }, { "aircrafts", aircraftDict }, { "origin", originAirport }, { "dest", destAirport }, { "totalPax", totalPax }, { "totalFreight", totalFreight } }; return(jsoner.Serialize(dictRes)); } finally { conn.Close(); } return(""); }
public static string QueryByOrigin(string year, string origin, string dest, string airline, string queryType, string dataSource, string locale) { // Verify the parameter string keyword = origin != "" ? origin : dest; if (queryType == "code") { if (AirportData.Query(keyword) == null) { return(""); } } else { string[] lstCoordinate = keyword.Split(','); if (lstCoordinate.Length == 4) { double x1 = Convert.ToDouble(lstCoordinate[0]); double y1 = Convert.ToDouble(lstCoordinate[1]); double x2 = Convert.ToDouble(lstCoordinate[2]); double y2 = Convert.ToDouble(lstCoordinate[3]); keyword = QueryAvailableAirportByGeometry(x1, y1, x2, y2, "code", locale); if (keyword == "") { return(""); } } else { return(""); } } if (origin != "") { origin = keyword; } else { dest = keyword; } List <DestInfo> destInfo = new List <DestInfo>(); HashSet <string> validSrc = new HashSet <string>(dataSource.Split(',')); HashSet <string> destSet = new HashSet <string>(); // Query USA T100 Data if (validSrc.Contains("T100") || validSrc.Contains("T100FF") || dataSource == "") { destInfo.AddRange(T100Data.QueryDestByOrigin(year, origin, dest, airline, dataSource, locale)); } // Query UK CAA Data if (validSrc.Contains("UkData") || dataSource == "") { destInfo.AddRange(UkData.QueryDestByOrigin(year, origin, dest, airline, locale)); } // Query Taiwan CAA Data if (validSrc.Contains("TaiwanData") || dataSource == "") { destInfo.AddRange(TwData.QueryDestByOrigin(year, origin, dest, airline, locale)); } // Query Japan MLIT Data if (validSrc.Contains("JapanData") || dataSource == "") { destInfo.AddRange(JpData.QueryDestByOrigin(year, origin, dest, airline, locale)); } // Query Korea Airport Corpartion Data if (validSrc.Contains("KoreaData") || dataSource == "") { destInfo.AddRange(KrData.QueryDestByOrigin(year, origin, dest, airline, locale)); } // Query Wiki connection data if (validSrc.Contains("ConnectionData") || dataSource == "") { for (int i = 0; i < destInfo.Count; i++) { destSet.Add(destInfo[i].Airport); } // Only show the destinations that don't exist in other data sources List <DestInfo> wikiResult = WikiData.QueryDestByOrigin(year, origin, dest, airline, locale); foreach (DestInfo _dest in wikiResult) { if (!destSet.Contains(_dest.Airport)) { destInfo.Add(_dest); } } } Dictionary <string, DestItem> destDict = new Dictionary <string, DestItem>(); foreach (DestInfo d in destInfo) { if (!destDict.ContainsKey(d.Airport)) { DestItem destItem = new DestItem(); destItem.Airport = AirportData.Query(d.Airport, locale).CastToDict(locale); destItem.RouteGeometry = d.RouteGeometry; destDict[d.Airport] = destItem; } destDict[d.Airport].AvailableData.Add(d); } Dictionary <string, Object> resDict = new Dictionary <string, object>(); resDict["routes"] = destDict.Values.ToList(); resDict["fromAirport"] = AirportData.Query(keyword, locale).CastToDict(locale); return(new JavaScriptSerializer().Serialize(resDict)); }
/* * THis might be deprecated. It's not used any more. Maybe it's useful for testing * */ public string QueryAirportInfo(string airportCode, string codeType, string locale) { return(AirportData.QueryAirportJson(airportCode, locale)); }