mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-04-22 09:06:38 +00:00
less logs
This commit is contained in:
@@ -58,12 +58,6 @@ public class RouteProcessingService : BackgroundService
|
||||
private async Task ProcessPendingRoutesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var pendingRoutes = await GetRoutesWithPendingMapsAsync();
|
||||
|
||||
if (pendingRoutes.Count > 0)
|
||||
{
|
||||
_logger.LogInformation("Processing {Count} route(s) with pending maps: {RouteIds}",
|
||||
pendingRoutes.Count, string.Join(", ", pendingRoutes.Select(r => r.Id)));
|
||||
}
|
||||
|
||||
foreach (var route in pendingRoutes)
|
||||
{
|
||||
@@ -96,20 +90,10 @@ public class RouteProcessingService : BackgroundService
|
||||
return;
|
||||
}
|
||||
|
||||
if (!route.RequestMaps)
|
||||
if (!route.RequestMaps || route.MapsReady)
|
||||
{
|
||||
_logger.LogInformation("Route {RouteId}: RequestMaps=false, skipping processing", routeId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (route.MapsReady)
|
||||
{
|
||||
_logger.LogInformation("Route {RouteId}: MapsReady=true, skipping processing", routeId);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Route {RouteId}: Starting processing check - RequestMaps={RequestMaps}, MapsReady={MapsReady}",
|
||||
routeId, route.RequestMaps, route.MapsReady);
|
||||
|
||||
var routePointsList = (await _routeRepository.GetRoutePointsAsync(routeId)).ToList();
|
||||
var regionIdsList = (await _routeRepository.GetRegionIdsByRouteAsync(routeId)).ToList();
|
||||
@@ -119,23 +103,13 @@ public class RouteProcessingService : BackgroundService
|
||||
|
||||
if (regionIdsList.Count == 0 && routePointsList.Count > 0)
|
||||
{
|
||||
_logger.LogInformation("Route {RouteId}: No route point regions linked yet. Will create regions for {PointCount} route points", routeId, routePointsList.Count);
|
||||
|
||||
using var scope = _serviceProvider.CreateScope();
|
||||
var regionService = scope.ServiceProvider.GetRequiredService<Common.Interfaces.IRegionService>();
|
||||
|
||||
_logger.LogInformation("Route {RouteId}: Starting parallel region processing for {PointCount} points",
|
||||
routeId, routePointsList.Count);
|
||||
|
||||
var queuedRegionIds = new List<Guid>();
|
||||
|
||||
foreach (var point in routePointsList)
|
||||
{
|
||||
var regionId = Guid.NewGuid();
|
||||
|
||||
_logger.LogInformation("RouteProcessingService - Creating region {RegionId} for route {RouteId} at point: Lat={Lat:F12}, Lon={Lon:F12}",
|
||||
regionId, routeId, point.Latitude, point.Longitude);
|
||||
|
||||
await regionService.RequestRegionAsync(
|
||||
regionId,
|
||||
point.Latitude,
|
||||
@@ -145,11 +119,8 @@ public class RouteProcessingService : BackgroundService
|
||||
stitchTiles: false);
|
||||
|
||||
await _routeRepository.LinkRouteToRegionAsync(routeId, regionId);
|
||||
queuedRegionIds.Add(regionId);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Route {RouteId}: Queued all {Count} regions for parallel processing. Region IDs: {RegionIds}",
|
||||
routeId, queuedRegionIds.Count, string.Join(", ", queuedRegionIds.Take(5)) + (queuedRegionIds.Count > 5 ? "..." : ""));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -170,27 +141,16 @@ public class RouteProcessingService : BackgroundService
|
||||
var completedRoutePointRegions = completedRegions.Where(r => !geofenceRegionIdsList.Contains(r.Id)).ToList();
|
||||
var completedGeofenceRegions = completedRegions.Where(r => geofenceRegionIdsList.Contains(r.Id)).ToList();
|
||||
|
||||
_logger.LogInformation("Route {RouteId}: Region counts - Total allRegionIds={AllCount}, regionIdsList={RoutePointCount}, geofenceRegionIdsList={GeofenceCount}",
|
||||
routeId, allRegionIds.Count, regionIdsList.Count, geofenceRegionIdsList.Count);
|
||||
_logger.LogInformation("Route {RouteId}: Status breakdown - Completed={Completed} (RoutePoint={CompletedRP}, Geofence={CompletedGF}), Failed={Failed}, Processing={Processing}",
|
||||
routeId, completedRegions.Count, completedRoutePointRegions.Count, completedGeofenceRegions.Count, failedRegions.Count, processingRegions.Count);
|
||||
|
||||
var hasRoutePointRegions = regionIdsList.Count > 0;
|
||||
var hasEnoughRoutePointRegions = !hasRoutePointRegions || completedRoutePointRegions.Count >= routePointsList.Count;
|
||||
var hasAllGeofenceRegions = geofenceRegionIdsList.Count == 0 || completedGeofenceRegions.Count >= geofenceRegionIdsList.Count;
|
||||
var hasEnoughCompleted = hasEnoughRoutePointRegions && hasAllGeofenceRegions;
|
||||
|
||||
_logger.LogInformation("Route {RouteId}: Condition checks - hasRoutePointRegions={HasRP}, hasEnoughRoutePointRegions={HasEnoughRP} (need {NeedRP}), hasAllGeofenceRegions={HasAllGF} (need {NeedGF}), hasEnoughCompleted={HasEnough}",
|
||||
routeId, hasRoutePointRegions, hasEnoughRoutePointRegions, routePointsList.Count, hasAllGeofenceRegions, geofenceRegionIdsList.Count, hasEnoughCompleted);
|
||||
|
||||
var activeRegions = completedRegions.Count + processingRegions.Count;
|
||||
var shouldRetryFailed = failedRegions.Count > 0 && !hasEnoughCompleted && activeRegions < allRegionIds.Count;
|
||||
|
||||
if (hasEnoughCompleted)
|
||||
{
|
||||
_logger.LogInformation("Route {RouteId}: Have {RoutePointCompleted}/{RoutePointRequired} route point regions and {GeofenceCompleted}/{GeofenceRequired} geofence regions completed. Generating final maps. Ignoring {Processing} processing and {Failed} failed regions.",
|
||||
routeId, completedRoutePointRegions.Count, routePointsList.Count, completedGeofenceRegions.Count, geofenceRegionIdsList.Count, processingRegions.Count, failedRegions.Count);
|
||||
|
||||
var orderedRouteRegions = MatchRegionsToRoutePoints(routePointsList, completedRoutePointRegions, routeId);
|
||||
var routeRegionIds = orderedRouteRegions.Select(r => r.Id).ToList();
|
||||
var allRegionIdsForStitching = routeRegionIds.Concat(completedGeofenceRegions.Select(r => r.Id)).Distinct();
|
||||
@@ -202,17 +162,12 @@ public class RouteProcessingService : BackgroundService
|
||||
|
||||
if (shouldRetryFailed)
|
||||
{
|
||||
_logger.LogWarning("Route {RouteId}: {FailedCount} region(s) failed: {FailedRegions}. Active regions: {ActiveCount}/{RequiredCount}. Attempting to retry with new regions.",
|
||||
routeId, failedRegions.Count, string.Join(", ", failedRegions.Select(r => r.Id)), activeRegions, routePointsList.Count);
|
||||
|
||||
using var scope = _serviceProvider.CreateScope();
|
||||
var regionService = scope.ServiceProvider.GetRequiredService<Common.Interfaces.IRegionService>();
|
||||
|
||||
foreach (var failedRegion in failedRegions)
|
||||
{
|
||||
var newRegionId = Guid.NewGuid();
|
||||
_logger.LogInformation("Route {RouteId}: Retrying failed region {OldRegionId} with new region {NewRegionId}",
|
||||
routeId, failedRegion.Id, newRegionId);
|
||||
|
||||
await regionService.RequestRegionAsync(
|
||||
newRegionId,
|
||||
@@ -225,15 +180,12 @@ public class RouteProcessingService : BackgroundService
|
||||
await _routeRepository.LinkRouteToRegionAsync(routeId, newRegionId);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Route {RouteId}: Queued {Count} retry regions", routeId, failedRegions.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
var anyProcessing = processingRegions.Count > 0;
|
||||
if (anyProcessing)
|
||||
{
|
||||
_logger.LogInformation("Route {RouteId}: Progress - {RoutePointCompleted}/{RoutePointRequired} route point regions, {GeofenceCompleted}/{GeofenceRequired} geofence regions completed, {Processing} still processing, {Failed} failed (will retry if needed)",
|
||||
routeId, completedRoutePointRegions.Count, routePointsList.Count, completedGeofenceRegions.Count, geofenceRegionIdsList.Count, processingRegions.Count, failedRegions.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -266,11 +218,6 @@ public class RouteProcessingService : BackgroundService
|
||||
_logger.LogWarning("Route {RouteId}: Region {RegionId} CSV not found", routeId, regionId);
|
||||
continue;
|
||||
}
|
||||
|
||||
var isGeofence = geofenceRegionIds.Contains(regionId);
|
||||
_logger.LogInformation("Route {RouteId}: Processing region {RegionId} ({Type}) - Lat={Lat}, Lon={Lon}, Size={Size}m, CSV={CsvPath}",
|
||||
routeId, regionId, isGeofence ? "GEOFENCE" : "RoutePoint",
|
||||
region.Latitude, region.Longitude, region.SizeMeters, region.CsvFilePath);
|
||||
|
||||
var csvLines = await File.ReadAllLinesAsync(region.CsvFilePath, cancellationToken);
|
||||
|
||||
@@ -283,22 +230,14 @@ public class RouteProcessingService : BackgroundService
|
||||
|
||||
if (!double.TryParse(parts[0], out var lat))
|
||||
{
|
||||
_logger.LogWarning("Route {RouteId} - Failed to parse latitude from CSV line {LineNumber}: {Line}", routeId, lineNumber, line);
|
||||
continue;
|
||||
}
|
||||
if (!double.TryParse(parts[1], out var lon))
|
||||
{
|
||||
_logger.LogWarning("Route {RouteId} - Failed to parse longitude from CSV line {LineNumber}: {Line}", routeId, lineNumber, line);
|
||||
continue;
|
||||
}
|
||||
var filePath = parts[2];
|
||||
|
||||
if (lineNumber <= 3)
|
||||
{
|
||||
_logger.LogInformation("Route {RouteId} - Reading tile from region {RegionId} CSV: Lat={Lat:F12}, Lon={Lon:F12}",
|
||||
routeId, regionId, lat, lon);
|
||||
}
|
||||
|
||||
totalTilesFromRegions++;
|
||||
var key = $"{lat:F6}_{lon:F6}";
|
||||
|
||||
@@ -318,9 +257,6 @@ public class RouteProcessingService : BackgroundService
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("Route {RouteId}: Collected {UniqueCount} unique tiles ({DuplicateCount} duplicates from {TotalCount} total)",
|
||||
routeId, allTiles.Count, duplicateTiles, totalTilesFromRegions);
|
||||
|
||||
var csvPath = Path.Combine(readyDir, $"route_{routeId}_ready.csv");
|
||||
await GenerateRouteCsvAsync(csvPath, allTiles.Values, cancellationToken);
|
||||
|
||||
@@ -363,8 +299,6 @@ public class RouteProcessingService : BackgroundService
|
||||
if (minX.HasValue && minY.HasValue && maxX.HasValue && maxY.HasValue)
|
||||
{
|
||||
geofencePolygonBounds.Add((minX.Value, minY.Value, maxX.Value, maxY.Value));
|
||||
_logger.LogInformation("Route {RouteId}: Polygon {PolygonIndex} tile bounds: X=[{MinX}..{MaxX}], Y=[{MinY}..{MaxY}]",
|
||||
routeId, polygonIndex, minX.Value, maxX.Value, minY.Value, maxY.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,11 +426,6 @@ public class RouteProcessingService : BackgroundService
|
||||
var imageWidth = gridWidth * tileSizePixels;
|
||||
var imageHeight = gridHeight * tileSizePixels;
|
||||
|
||||
_logger.LogInformation("Stitching route map: {Width}x{Height} pixels (grid: {GridWidth}x{GridHeight} tiles)",
|
||||
imageWidth, imageHeight, gridWidth, gridHeight);
|
||||
_logger.LogInformation("Bounding box: top={MinY}, left={MinX}, bottom={MaxY}, right={MaxX}",
|
||||
minY, minX, maxY, maxX);
|
||||
|
||||
using var stitchedImage = new Image<Rgb24>(imageWidth, imageHeight);
|
||||
stitchedImage.Mutate(ctx => ctx.BackgroundColor(Color.Black));
|
||||
|
||||
@@ -507,14 +436,6 @@ public class RouteProcessingService : BackgroundService
|
||||
.ThenBy(t => t.TileX)
|
||||
.ToList();
|
||||
|
||||
_logger.LogInformation("Unique tiles to place: {Count}", uniqueTileCoords.Count);
|
||||
_logger.LogInformation("Sample tiles (first 5):");
|
||||
foreach (var sample in uniqueTileCoords.Take(5))
|
||||
{
|
||||
_logger.LogInformation(" Tile ({TileX}, {TileY}) from ({Lat:F6}, {Lon:F6})",
|
||||
sample.TileX, sample.TileY, sample.Latitude, sample.Longitude);
|
||||
}
|
||||
|
||||
int placedTiles = 0;
|
||||
int missingTiles = 0;
|
||||
|
||||
@@ -529,20 +450,8 @@ public class RouteProcessingService : BackgroundService
|
||||
{
|
||||
using var tileImage = await Image.LoadAsync<Rgb24>(tile.FilePath, cancellationToken);
|
||||
|
||||
if (tileImage.Width != tileSizePixels || tileImage.Height != tileSizePixels)
|
||||
{
|
||||
_logger.LogWarning("Tile {FilePath} has wrong size {Width}x{Height}, expected {ExpectedWidth}x{ExpectedHeight}",
|
||||
tile.FilePath, tileImage.Width, tileImage.Height, tileSizePixels, tileSizePixels);
|
||||
}
|
||||
|
||||
stitchedImage.Mutate(ctx => ctx.DrawImage(tileImage, new Point(destX, destY), 1f));
|
||||
placedTiles++;
|
||||
|
||||
if (placedTiles <= 3)
|
||||
{
|
||||
_logger.LogInformation("Placed tile {Count}: ({TileX},{TileY}) at pixel ({DestX},{DestY})",
|
||||
placedTiles, tile.TileX, tile.TileY, destX, destY);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -559,24 +468,15 @@ public class RouteProcessingService : BackgroundService
|
||||
|
||||
if (geofencePolygonBounds.Count > 0)
|
||||
{
|
||||
_logger.LogInformation("Drawing {Count} geofence polygon borders on image {Width}x{Height} (grid: minX={MinX}, minY={MinY})",
|
||||
geofencePolygonBounds.Count, imageWidth, imageHeight, minX, minY);
|
||||
|
||||
for (int i = 0; i < geofencePolygonBounds.Count; i++)
|
||||
{
|
||||
var (geoMinX, geoMinY, geoMaxX, geoMaxY) = geofencePolygonBounds[i];
|
||||
|
||||
_logger.LogInformation("Polygon {Index}: Tile range - X=[{MinX}..{MaxX}], Y=[{MinY}..{MaxY}]",
|
||||
i, geoMinX, geoMaxX, geoMinY, geoMaxY);
|
||||
|
||||
var x1 = (geoMinX - minX) * tileSizePixels;
|
||||
var y1 = (geoMinY - minY + 1) * tileSizePixels;
|
||||
var x2 = (geoMaxX - minX + 2) * tileSizePixels - 1;
|
||||
var y2 = (geoMaxY - minY + 1) * tileSizePixels - 1;
|
||||
|
||||
_logger.LogInformation("Polygon {Index}: Pixel coords before clipping - ({X1},{Y1}) to ({X2},{Y2})",
|
||||
i, x1, y1, x2, y2);
|
||||
|
||||
x1 = Math.Max(0, Math.Min(x1, imageWidth - 1));
|
||||
y1 = Math.Max(0, Math.Min(y1, imageHeight - 1));
|
||||
x2 = Math.Max(0, Math.Min(x2, imageWidth - 1));
|
||||
@@ -584,22 +484,10 @@ public class RouteProcessingService : BackgroundService
|
||||
|
||||
if (x1 >= 0 && y1 >= 0 && x2 < imageWidth && y2 < imageHeight && x2 > x1 && y2 > y1)
|
||||
{
|
||||
_logger.LogInformation("Polygon {Index}: Drawing border at pixel coords ({X1},{Y1}) to ({X2},{Y2})",
|
||||
i, x1, y1, x2, y2);
|
||||
|
||||
DrawRectangleBorder(stitchedImage, x1, y1, x2, y2, new Rgb24(255, 255, 0));
|
||||
|
||||
_logger.LogInformation("Polygon {Index}: Successfully drew geofence border", i);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Polygon {Index}: Border out of bounds or invalid - ({X1},{Y1}) to ({X2},{Y2}), image size: {Width}x{Height}",
|
||||
i, x1, y1, x2, y2, imageWidth, imageHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("Drawing {Count} route point crosses on map", routePoints.Count);
|
||||
|
||||
foreach (var point in routePoints)
|
||||
{
|
||||
@@ -614,20 +502,8 @@ public class RouteProcessingService : BackgroundService
|
||||
DrawCross(stitchedImage, pixelX, pixelY, new Rgb24(255, 0, 0), 50);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("Finished drawing route point crosses");
|
||||
|
||||
await stitchedImage.SaveAsJpegAsync(outputPath, cancellationToken);
|
||||
|
||||
var totalPossibleTiles = gridWidth * gridHeight;
|
||||
var uncoveredTiles = totalPossibleTiles - placedTiles - missingTiles;
|
||||
|
||||
_logger.LogInformation("Route map stitched: {OutputPath}", outputPath);
|
||||
_logger.LogInformation(" Tiles placed: {PlacedTiles}", placedTiles);
|
||||
_logger.LogInformation(" Tiles missing (file issues): {MissingTiles}", missingTiles);
|
||||
_logger.LogInformation(" Uncovered area (black): {UncoveredTiles} tiles", uncoveredTiles);
|
||||
_logger.LogInformation(" Total canvas: {TotalTiles} tiles ({GridWidth}x{GridHeight})",
|
||||
totalPossibleTiles, gridWidth, gridHeight);
|
||||
}
|
||||
|
||||
private List<DataAccess.Models.RegionEntity> MatchRegionsToRoutePoints(
|
||||
@@ -648,16 +524,6 @@ public class RouteProcessingService : BackgroundService
|
||||
{
|
||||
orderedRegions.Add(matchedRegion);
|
||||
availableRegions.Remove(matchedRegion);
|
||||
|
||||
var distance = CalculateDistance(point.Latitude, point.Longitude, matchedRegion.Latitude, matchedRegion.Longitude);
|
||||
_logger.LogInformation("Route {RouteId}: Matched route point Seq={Seq} ({Lat:F6},{Lon:F6}) to region {RegionId} ({RegLat:F6},{RegLon:F6}), distance={Distance:F2}m",
|
||||
routeId, point.SequenceNumber, point.Latitude, point.Longitude,
|
||||
matchedRegion.Id, matchedRegion.Latitude, matchedRegion.Longitude, distance);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Route {RouteId}: No region found for route point Seq={Seq} ({Lat:F6},{Lon:F6})",
|
||||
routeId, point.SequenceNumber, point.Latitude, point.Longitude);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user