namespace PagerParser; public interface ITtsService { public string GetTtsMessage(ParsedPagerMessage pm); } public class TtsService : ITtsService { public static readonly Dictionary IncidentTypeMap = new() { { "ALAR", "FIRE ALARM" }, { "G&S", "GRASS & SCRUB" }, { "HIAR", "HIGH-ANGLE RESCUE" }, { "INCI", "INCIDENT" }, { "NOST", "NON-STRUCTURE" }, { "RESC", "RESCUE" }, { "STRU", "STRUCTURE" } }; private List landmarks; public TtsService(IConfiguration config) => config.Bind("PagerParser:Landmarks", landmarks); public string GetTtsMessage(ParsedPagerMessage pm) { // If we have GPS coordinates for the page, check if // it's near a well-known landmark and include that // in the TTS message. string? nearestLandmark = null; if(pm.GpsPosition is not null) nearestLandmark = landmarks .Where(l => pm.GpsPosition.GetDistance(l.Latitude, l.Longitude) < l.Radius) .OrderBy(l => pm.GpsPosition.GetDistance(l.Latitude, l.Longitude)) .Select(l => l.Name) .FirstOrDefault(); return string.Join(" ", [ IncidentTypeMap.GetValueOrDefault(pm.JobType) ?? "UNKNOWN ALERT", pm.Description, nearestLandmark is null ? null : $"located near {nearestLandmark}", // TODO: more detailed information on what services have been paged pm.PagedServices.Count > 0 ? $"{pm.PagedServices.Count} services paged" : null ]).Trim(); } } public record Landmark { public string Name { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } public double Radius { get; set; } }