fix throttle ext

fix configs
fix build scripts
This commit is contained in:
Alex Bezdieniezhnykh
2025-04-17 19:40:09 +03:00
parent 277aaf09b0
commit d42409de7d
9 changed files with 21 additions and 61 deletions
@@ -6,7 +6,7 @@ public static class ThrottleExt
{
private class ThrottleState(Func<Task> action)
{
public Func<Task> Action { get; } = action ?? throw new ArgumentNullException(nameof(action));
public Func<Task> 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<Guid, ThrottleState> ThrottlerStates = new();
public static void Throttle(Func<Task> action, Guid actionId, TimeSpan interval)
public static void Throttle(Func<Task> 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,6 +35,7 @@ public static class ThrottleExt
}
else
{
if (scheduleCallAfterCooldown)
state.CallScheduledDuringCooldown = true;
}
}
+1 -1
View File
@@ -80,7 +80,7 @@ public class AnnotationService : INotificationHandler<AnnotationsDeletedEvent>
{
_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;
+1 -1
View File
@@ -17,7 +17,7 @@ public interface IGpsMatcherService
public class GpsMatcherService(IGpsMatcherClient gpsMatcherClient, ISatelliteDownloader satelliteTileDownloader, IOptions<DirectoriesConfig> 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);
@@ -104,51 +104,6 @@ public class SatelliteDownloader(
await Task.Run(() => Parallel.ForEach(cropTasks, action => action()), token);
}
private async Task SplitToTiles_OLD(Image<Rgba32> 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<Image<Rgba32>?> ComposeTiles(ConcurrentDictionary<(int x, int y), byte[]> downloadedTiles, CancellationToken token = default)
{
if (downloadedTiles.IsEmpty)
-2
View File
@@ -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')
+1
View File
@@ -182,6 +182,7 @@ public partial class App
services.ConfigureSection<AIRecognitionConfig>(context.Configuration);
services.ConfigureSection<ThumbnailConfig>(context.Configuration);
services.ConfigureSection<UIConfig>(context.Configuration);
services.ConfigureSection<MapConfig>(context.Configuration);
#region External Services
+3 -1
View File
@@ -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,
+3 -1
View File
@@ -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