diff options
| author | Jake Mannens <jake@asger.xyz> | 2024-10-04 03:29:37 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2024-10-29 13:06:30 +1100 |
| commit | 886665f68a652f91ad94d20feb648c3758a79b85 (patch) | |
| tree | 1ecdf4b267e99f47aa39a86edcea45c90f93dc6f | |
| parent | b39dc97286456159a99b8afcdfdb6e0aae759495 (diff) | |
Initial commitTTS
| -rw-r--r-- | TtsService.cs | 50 | ||||
| -rw-r--r-- | appsettings.json | 22 |
2 files changed, 72 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; } +} diff --git a/appsettings.json b/appsettings.json index 00b7c95..37fa847 100644 --- a/appsettings.json +++ b/appsettings.json @@ -27,6 +27,28 @@ // "BRIG": 500 // } //} + // Used when generating TTS messages to indicate proximity to a well-known location + //"Landmarks": [ + // { "Name": "Alira Village", "Radius": 300, "Latitude": -38.047981231791276, "Longitude": 145.32244920730594 }, + // { "Name": "Beaconhills College", "Radius": 350, "Latitude": -38.049206312580075, "Longitude": 145.35716772079470 }, + // { "Name": "Bridgewater Boulevard", "Radius": 300, "Latitude": -38.063394000000000, "Longitude": 145.34790600000000 }, + // { "Name": "Casey Hospital", "Radius": 300, "Latitude": -38.044846621406975, "Longitude": 145.34568786621097 }, + // { "Name": "Clyde Bunnings", "Radius": 1000, "Latitude": -38.092417418430440, "Longitude": 145.33373594284060 }, + // { "Name": "Eden Rise", "Radius": 1000, "Latitude": -38.061785000000000, "Longitude": 145.33969300000000 }, + // { "Name": "Enterprise Avenue", "Radius": 300, "Latitude": -38.036996833045080, "Longitude": 145.33873558044436 }, + // { "Name": "Federation University", "Radius": 250, "Latitude": -38.039367067725905, "Longitude": 145.32928347587588 }, + // { "Name": "High Street", "Radius": 300, "Latitude": -38.031495564962510, "Longitude": 145.34603118896487 }, + // { "Name": "Kambrya College", "Radius": 300, "Latitude": -38.054516000000000, "Longitude": 145.34746300000000 }, + // { "Name": "King Road Harkaway", "Radius": 750, "Latitude": -38.000761990532860, "Longitude": 145.34697532653811 }, + // { "Name": "Nossal High School", "Radius": 250, "Latitude": -38.038779797476170, "Longitude": 145.32573223114017 }, + // { "Name": "Parkhill Plaza", "Radius": 500, "Latitude": -38.014389136866830, "Longitude": 145.32280325889590 }, + // { "Name": "St Francis Xavier College", "Radius": 500, "Latitude": -38.070877000000000, "Longitude": 145.33843600000000 }, + // { "Name": "St Michael's Church", "Radius": 270, "Latitude": -38.032982891710270, "Longitude": 145.35382032394412 }, + // { "Name": "The Gateway Estate", "Radius": 300, "Latitude": -38.021573646929234, "Longitude": 145.31929492950442 }, + // { "Name": "The Old Cheesecake Factory", "Radius": 400, "Latitude": -38.054224705380925, "Longitude": 145.33377885818484 }, + // { "Name": "William Road", "Radius": 300, "Latitude": -38.027151721917704, "Longitude": 145.33296346664432 }, + // { "Name": "Woodlands Park Retirement Village", "Radius": 300, "Latitude": -38.047077193511520, "Longitude": 145.35088062286380 } + //] }, "ConnectionStrings": { "DefaultConnection": "Host=127.0.0.1;Database=PagerParser;Username=pagerparser;Password=password" |
