diff options
Diffstat (limited to 'TtsService.cs')
| -rw-r--r-- | TtsService.cs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/TtsService.cs b/TtsService.cs new file mode 100644 index 0000000..8d0a146 --- /dev/null +++ b/TtsService.cs @@ -0,0 +1,50 @@ +namespace PagerParser; + +public interface ITtsService { + public string GetTtsMessage(ParsedPagerMessage pm); +} + +public class TtsService : ITtsService { + public static readonly Dictionary<string, string> IncidentTypeMap = new() { + { "ALAR", "FIRE ALARM" }, + { "G&S", "GRASS & SCRUB" }, + { "HIAR", "HIGH-ANGLE RESCUE" }, + { "INCI", "INCIDENT" }, + { "NOST", "NON-STRUCTURE" }, + { "RESC", "RESCUE" }, + { "STRU", "STRUCTURE" } + }; + + private List<Landmark> 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; } +} |
