public static List<TripResult> GetResult() { using (ATDataContext context = new ATDataContext()) { List<TripResult> list = new List<TripResult>(); List<Trip> trips = context.Trips.ToList(); Boolean IsExisted = false; foreach(var trip in trips) { IsExisted = false; foreach(var result in list) { if(trip.HeadSign == result.HeadSign) { result.NumberOfTrips++; IsExisted = true; break; } } if (IsExisted == false) { list.Add(new TripResult { HeadSign = trip.HeadSign, NumberOfTrips = 1 }); } } return list; } }
public static List<RoadWorkResult> GetResult(Boolean SuburbIncluded) { using (ATDataContext context = new ATDataContext()) { List<RoadWorkResult> list = new List<RoadWorkResult>(); List<ScheduledWork> works = context.ScheduledWorks.ToList(); Boolean IsExisted = false; foreach(var work in works) { IsExisted = false; foreach(var result in list) { if((work.Suburb == result.Suburb || SuburbIncluded == false) && work.Region == result.Region) { result.NumberOfWorks++; IsExisted = true; break; } } if(IsExisted == false) { list.Add(new RoadWorkResult { Suburb = work.Suburb, Region = work.Region, NumberOfWorks = 1 }); } } return list; } }
/// <summary> /// Find single stop nearest to multiple location /// </summary> /// <param name="location"></param> /// <param name="radius"></param> public static Stop CloestToMultipleLocation(List<double[]> locations, decimal radius = 500) { List<Stop> list = new List<Stop>(); using (ATDataContext context = new ATDataContext()) { list = context.Stops.ToList(); } GeoCoordinate endpoint = new GeoCoordinate(); GeoCoordinate startpoint = new GeoCoordinate(); double distance = 0; double new_distance = 0; Stop result = new Stop(); foreach (Stop s in list) { new_distance = 0; startpoint = new GeoCoordinate(s.Latitude.GetValueOrDefault(), s.Longitude.GetValueOrDefault()); foreach(var location in locations) { endpoint = new GeoCoordinate(location[0], location[1]); new_distance += startpoint.GetDistanceTo(endpoint); } if (list.IndexOf(s) == 0 || new_distance < distance) { distance = new_distance; result = s; } } return result; }
/// <summary> /// Find multiple stops based on radius /// </summary> /// <param name="location"></param> /// <param name="radius"></param> public static List<Stop> AroundSingleLocation(double[] location, double radius = 500) { List<Stop> list = new List<Stop>(); List<Stop> filtered_list = new List<Stop>(); using (ATDataContext context = new ATDataContext()) { list = context.Stops.ToList(); } GeoCoordinate endpoint = new GeoCoordinate(location[0], location[1]); GeoCoordinate startpoint = new GeoCoordinate(); foreach (Stop s in list) { startpoint = new GeoCoordinate(s.Latitude.GetValueOrDefault(), s.Longitude.GetValueOrDefault()); if (startpoint.GetDistanceTo(endpoint) < radius) { filtered_list.Add(s); } } return filtered_list; }
public static void Run() { using (ATDataContext context = new ATDataContext()) { // Delete is called te to necessary to mark the database uninitialized, whereas physically delete mdf file is insufficient. // "Alter Database ATA Set Offline with rollback immediate" // "Alter Database ATA Set Online" context.Database.Delete(); context.Database.Create(); } }
/// <summary> /// Find single stop nearest to single location /// </summary> /// <param name="location"></param> /// <param name="radius"></param> public static Stop CloestToSingleLocation(double[] location) { List<Stop> list = new List<Stop>(); using (ATDataContext context = new ATDataContext()) { list = context.Stops.ToList(); } GeoCoordinate endpoint = new GeoCoordinate(location[0], location[1]); GeoCoordinate startpoint = new GeoCoordinate(); double distance = 0; double new_distance = 0; Stop result = new Stop(); foreach (Stop s in list) { startpoint = new GeoCoordinate(s.Latitude.GetValueOrDefault(), s.Longitude.GetValueOrDefault()); new_distance = startpoint.GetDistanceTo(endpoint); if (list.IndexOf(s) == 0 || new_distance < distance) { distance = new_distance; result = s; } } return result; }