mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-04-22 08:56:38 +00:00
first region implementation
This commit is contained in:
@@ -33,6 +33,8 @@ class Program
|
||||
Console.WriteLine();
|
||||
|
||||
await RunSingleTileDownloadTest(httpClient);
|
||||
|
||||
await RunRegionProcessingTest(httpClient);
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("=========================");
|
||||
@@ -164,6 +166,122 @@ class Program
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Single Tile Download Test: PASSED");
|
||||
}
|
||||
|
||||
static async Task RunRegionProcessingTest(HttpClient httpClient)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Test: Region Processing at Coordinates 47.461747, 37.647063");
|
||||
Console.WriteLine("------------------------------------------------------------------");
|
||||
|
||||
const double latitude = 47.461747;
|
||||
const double longitude = 37.647063;
|
||||
const double sizeMeters = 200;
|
||||
const int zoomLevel = 18;
|
||||
|
||||
var regionId = Guid.NewGuid();
|
||||
|
||||
Console.WriteLine($"Requesting region: ID={regionId}");
|
||||
Console.WriteLine($" Coordinates: ({latitude}, {longitude})");
|
||||
Console.WriteLine($" Size: {sizeMeters}m");
|
||||
Console.WriteLine($" Zoom Level: {zoomLevel}");
|
||||
Console.WriteLine();
|
||||
|
||||
var requestRegion = new RequestRegionRequest
|
||||
{
|
||||
Id = regionId,
|
||||
Latitude = latitude,
|
||||
Longitude = longitude,
|
||||
SizeMeters = sizeMeters,
|
||||
ZoomLevel = zoomLevel
|
||||
};
|
||||
|
||||
var requestResponse = await httpClient.PostAsJsonAsync("/api/satellite/request", requestRegion);
|
||||
|
||||
if (!requestResponse.IsSuccessStatusCode)
|
||||
{
|
||||
var errorContent = await requestResponse.Content.ReadAsStringAsync();
|
||||
throw new Exception($"Region request failed with status {requestResponse.StatusCode}: {errorContent}");
|
||||
}
|
||||
|
||||
var initialStatus = await requestResponse.Content.ReadFromJsonAsync<RegionStatusResponse>(JsonOptions);
|
||||
|
||||
if (initialStatus == null)
|
||||
{
|
||||
throw new Exception("No status returned from region request");
|
||||
}
|
||||
|
||||
Console.WriteLine($"✓ Region queued successfully");
|
||||
Console.WriteLine($" Initial Status: {initialStatus.Status}");
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("Polling for region status updates...");
|
||||
RegionStatusResponse? finalStatus = null;
|
||||
int maxAttempts = 30;
|
||||
|
||||
for (int i = 0; i < maxAttempts; i++)
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
|
||||
var statusResponse = await httpClient.GetAsync($"/api/satellite/region/{regionId}");
|
||||
|
||||
if (!statusResponse.IsSuccessStatusCode)
|
||||
{
|
||||
var errorContent = await statusResponse.Content.ReadAsStringAsync();
|
||||
throw new Exception($"Status check failed with status {statusResponse.StatusCode}: {errorContent}");
|
||||
}
|
||||
|
||||
var status = await statusResponse.Content.ReadFromJsonAsync<RegionStatusResponse>(JsonOptions);
|
||||
|
||||
if (status == null)
|
||||
{
|
||||
throw new Exception("No status returned");
|
||||
}
|
||||
|
||||
Console.WriteLine($" Attempt {i + 1}: Status = {status.Status}");
|
||||
|
||||
if (status.Status == "completed" || status.Status == "failed")
|
||||
{
|
||||
finalStatus = status;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (finalStatus == null)
|
||||
{
|
||||
throw new Exception("Region processing did not complete in time");
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Region Processing Results:");
|
||||
Console.WriteLine($" Status: {finalStatus.Status}");
|
||||
Console.WriteLine($" Tiles Downloaded: {finalStatus.TilesDownloaded}");
|
||||
Console.WriteLine($" Tiles Reused: {finalStatus.TilesReused}");
|
||||
Console.WriteLine($" CSV File: {finalStatus.CsvFilePath}");
|
||||
Console.WriteLine($" Summary File: {finalStatus.SummaryFilePath}");
|
||||
Console.WriteLine($" Created At: {finalStatus.CreatedAt:yyyy-MM-dd HH:mm:ss}");
|
||||
Console.WriteLine($" Updated At: {finalStatus.UpdatedAt:yyyy-MM-dd HH:mm:ss}");
|
||||
|
||||
if (finalStatus.Status != "completed")
|
||||
{
|
||||
throw new Exception($"Expected status 'completed', got '{finalStatus.Status}'");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(finalStatus.CsvFilePath))
|
||||
{
|
||||
throw new Exception("CSV file path is empty");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(finalStatus.SummaryFilePath))
|
||||
{
|
||||
throw new Exception("Summary file path is empty");
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("✓ Region processed successfully");
|
||||
Console.WriteLine("✓ CSV and summary files created");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Region Processing Test: PASSED");
|
||||
}
|
||||
}
|
||||
|
||||
public record DownloadTileRequest
|
||||
@@ -187,3 +305,24 @@ public record DownloadTileResponse
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
public record RequestRegionRequest
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public double SizeMeters { get; set; }
|
||||
public int ZoomLevel { get; set; }
|
||||
}
|
||||
|
||||
public record RegionStatusResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Status { get; set; } = string.Empty;
|
||||
public string? CsvFilePath { get; set; }
|
||||
public string? SummaryFilePath { get; set; }
|
||||
public int TilesDownloaded { get; set; }
|
||||
public int TilesReused { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user