From dd90dcb8722ef687a90bcf90529ad6b339684ebe Mon Sep 17 00:00:00 2001 From: Eddasol Date: Tue, 3 Dec 2024 10:19:00 +0100 Subject: [PATCH 1/2] Reduce loglevel for tags without area --- backend/api/Services/StidService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/api/Services/StidService.cs b/backend/api/Services/StidService.cs index 80d8ebdc..1a9c71e1 100644 --- a/backend/api/Services/StidService.cs +++ b/backend/api/Services/StidService.cs @@ -35,7 +35,7 @@ public class StidService(ILogger logger, IDownstreamApi stidApi, IA if (stidTagAreaResponse.LocationCode == null) { string errorMessage = $"Could not get area name from STID for tag {tag}"; - logger.LogError("{Message}", errorMessage); + logger.LogDebug("{Message}", errorMessage); return null; } From 3e0683420aee5f6010f9f864c1a99c4ec6b55b88 Mon Sep 17 00:00:00 2001 From: Eddasol Date: Tue, 3 Dec 2024 10:19:41 +0100 Subject: [PATCH 2/2] Allow missions where most tags don't have area --- .../api/Controllers/MissionSchedulingController.cs | 11 +++++++++-- backend/api/Services/EchoService.cs | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/api/Controllers/MissionSchedulingController.cs b/backend/api/Controllers/MissionSchedulingController.cs index ffdd27ae..b5007e17 100644 --- a/backend/api/Controllers/MissionSchedulingController.cs +++ b/backend/api/Controllers/MissionSchedulingController.cs @@ -252,11 +252,18 @@ [FromBody] ScheduledMissionQuery scheduledMissionQuery logger.LogWarning($"Mission {missionDefinition.Name} has tags on more than one deck. The decks are: {joinedMissionDeckNames}."); } - Area? area = null; - area = missionAreas.GroupBy(i => i).OrderByDescending(grp => grp.Count()).Select(grp => grp.Key).First(); + var sortedAreas = missionAreas.GroupBy(i => i).OrderByDescending(grp => grp.Count()).Select(grp => grp.Key); + var area = sortedAreas.First(); + if (area == null && sortedAreas.Count() > 1) + { + logger.LogWarning($"Most common area in mission {missionDefinition.Name} is null. Will use second most common area."); + area = sortedAreas.Skip(1).First(); + + } if (area == null) { + logger.LogError($"Mission {missionDefinition.Name} doesn't have any tags with valid area."); return NotFound($"No area found for mission '{missionDefinition.Name}'."); } diff --git a/backend/api/Services/EchoService.cs b/backend/api/Services/EchoService.cs index 559196c6..65ddb308 100644 --- a/backend/api/Services/EchoService.cs +++ b/backend/api/Services/EchoService.cs @@ -119,11 +119,18 @@ public async Task> GetTasksForMission(string missionSourceId) logger.LogWarning($"Mission {echoMission.Name} has tags on more than one deck. The decks are: {joinedMissionDeckNames}."); } - Area? area = null; - area = missionAreas.GroupBy(i => i).OrderByDescending(grp => grp.Count()).Select(grp => grp.Key).First(); + var sortedAreas = missionAreas.GroupBy(i => i).OrderByDescending(grp => grp.Count()).Select(grp => grp.Key); + var area = sortedAreas.First(); + if (area == null && sortedAreas.Count() > 1) + { + logger.LogWarning($"Most common area in mission {echoMission.Name} is null. Will use second most common area."); + area = sortedAreas.Skip(1).First(); + + } if (area == null) { + logger.LogError($"Mission {echoMission.Name} doesn't have any tags with valid area."); return null; }