From d42409de7d91cf63bd4993c34bded8bbcba1e343 Mon Sep 17 00:00:00 2001 From: Alex Bezdieniezhnykh Date: Thu, 17 Apr 2025 19:40:09 +0300 Subject: [PATCH] fix throttle ext fix configs fix build scripts --- Azaion.Common/DTO/Config/AppConfig.cs | 14 +++--- .../Extensions/ThrottleExtensions.cs | 8 ++-- Azaion.Common/Services/AnnotationService.cs | 2 +- Azaion.Common/Services/GPSMatcherService.cs | 2 +- Azaion.Common/Services/SatelliteDownloader.cs | 45 ------------------- Azaion.Inference/azaion-inference.spec | 2 - Azaion.Suite/App.xaml.cs | 1 + Azaion.Suite/config.json | 4 +- build/build_downloader.cmd | 4 +- 9 files changed, 21 insertions(+), 61 deletions(-) diff --git a/Azaion.Common/DTO/Config/AppConfig.cs b/Azaion.Common/DTO/Config/AppConfig.cs index b03f988..7d94ab3 100644 --- a/Azaion.Common/DTO/Config/AppConfig.cs +++ b/Azaion.Common/DTO/Config/AppConfig.cs @@ -12,19 +12,19 @@ public class AppConfig public GpsDeniedClientConfig GpsDeniedClientConfig { get; set; } = null!; - public QueueConfig QueueConfig { get; set; } = null!; + public QueueConfig QueueConfig { get; set; } = null!; - public DirectoriesConfig DirectoriesConfig { get; set; } = null!; + public DirectoriesConfig DirectoriesConfig { get; set; } = null!; - public AnnotationConfig AnnotationConfig { get; set; } = null!; + public AnnotationConfig AnnotationConfig { get; set; } = null!; - public UIConfig UIConfig { get; set; } = null!; + public UIConfig UIConfig { get; set; } = null!; - public AIRecognitionConfig AIRecognitionConfig { get; set; } = null!; + public AIRecognitionConfig AIRecognitionConfig { get; set; } = null!; - public ThumbnailConfig ThumbnailConfig { get; set; } = null!; + public ThumbnailConfig ThumbnailConfig { get; set; } = null!; - public MapConfig MapConfig{ get; set; } = null!; + public MapConfig MapConfig{ get; set; } = null!; } public interface IConfigUpdater diff --git a/Azaion.Common/Extensions/ThrottleExtensions.cs b/Azaion.Common/Extensions/ThrottleExtensions.cs index a210621..219374f 100644 --- a/Azaion.Common/Extensions/ThrottleExtensions.cs +++ b/Azaion.Common/Extensions/ThrottleExtensions.cs @@ -6,7 +6,7 @@ public static class ThrottleExt { private class ThrottleState(Func action) { - public Func Action { get; } = action ?? throw new ArgumentNullException(nameof(action)); + public Func Action { get; set; } = action ?? throw new ArgumentNullException(nameof(action)); public bool IsCoolingDown = false; public bool CallScheduledDuringCooldown = false; public Task CooldownTask = Task.CompletedTask; @@ -15,7 +15,7 @@ public static class ThrottleExt private static readonly ConcurrentDictionary ThrottlerStates = new(); - public static void Throttle(Func action, Guid actionId, TimeSpan interval) + public static void Throttle(Func action, Guid actionId, TimeSpan interval, bool scheduleCallAfterCooldown = false) { ArgumentNullException.ThrowIfNull(action); if (actionId == Guid.Empty) @@ -24,6 +24,7 @@ public static class ThrottleExt throw new ArgumentOutOfRangeException(nameof(interval), "Interval must be positive."); var state = ThrottlerStates.GetOrAdd(actionId, new ThrottleState(action)); + state.Action = action; lock (state.StateLock) { @@ -34,7 +35,8 @@ public static class ThrottleExt } else { - state.CallScheduledDuringCooldown = true; + if (scheduleCallAfterCooldown) + state.CallScheduledDuringCooldown = true; } } } diff --git a/Azaion.Common/Services/AnnotationService.cs b/Azaion.Common/Services/AnnotationService.cs index 293ad4f..ab6fa21 100644 --- a/Azaion.Common/Services/AnnotationService.cs +++ b/Azaion.Common/Services/AnnotationService.cs @@ -80,7 +80,7 @@ public class AnnotationService : INotificationHandler { _api.UpdateOffsets(offsets); return Task.CompletedTask; - }, SaveTaskId, TimeSpan.FromSeconds(10)); + }, SaveTaskId, TimeSpan.FromSeconds(10), scheduleCallAfterCooldown: true); if (msg.CreatedEmail == _api.CurrentUser.Email) //Don't process messages by yourself return; diff --git a/Azaion.Common/Services/GPSMatcherService.cs b/Azaion.Common/Services/GPSMatcherService.cs index 03c4370..9883c5a 100644 --- a/Azaion.Common/Services/GPSMatcherService.cs +++ b/Azaion.Common/Services/GPSMatcherService.cs @@ -17,7 +17,7 @@ public interface IGpsMatcherService public class GpsMatcherService(IGpsMatcherClient gpsMatcherClient, ISatelliteDownloader satelliteTileDownloader, IOptions dirConfig) : IGpsMatcherService { private const int ZOOM_LEVEL = 18; - private const int POINTS_COUNT = 10; + private const int POINTS_COUNT = 5; private const int DISTANCE_BETWEEN_POINTS_M = 100; private const double SATELLITE_RADIUS_M = DISTANCE_BETWEEN_POINTS_M * (POINTS_COUNT + 1); diff --git a/Azaion.Common/Services/SatelliteDownloader.cs b/Azaion.Common/Services/SatelliteDownloader.cs index 7c7d0be..867980d 100644 --- a/Azaion.Common/Services/SatelliteDownloader.cs +++ b/Azaion.Common/Services/SatelliteDownloader.cs @@ -104,51 +104,6 @@ public class SatelliteDownloader( await Task.Run(() => Parallel.ForEach(cropTasks, action => action()), token); } - private async Task SplitToTiles_OLD(Image image, DownloadTilesResult bounds, CancellationToken token = default) - { - ArgumentNullException.ThrowIfNull(image); - ArgumentNullException.ThrowIfNull(bounds); - - if (bounds.LatMax <= bounds.LatMin || bounds.LonMax <= bounds.LonMin || image.Width <= 0 || image.Height <= 0) - throw new ArgumentException("Invalid coordinate bounds (LatMax <= LatMin or LonMax <= LonMin) or image dimensions (Width/Height <= 0)."); - - var latRange = bounds.LatMax - bounds.LatMin; - var lonRange = bounds.LonMax - bounds.LonMin; - var degreesPerPixelLat = latRange / image.Height; - var degreesPerPixelLon = lonRange / image.Width; - - var rowIndex = 0; - for (int top = 0; top <= image.Height - CROP_HEIGHT; top += STEP_Y) - { - token.ThrowIfCancellationRequested(); - int colIndex = 0; - for (int left = 0; left <= image.Width - CROP_WIDTH; left += STEP_X) - { - token.ThrowIfCancellationRequested(); - - var cropBox = new Rectangle(left, top, CROP_WIDTH, CROP_HEIGHT); - - using (var croppedImage = image.Clone(ctx => ctx.Crop(cropBox))) - { - var cropTlLat = bounds.LatMax - (top * degreesPerPixelLat); - var cropTlLon = bounds.LonMin + (left * degreesPerPixelLon); - var cropBrLat = cropTlLat - (CROP_HEIGHT * degreesPerPixelLat); - var cropBrLon = cropTlLon + (CROP_WIDTH * degreesPerPixelLon); - - var outputFilename = Path.Combine(_satDirectory, - $"map_{rowIndex:D4}_{colIndex:D4}_tl_{cropTlLat:F6}_{cropTlLon:F6}_br_{cropBrLat:F6}_{cropBrLon:F6}.tif" - ); - - using (var resizedImage = croppedImage.Clone(ctx => ctx.Resize(OUTPUT_TILE_SIZE, OUTPUT_TILE_SIZE, KnownResamplers.Lanczos3))) - await resizedImage.SaveAsTiffAsync(outputFilename, token); - } - colIndex++; - } - rowIndex++; - } - } - - private async Task?> ComposeTiles(ConcurrentDictionary<(int x, int y), byte[]> downloadedTiles, CancellationToken token = default) { if (downloadedTiles.IsEmpty) diff --git a/Azaion.Inference/azaion-inference.spec b/Azaion.Inference/azaion-inference.spec index 37f6901..a01fda6 100644 --- a/Azaion.Inference/azaion-inference.spec +++ b/Azaion.Inference/azaion-inference.spec @@ -4,8 +4,6 @@ from PyInstaller.utils.hooks import collect_all datas = [] binaries = [] hiddenimports = ['constants', 'annotation', 'credentials', 'file_data', 'user', 'security', 'secure_model', 'api_client', 'hardware_service', 'remote_command', 'ai_config', 'inference_engine', 'inference', 'remote_command_handler'] -tmp_ret = collect_all('pyyaml') -datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2] tmp_ret = collect_all('jwt') datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2] tmp_ret = collect_all('requests') diff --git a/Azaion.Suite/App.xaml.cs b/Azaion.Suite/App.xaml.cs index 85ddb8f..7c41de7 100644 --- a/Azaion.Suite/App.xaml.cs +++ b/Azaion.Suite/App.xaml.cs @@ -182,6 +182,7 @@ public partial class App services.ConfigureSection(context.Configuration); services.ConfigureSection(context.Configuration); services.ConfigureSection(context.Configuration); + services.ConfigureSection(context.Configuration); #region External Services diff --git a/Azaion.Suite/config.json b/Azaion.Suite/config.json index 3f0cdf1..2fa431d 100644 --- a/Azaion.Suite/config.json +++ b/Azaion.Suite/config.json @@ -18,7 +18,9 @@ "LabelsDirectory": "E:\\labels", "ImagesDirectory": "E:\\images", "ResultsDirectory": "E:\\results", - "ThumbnailsDirectory": "E:\\thumbnails" + "ThumbnailsDirectory": "E:\\thumbnails", + "GpsSatDirectory": "satellitesDir", + "GpsRouteDirectory": "routeDir" }, "UIConfig": { "LeftPanelWidth": 220.0, diff --git a/build/build_downloader.cmd b/build/build_downloader.cmd index d8a0e03..94b0cd6 100644 --- a/build/build_downloader.cmd +++ b/build/build_downloader.cmd @@ -1,4 +1,6 @@ -pyinstaller --onefile --collect-all boto3 cdn_manager.py +python -m venv venv +venv\Scripts\pip install -r requirements.txt +venv\Scripts\pyinstaller --onefile --collect-all boto3 cdn_manager.py move dist\cdn_manager.exe .\cdn_manager.exe rmdir /s /q dist rmdir /s /q build