using System.Windows.Media; using Newtonsoft.Json; namespace Azaion.Annotator.DTO; public class AnnotationResult { private readonly Config _config = null!; [JsonProperty(PropertyName = "f")] public string Image { get; set; } = null!; [JsonProperty(PropertyName = "t")] public TimeSpan Time { get; set; } public double Lat { get; set; } public double Lon { get; set; } public List Detections { get; set; } = new(); #region For Display in the grid [JsonIgnore] //For XAML Form public string TimeStr => $"{Time:h\\:mm\\:ss}"; [JsonIgnore] //For XAML Form public string ClassName { get { if (Detections.Count == 0) return ""; var groups = Detections.Select(x => x.ClassNumber).GroupBy(x => x).ToList(); return groups.Count > 1 ? string.Join(",", groups.Select(x => x.Key + 1)) : _config.AnnotationClassesDict[groups.FirstOrDefault().Key].Name; } } [JsonIgnore] //For XAML Form public Color ClassColor { get { var defaultColor = (Color)ColorConverter.ConvertFromString("#404040"); if (Detections.Count == 0) return defaultColor; var groups = Detections.Select(x => x.ClassNumber).GroupBy(x => x).ToList(); return groups.Count > 1 ? defaultColor : _config.AnnotationClassesDict[groups.FirstOrDefault().Key].Color; } } #endregion public AnnotationResult() { } public AnnotationResult(TimeSpan time, string timeName, List detections, Config config) { _config = config; Detections = detections; Time = time; Image = $"{timeName}.jpg"; } }