Exemplo n.º 1
0
        public static CheckPoint FindCheckPoint(List <Location> locations, Location location1, string country1, Location location2, string country2, Func <Geometry, string> getCountry, int callCount = 0)
        {
            callCount++;
            if (locations.Count < 4 || (location2.TimestampMsUnix - location1.TimestampMsUnix) < MinInterval || callCount > 10)
            {
                return(LocationToCheckPoint(location2, country2));
            }

            var mid         = (long)((location2.TimestampMsUnix + location1.TimestampMsUnix) / 2.0);
            var midLocation = locations.OrderBy(l => Math.Abs(l.TimestampMsUnix - mid)).First();

            if (midLocation == null)
            {
                return(LocationToCheckPoint(location2, country2));
            }

            var midCountry = getCountry(midLocation.Point);

            if (midCountry == country2)
            {
                var range = locations.Where(lh => lh.TimestampMsUnix >= location1.TimestampMsUnix && lh.TimestampMsUnix <= midLocation.TimestampMsUnix).ToList();
                return(FindCheckPoint(range, location1, country1, midLocation, midCountry, getCountry, callCount));
            }
            else
            {
                var range = locations.Where(lh => lh.TimestampMsUnix >= midLocation.TimestampMsUnix && lh.TimestampMsUnix <= location2.TimestampMsUnix).ToList();
                return(FindCheckPoint(range, midLocation, midCountry, location2, country2, getCountry, callCount));
            }
        }
Exemplo n.º 2
0
 public static CheckPoint LocationToCheckPoint(Location location, string country)
 {
     return(new CheckPoint
     {
         CountryName = country,
         Date = location.Date,
         Point = location.Point
     });
 }