Skip to content

Commit

Permalink
Allow missions where most tags don't have area
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Dec 3, 2024
1 parent dd90dcb commit 3e06834
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions backend/api/Controllers/MissionSchedulingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}'.");
}

Expand Down
11 changes: 9 additions & 2 deletions backend/api/Services/EchoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,18 @@ public async Task<List<MissionTask>> 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;
}

Expand Down

0 comments on commit 3e06834

Please sign in to comment.