less logs

This commit is contained in:
Anton Martynenko
2025-11-19 18:18:19 +01:00
parent eff7ca4dba
commit 48ebad0609
7 changed files with 3 additions and 314 deletions
@@ -36,9 +36,6 @@ public class RegionService : IRegionService
public async Task<RegionStatus> RequestRegionAsync(Guid id, double latitude, double longitude, double sizeMeters, int zoomLevel, bool stitchTiles = false)
{
_logger.LogInformation("RegionService - Requesting region {RegionId}: Lat={Lat:F12}, Lon={Lon:F12}, Size={Size}m, Zoom={Zoom}",
id, latitude, longitude, sizeMeters, zoomLevel);
var now = DateTime.UtcNow;
var region = new RegionEntity
{
@@ -69,8 +66,6 @@ public class RegionService : IRegionService
await _queue.EnqueueAsync(request);
_logger.LogInformation("Region {RegionId} queued for processing", id);
return MapToStatus(region);
}
@@ -82,7 +77,6 @@ public class RegionService : IRegionService
public async Task ProcessRegionAsync(Guid id, CancellationToken cancellationToken = default)
{
_logger.LogInformation("Processing region {RegionId} - START", id);
var startTime = DateTime.UtcNow;
var region = await _regionRepository.GetByIdAsync(id);
@@ -92,12 +86,10 @@ public class RegionService : IRegionService
return;
}
_logger.LogInformation("Region {RegionId}: Updating status to 'processing' (was: {OldStatus})", id, region.Status);
region.Status = "processing";
region.UpdatedAt = DateTime.UtcNow;
await _regionRepository.UpdateAsync(region);
_logger.LogInformation("Region {RegionId}: Creating timeout CTS (5 minutes)", id);
using var timeoutCts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutCts.Token);
@@ -108,35 +100,25 @@ public class RegionService : IRegionService
try
{
_logger.LogInformation("Region {RegionId}: Step 1 - Starting download for location ({Lat}, {Lon}) size {Size}m zoom {Zoom}",
id, region.Latitude, region.Longitude, region.SizeMeters, region.ZoomLevel);
var processingStartTime = DateTime.UtcNow;
_logger.LogInformation("Region {RegionId}: Step 2 - Checking for existing tiles", id);
var tilesBeforeDownload = await _tileService.GetTilesByRegionAsync(
region.Latitude,
region.Longitude,
region.SizeMeters,
region.ZoomLevel);
var existingTileIds = new HashSet<Guid>(tilesBeforeDownload.Select(t => t.Id));
_logger.LogInformation("Region {RegionId}: Step 3 - Found {Count} existing tiles", id, existingTileIds.Count);
_logger.LogInformation("Region {RegionId}: Step 4 - Calling DownloadAndStoreTilesAsync", id);
tiles = await _tileService.DownloadAndStoreTilesAsync(
region.Latitude,
region.Longitude,
region.SizeMeters,
region.ZoomLevel,
linkedCts.Token);
_logger.LogInformation("Region {RegionId}: Step 5 - DownloadAndStoreTilesAsync completed with {Count} tiles", id, tiles.Count);
tilesDownloaded = tiles.Count(t => !existingTileIds.Contains(t.Id));
tilesReused = tiles.Count(t => existingTileIds.Contains(t.Id));
_logger.LogInformation("Region {RegionId}: Step 6 - Downloaded {Downloaded} new tiles, Reused {Reused} existing tiles",
id, tilesDownloaded, tilesReused);
var readyDir = _storageConfig.ReadyDirectory;
Directory.CreateDirectory(readyDir);
@@ -149,13 +131,8 @@ public class RegionService : IRegionService
if (region.StitchTiles)
{
stitchedImagePath = Path.Combine(readyDir, $"region_{id}_stitched.jpg");
_logger.LogInformation("Stitching tiles for region {RegionId}", id);
await StitchTilesAsync(tiles, region.Latitude, region.Longitude, region.ZoomLevel, stitchedImagePath, linkedCts.Token);
}
else
{
_logger.LogInformation("Skipping tile stitching for region {RegionId}", id);
}
await GenerateSummaryFileAsync(summaryPath, id, region, tiles, tilesDownloaded, tilesReused, stitchedImagePath, processingStartTime, linkedCts.Token, errorMessage);
@@ -166,9 +143,6 @@ public class RegionService : IRegionService
region.TilesReused = tilesReused;
region.UpdatedAt = DateTime.UtcNow;
await _regionRepository.UpdateAsync(region);
var duration = (DateTime.UtcNow - startTime).TotalSeconds;
_logger.LogInformation("Region {RegionId} processing completed in {Duration:F2}s", id, duration);
}
catch (TaskCanceledException ex) when (timeoutCts.IsCancellationRequested)
{
@@ -293,9 +267,6 @@ public class RegionService : IRegionService
var imageWidth = gridWidth * tileSizePixels;
var imageHeight = gridHeight * tileSizePixels;
_logger.LogInformation("Stitching {Count} tiles into {Width}x{Height} image (grid: {GridWidth}x{GridHeight})",
tiles.Count, imageWidth, imageHeight, gridWidth, gridHeight);
using var stitchedImage = new Image<Rgb24>(imageWidth, imageHeight);
foreach (var (x, y, filePath) in tileCoords)
@@ -323,9 +294,6 @@ public class RegionService : IRegionService
var crossX = (int)Math.Round((centerTileX - minX) * tileSizePixels + centerTilePixelX);
var crossY = (int)Math.Round((centerTileY - minY) * tileSizePixels + centerTilePixelY);
_logger.LogInformation("Drawing red cross at pixel position ({X}, {Y}) for coordinates ({Lat}, {Lon})",
crossX, crossY, centerLatitude, centerLongitude);
var red = new Rgb24(255, 0, 0);
stitchedImage.Mutate(ctx =>
{
@@ -347,7 +315,6 @@ public class RegionService : IRegionService
});
await stitchedImage.SaveAsJpegAsync(outputPath, cancellationToken);
_logger.LogInformation("Stitched image saved to {OutputPath}", outputPath);
return outputPath;
}
@@ -356,12 +323,6 @@ public class RegionService : IRegionService
{
var orderedTiles = tiles.OrderByDescending(t => t.Latitude).ThenBy(t => t.Longitude).ToList();
if (orderedTiles.Any())
{
_logger.LogInformation("RegionService - Writing CSV with {Count} tiles. First tile: Lat={Lat:F12}, Lon={Lon:F12}",
orderedTiles.Count, orderedTiles[0].Latitude, orderedTiles[0].Longitude);
}
using var writer = new StreamWriter(filePath);
await writer.WriteLineAsync("latitude,longitude,file_path");