private static Result ConvertRawResultToCity(RawResult r) { Result result = new City { Name = r.name, Link = r.l, CountryCode = r.c, Identifier = r.zmw, TimeZone = r.tz, ShortTimeZone = r.tzs, Latitude = Double.Parse(r.lat, CultureInfo.InvariantCulture), Longitude = Double.Parse(r.lon, CultureInfo.InvariantCulture), LatitudeLongitude = r.ll }; return result; }
private static Result ConvertRawResultToHurricane(RawResult r) { // Handle the start_epoch and end_epoch. DateTime start = DateTime.MinValue; DateTime end = DateTime.MinValue; bool isStartAndEndEqual = r.start_epoch.Equals(r.end_epoch); bool isStartValid = r.start_epoch != "-1"; bool isEndValid = r.end_epoch != "-1"; if (!isStartAndEndEqual && isStartValid && isEndValid) { start = Utilities.GetDateTimeFromUnixEpochTime(r.start_epoch); end = Utilities.GetDateTimeFromUnixEpochTime(r.end_epoch); } // Figure out which basin we're in. var basin = GetBasinFromRawResult(r); Result result = new Hurricane { Name = r.name, Link = r.l, Date = DateTime.ParseExact(r.date, "M/d/yyyy", CultureInfo.InvariantCulture), StormNumber = Int32.Parse(r.strmnum, CultureInfo.InvariantCulture), Basin = basin, Damage = Int32.Parse(r.damage, CultureInfo.InvariantCulture), FormationDate = start, DissipationDate = end, SouthWestLatitude = Double.Parse(r.sw_lat, CultureInfo.InvariantCulture), SouthWestLongitude = Double.Parse(r.sw_lon, CultureInfo.InvariantCulture), NorthEastLatitude = Double.Parse(r.ne_lat, CultureInfo.InvariantCulture), NorthEastLongitude = Double.Parse(r.ne_lon, CultureInfo.InvariantCulture), PeakCategory = Int32.Parse(r.maxcat, CultureInfo.InvariantCulture) }; return result; }
private static TropicalCycloneBasin GetBasinFromRawResult(RawResult r) { TropicalCycloneBasin basin; switch (r.basin) { case "at": basin = TropicalCycloneBasin.NorthAtlantic; break; case "ep": basin = TropicalCycloneBasin.EasternPacific; break; case "wp": basin = TropicalCycloneBasin.WesternPacific; break; case "ni": basin = TropicalCycloneBasin.NorthIndian; break; case "si": basin = TropicalCycloneBasin.SouthIndian; break; default: basin = TropicalCycloneBasin.Unknown; break; } return basin; }
private static Result GetUsableResult(RawResult r) { Result result = null; switch (r.type) { case "city": result = ConvertRawResultToCity(r); break; case "hurricanes": result = ConvertRawResultToHurricane(r); break; } return result; }