geo fences - wip

This commit is contained in:
Anton Martynenko
2025-11-19 17:26:23 +01:00
parent 5974b0c589
commit d122497b50
22 changed files with 766 additions and 114 deletions
@@ -10,6 +10,11 @@ public static class RouteTests
PropertyNameCaseInsensitive = true
};
private static readonly JsonSerializerOptions JsonWriteOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
public static async Task RunSimpleRouteTest(HttpClient httpClient)
{
Console.WriteLine("Test: Create Simple Route with Two Points");
@@ -25,19 +30,19 @@ public static class RouteTests
ZoomLevel = 18,
Points = new List<RoutePointInput>
{
new() { Latitude = 48.276067180586544, Longitude = 37.38445758819581 },
new() { Latitude = 48.27074009522731, Longitude = 37.374029159545906 }
new() { Lat = 48.276067180586544, Lon = 37.38445758819581 },
new() { Lat = 48.27074009522731, Lon = 37.374029159545906 }
}
};
Console.WriteLine($"Creating route with 2 points:");
Console.WriteLine($" Start: ({request.Points[0].Latitude}, {request.Points[0].Longitude})");
Console.WriteLine($" End: ({request.Points[1].Latitude}, {request.Points[1].Longitude})");
Console.WriteLine($" Start: ({request.Points[0].Lat}, {request.Points[0].Lon})");
Console.WriteLine($" End: ({request.Points[1].Lat}, {request.Points[1].Lon})");
Console.WriteLine($" Region Size: {request.RegionSizeMeters}m");
Console.WriteLine($" Zoom Level: {request.ZoomLevel}");
Console.WriteLine();
var response = await httpClient.PostAsJsonAsync("/api/satellite/route", request);
var response = await httpClient.PostAsJsonAsync("/api/satellite/route", request, JsonWriteOptions);
if (!response.IsSuccessStatusCode)
{
@@ -136,20 +141,20 @@ public static class RouteTests
RequestMaps = true,
Points = new List<RoutePointInput>
{
new() { Latitude = 48.276067180586544, Longitude = 37.38445758819581 },
new() { Latitude = 48.27074009522731, Longitude = 37.374029159545906 }
new() { Lat = 48.276067180586544, Lon = 37.38445758819581 },
new() { Lat = 48.27074009522731, Lon = 37.374029159545906 }
}
};
Console.WriteLine("Step 1: Creating route with RequestMaps=true");
Console.WriteLine($" Start: ({request.Points[0].Latitude}, {request.Points[0].Longitude})");
Console.WriteLine($" End: ({request.Points[1].Latitude}, {request.Points[1].Longitude})");
Console.WriteLine($" Start: ({request.Points[0].Lat}, {request.Points[0].Lon})");
Console.WriteLine($" End: ({request.Points[1].Lat}, {request.Points[1].Lon})");
Console.WriteLine($" Region Size: {request.RegionSizeMeters}m");
Console.WriteLine($" Zoom Level: {request.ZoomLevel}");
Console.WriteLine($" Request Maps: {request.RequestMaps}");
Console.WriteLine();
var routeResponse = await httpClient.PostAsJsonAsync("/api/satellite/route", request);
var routeResponse = await httpClient.PostAsJsonAsync("/api/satellite/route", request, JsonWriteOptions);
if (!routeResponse.IsSuccessStatusCode)
{
@@ -287,48 +292,72 @@ public static class RouteTests
public static async Task RunComplexRouteWithStitching(HttpClient httpClient)
{
Console.WriteLine();
Console.WriteLine("Test: Complex Route with 10 Points - Region Processing and Stitching");
Console.WriteLine("=======================================================================");
Console.WriteLine("Test: Complex Route with 10 Points + 2 Geofences - Region Processing and Stitching");
Console.WriteLine("======================================================================================");
Console.WriteLine();
var routeId = Guid.NewGuid();
var request = new CreateRouteRequest
{
Id = routeId,
Name = "Complex Route with 10 Points",
Description = "Test route with 10 action points for complex map stitching",
Name = "Complex Route with 10 Points + 2 Geofences",
Description = "Test route with 10 action points and 2 geofence regions for complex map stitching",
RegionSizeMeters = 300.0,
ZoomLevel = 18,
RequestMaps = true,
Points = new List<RoutePointInput>
{
new() { Latitude = 48.276067180586544, Longitude = 37.38445758819581 },
new() { Latitude = 48.27074009522731, Longitude = 37.374029159545906 },
new() { Latitude = 48.263312668696855, Longitude = 37.37707614898682 },
new() { Latitude = 48.26539817051818, Longitude = 37.36587524414063 },
new() { Latitude = 48.25851283439989, Longitude = 37.35952377319337 },
new() { Latitude = 48.254426906081555, Longitude = 37.374801635742195 },
new() { Latitude = 48.25914140977405, Longitude = 37.39068031311036 },
new() { Latitude = 48.25354110233028, Longitude = 37.401752471923835 },
new() { Latitude = 48.25902712391726, Longitude = 37.416257858276374 },
new() { Latitude = 48.26828345053738, Longitude = 37.402009963989265 }
new() { Lat = 48.276067180586544, Lon = 37.38445758819581 },
new() { Lat = 48.27074009522731, Lon = 37.374029159545906 },
new() { Lat = 48.263312668696855, Lon = 37.37707614898682 },
new() { Lat = 48.26539817051818, Lon = 37.36587524414063 },
new() { Lat = 48.25851283439989, Lon = 37.35952377319337 },
new() { Lat = 48.254426906081555, Lon = 37.374801635742195 },
new() { Lat = 48.25914140977405, Lon = 37.39068031311036 },
new() { Lat = 48.25354110233028, Lon = 37.401752471923835 },
new() { Lat = 48.25902712391726, Lon = 37.416257858276374 },
new() { Lat = 48.26828345053738, Lon = 37.402009963989265 }
},
Geofences = new GeofencesInput
{
Polygons = new List<GeofencePolygonInput>
{
new()
{
NorthWest = new GeoPointInput { Lat = 48.28022277841604, Lon = 37.37548828125001 },
SouthEast = new GeoPointInput { Lat = 48.2720540660028, Lon = 37.3901653289795 }
},
new()
{
NorthWest = new GeoPointInput { Lat = 48.2614270732573, Lon = 37.35239982604981 },
SouthEast = new GeoPointInput { Lat = 48.24988342757033, Lon = 37.37943649291993 }
}
}
}
};
Console.WriteLine("Step 1: Creating complex route with RequestMaps=true");
Console.WriteLine("Step 1: Creating complex route with RequestMaps=true and 2 geofences");
Console.WriteLine($" Action Points: {request.Points.Count}");
Console.WriteLine($" Geofence Regions: {request.Geofences.Polygons.Count}");
Console.WriteLine($" Region Size: {request.RegionSizeMeters}m");
Console.WriteLine($" Zoom Level: {request.ZoomLevel}");
Console.WriteLine($" Request Maps: {request.RequestMaps}");
Console.WriteLine();
Console.WriteLine("Geofence Regions:");
for (int i = 0; i < request.Geofences.Polygons.Count; i++)
{
var polygon = request.Geofences.Polygons[i];
Console.WriteLine($" {i + 1}. NW: ({polygon.NorthWest.Lat}, {polygon.NorthWest.Lon}) -> SE: ({polygon.SouthEast.Lat}, {polygon.SouthEast.Lon})");
}
Console.WriteLine();
Console.WriteLine("Route Path:");
for (int i = 0; i < request.Points.Count; i++)
{
Console.WriteLine($" {i + 1}. ({request.Points[i].Latitude}, {request.Points[i].Longitude})");
Console.WriteLine($" {i + 1}. ({request.Points[i].Lat}, {request.Points[i].Lon})");
}
Console.WriteLine();
var routeResponse = await httpClient.PostAsJsonAsync("/api/satellite/route", request);
var routeResponse = await httpClient.PostAsJsonAsync("/api/satellite/route", request, JsonWriteOptions);
if (!routeResponse.IsSuccessStatusCode)
{
@@ -387,7 +416,7 @@ public static class RouteTests
}
Console.WriteLine("Step 2: Waiting for complex route maps to be ready");
Console.WriteLine(" (Processing 56 regions SEQUENTIALLY to avoid API throttling)");
Console.WriteLine(" (Processing route point regions + 2 geofence regions SEQUENTIALLY to avoid API throttling)");
Console.WriteLine(" (This will take several minutes as each region is processed one at a time)");
Console.WriteLine();
@@ -486,13 +515,14 @@ public static class RouteTests
Console.WriteLine($" Total Points: {finalRoute.TotalPoints}");
Console.WriteLine($" Action Points: {actionPoints}");
Console.WriteLine($" Distance: {finalRoute.TotalDistanceMeters:F2}m");
Console.WriteLine($" Geofence Regions: 2");
Console.WriteLine($" Unique Tiles: {uniqueTileCount}");
Console.WriteLine($" Maps Ready: {finalRoute.MapsReady}");
Console.WriteLine();
if (uniqueTileCount < 10)
{
throw new Exception($"Expected at least 10 unique tiles for complex route, got {uniqueTileCount}");
throw new Exception($"Expected at least 10 unique tiles for complex route with geofences, got {uniqueTileCount}");
}
if (stitchedInfo.Length < 1024)
@@ -500,7 +530,7 @@ public static class RouteTests
throw new Exception($"Stitched image seems too small: {stitchedInfo.Length} bytes");
}
Console.WriteLine("✓ Complex Route with 10 Points Test: PASSED");
Console.WriteLine("✓ Complex Route with 10 Points + 2 Geofences Test: PASSED");
}
public static async Task RunExtendedRouteEast(HttpClient httpClient)
@@ -521,26 +551,26 @@ public static class RouteTests
RequestMaps = true,
Points = new List<RoutePointInput>
{
new() { Latitude = 48.276067180586544, Longitude = 37.51945758819581 },
new() { Latitude = 48.27074009522731, Longitude = 37.509029159545906 },
new() { Latitude = 48.263312668696855, Longitude = 37.51207614898682 },
new() { Latitude = 48.26539817051818, Longitude = 37.50087524414063 },
new() { Latitude = 48.25851283439989, Longitude = 37.49452377319337 },
new() { Latitude = 48.254426906081555, Longitude = 37.509801635742195 },
new() { Latitude = 48.25914140977405, Longitude = 37.52568031311036 },
new() { Latitude = 48.25354110233028, Longitude = 37.536752471923835 },
new() { Latitude = 48.25902712391726, Longitude = 37.551257858276374 },
new() { Latitude = 48.26828345053738, Longitude = 37.537009963989265 },
new() { Latitude = 48.27421563182974, Longitude = 37.52345758819581 },
new() { Latitude = 48.26889854647051, Longitude = 37.513029159545906 },
new() { Latitude = 48.26147111993905, Longitude = 37.51607614898682 },
new() { Latitude = 48.26355662176038, Longitude = 37.50487524414063 },
new() { Latitude = 48.25667128564209, Longitude = 37.49852377319337 },
new() { Latitude = 48.25258535732375, Longitude = 37.513801635742195 },
new() { Latitude = 48.25729986101625, Longitude = 37.52968031311036 },
new() { Latitude = 48.25169955357248, Longitude = 37.540752471923835 },
new() { Latitude = 48.25718557515946, Longitude = 37.555257858276374 },
new() { Latitude = 48.26644190177958, Longitude = 37.541009963989265 }
new() { Lat = 48.276067180586544, Lon = 37.51945758819581 },
new() { Lat = 48.27074009522731, Lon = 37.509029159545906 },
new() { Lat = 48.263312668696855, Lon = 37.51207614898682 },
new() { Lat = 48.26539817051818, Lon = 37.50087524414063 },
new() { Lat = 48.25851283439989, Lon = 37.49452377319337 },
new() { Lat = 48.254426906081555, Lon = 37.509801635742195 },
new() { Lat = 48.25914140977405, Lon = 37.52568031311036 },
new() { Lat = 48.25354110233028, Lon = 37.536752471923835 },
new() { Lat = 48.25902712391726, Lon = 37.551257858276374 },
new() { Lat = 48.26828345053738, Lon = 37.537009963989265 },
new() { Lat = 48.27421563182974, Lon = 37.52345758819581 },
new() { Lat = 48.26889854647051, Lon = 37.513029159545906 },
new() { Lat = 48.26147111993905, Lon = 37.51607614898682 },
new() { Lat = 48.26355662176038, Lon = 37.50487524414063 },
new() { Lat = 48.25667128564209, Lon = 37.49852377319337 },
new() { Lat = 48.25258535732375, Lon = 37.513801635742195 },
new() { Lat = 48.25729986101625, Lon = 37.52968031311036 },
new() { Lat = 48.25169955357248, Lon = 37.540752471923835 },
new() { Lat = 48.25718557515946, Lon = 37.555257858276374 },
new() { Lat = 48.26644190177958, Lon = 37.541009963989265 }
}
};
@@ -554,16 +584,16 @@ public static class RouteTests
Console.WriteLine("Route Path (first 5 and last 5 points):");
for (int i = 0; i < Math.Min(5, request.Points.Count); i++)
{
Console.WriteLine($" {i + 1}. ({request.Points[i].Latitude}, {request.Points[i].Longitude})");
Console.WriteLine($" {i + 1}. ({request.Points[i].Lat}, {request.Points[i].Lon})");
}
Console.WriteLine(" ...");
for (int i = Math.Max(5, request.Points.Count - 5); i < request.Points.Count; i++)
{
Console.WriteLine($" {i + 1}. ({request.Points[i].Latitude}, {request.Points[i].Longitude})");
Console.WriteLine($" {i + 1}. ({request.Points[i].Lat}, {request.Points[i].Lon})");
}
Console.WriteLine();
var routeResponse = await httpClient.PostAsJsonAsync("/api/satellite/route", request);
var routeResponse = await httpClient.PostAsJsonAsync("/api/satellite/route", request, JsonWriteOptions);
if (!routeResponse.IsSuccessStatusCode)
{