route stitching

This commit is contained in:
Anton Martynenko
2025-11-01 16:54:46 +01:00
parent 8714a4817d
commit 11395ec913
15 changed files with 698 additions and 10 deletions
@@ -58,6 +58,7 @@ public class CreateRouteRequest
public double RegionSizeMeters { get; set; }
public int ZoomLevel { get; set; }
public List<RoutePointInput> Points { get; set; } = new();
public bool RequestMaps { get; set; } = false;
}
public class RoutePointModel
@@ -80,6 +81,11 @@ public class RouteResponseModel
public double TotalDistanceMeters { get; set; }
public int TotalPoints { get; set; }
public List<RoutePointModel> Points { get; set; } = new();
public bool RequestMaps { get; set; }
public bool MapsReady { get; set; }
public string? CsvFilePath { get; set; }
public string? SummaryFilePath { get; set; }
public string? StitchedImagePath { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
@@ -34,6 +34,8 @@ class Program
await RouteTests.RunSimpleRouteTest(httpClient);
await RouteTests.RunRouteWithRegionProcessingAndStitching(httpClient);
Console.WriteLine();
Console.WriteLine("=========================");
Console.WriteLine("All tests completed successfully!");
@@ -117,5 +117,171 @@ public static class RouteTests
Console.WriteLine();
Console.WriteLine("Simple Route Test: PASSED");
}
public static async Task RunRouteWithRegionProcessingAndStitching(HttpClient httpClient)
{
Console.WriteLine();
Console.WriteLine("Test: Route with Region Processing and Full Map Stitching (Service-Level)");
Console.WriteLine("===========================================================================");
Console.WriteLine();
var routeId = Guid.NewGuid();
var request = new CreateRouteRequest
{
Id = routeId,
Name = "Route with Region Processing",
Description = "Test route that processes regions for all points and stitches a full map",
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 }
}
};
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($" 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);
if (!routeResponse.IsSuccessStatusCode)
{
var errorContent = await routeResponse.Content.ReadAsStringAsync();
throw new Exception($"Route creation failed: {routeResponse.StatusCode} - {errorContent}");
}
var route = await routeResponse.Content.ReadFromJsonAsync<RouteResponseModel>(JsonOptions);
if (route == null)
{
throw new Exception("No route data returned");
}
Console.WriteLine($"✓ Route created with {route.TotalPoints} points");
Console.WriteLine($" Distance: {route.TotalDistanceMeters:F2}m");
Console.WriteLine($" Request Maps: {route.RequestMaps}");
Console.WriteLine($" Maps Ready: {route.MapsReady}");
Console.WriteLine();
if (!route.RequestMaps)
{
throw new Exception("Expected RequestMaps to be true");
}
if (route.MapsReady)
{
throw new Exception("Expected MapsReady to be false initially");
}
Console.WriteLine("Step 2: Waiting for route maps to be ready");
Console.WriteLine(" (Service is processing regions and stitching automatically)");
Console.WriteLine();
RouteResponseModel? finalRoute = null;
int maxAttempts = 180;
int pollInterval = 3000;
for (int attempt = 0; attempt < maxAttempts; attempt++)
{
await Task.Delay(pollInterval);
var getResponse = await httpClient.GetAsync($"/api/satellite/route/{routeId}");
if (!getResponse.IsSuccessStatusCode)
{
throw new Exception($"Failed to get route status: {getResponse.StatusCode}");
}
var currentRoute = await getResponse.Content.ReadFromJsonAsync<RouteResponseModel>(JsonOptions);
if (currentRoute == null)
{
throw new Exception("No route returned");
}
if (currentRoute.MapsReady)
{
finalRoute = currentRoute;
Console.WriteLine($"✓ Route maps ready in approximately {attempt * pollInterval / 1000}s");
break;
}
if (attempt % 5 == 0)
{
Console.WriteLine($" Waiting... (attempt {attempt + 1}/{maxAttempts})");
}
if (attempt == maxAttempts - 1)
{
throw new Exception($"Timeout: Route maps did not become ready in {maxAttempts * pollInterval / 1000}s");
}
}
if (finalRoute == null)
{
throw new Exception("Final route is null");
}
Console.WriteLine();
Console.WriteLine("Step 3: Verifying generated files");
if (string.IsNullOrEmpty(finalRoute.CsvFilePath))
{
throw new Exception("CSV file path is null or empty");
}
if (string.IsNullOrEmpty(finalRoute.SummaryFilePath))
{
throw new Exception("Summary file path is null or empty");
}
if (string.IsNullOrEmpty(finalRoute.StitchedImagePath))
{
throw new Exception("Stitched image path is null or empty");
}
if (!File.Exists(finalRoute.CsvFilePath))
{
throw new Exception($"CSV file not found: {finalRoute.CsvFilePath}");
}
if (!File.Exists(finalRoute.SummaryFilePath))
{
throw new Exception($"Summary file not found: {finalRoute.SummaryFilePath}");
}
if (!File.Exists(finalRoute.StitchedImagePath))
{
throw new Exception($"Stitched image not found: {finalRoute.StitchedImagePath}");
}
var csvLines = await File.ReadAllLinesAsync(finalRoute.CsvFilePath);
var uniqueTileCount = csvLines.Length - 1;
var stitchedInfo = new FileInfo(finalRoute.StitchedImagePath);
Console.WriteLine("Files Generated:");
Console.WriteLine($" ✓ CSV: {Path.GetFileName(finalRoute.CsvFilePath)} ({uniqueTileCount} tiles)");
Console.WriteLine($" ✓ Summary: {Path.GetFileName(finalRoute.SummaryFilePath)}");
Console.WriteLine($" ✓ Stitched Map: {Path.GetFileName(finalRoute.StitchedImagePath)} ({stitchedInfo.Length / 1024:F2} KB)");
Console.WriteLine();
Console.WriteLine("Route Summary:");
Console.WriteLine($" Route ID: {finalRoute.Id}");
Console.WriteLine($" Route Points: {finalRoute.TotalPoints}");
Console.WriteLine($" Distance: {finalRoute.TotalDistanceMeters:F2}m");
Console.WriteLine($" Unique Tiles: {uniqueTileCount}");
Console.WriteLine($" Maps Ready: {finalRoute.MapsReady}");
Console.WriteLine();
Console.WriteLine("✓ Route with Region Processing and Stitching Test: PASSED");
}
}