Beispiel #1
0
 private static void SetupPropertyCache()
 {
     PropertyCache = new Dictionary <string, object>
     {
         { "GameSession", RandomEx.GetUniqueShortId() },
         { "EventCorrelationId", RandomEx.GetUniqueShortId() },
         { "GamerTag", "gamer" },
         { "DisplayName", "display" },
         { "Value", 1 }
     };
 }
Beispiel #2
0
        private void GenerateRandomRoute(int i, float minLat, float maxLat, float minLon, float maxLon, int maxDistance, int maxTotalWalkingTime, string outputPath, string outputFilePrefix, bool verbose = true)
        {
            Console.WriteLine($"Route - {i}");

            Coordinate startCoordinate;
            Coordinate endCoordinate;
            Route      route;

            Console.Write(".");
            while (true)
            {
                try
                {
                    startCoordinate = new Coordinate(
                        (float)(minLat + Math.Abs(maxLat - minLat) * _rnd.NextDouble()),
                        (float)(minLon + Math.Abs(maxLon - minLon) * _rnd.NextDouble()));

                    endCoordinate = new Coordinate(
                        (float)(minLat + Math.Abs(maxLat - minLat) * _rnd.NextDouble()),
                        (float)(minLon + Math.Abs(maxLon - minLon) * _rnd.NextDouble()));

                    route = s_router.Calculate(Vehicle.Pedestrian.Shortest(), startCoordinate, endCoordinate);

                    if (maxDistance > 0 && route.TotalDistance > maxDistance)
                    {
                        if (verbose)
                        {
                            Console.Write("D");
                        }
                        continue;
                    }

                    if (maxTotalWalkingTime > 0 && route.TotalTime > maxTotalWalkingTime)
                    {
                        if (verbose)
                        {
                            Console.Write("T");
                        }
                        continue;
                    }

                    break;
                }
                catch (ResolveFailedException)
                {
                    if (verbose)
                    {
                        Console.Write("!");
                    }
                    continue;
                }
                catch (RouteNotFoundException)
                {
                    if (verbose)
                    {
                        Console.Write("#");
                    }
                    continue;
                }
                catch (Exception)
                {
                    if (verbose)
                    {
                        Console.Write("E");
                    }
                    continue;
                }
            }
            if (verbose)
            {
                Console.WriteLine();
            }

            var id       = RandomEx.GetUniqueShortId();
            var filePath = Path.Combine(outputPath, $"{outputFilePrefix}_{id}.json");

            File.WriteAllText(filePath, route.ToGeoJson());

            if (verbose)
            {
                Console.WriteLine($"Total Distance: {route.TotalDistance / 1000:0.0}km");
            }
            if (verbose)
            {
                Console.WriteLine($"Total Time:     {TimeSpan.FromSeconds(route.TotalTime)}");
            }
            if (verbose)
            {
                Console.WriteLine($"File:           {filePath}");
            }
            if (verbose)
            {
                Console.WriteLine();
            }
        }