aboutsummaryrefslogtreecommitdiff
path: root/TtsService.cs
blob: 8d0a146ecaa2ca795208cd9295bf6d4805bf16ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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; }
}