aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Telemetry/Reporting/TelemetryReport.cs
blob: 9e9906fde27d950200020a539c4c93b40cf2ecba (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.Telemetry.Reporting
{
    /// <summary>
    /// Represents a diagnostic snapshot of the telemetry system,
    /// providing detailed statistics about published and pending telemetry data,
    /// grouped by source type and destination.
    /// </summary>
    public class TelemetryReport
    {
        /// <summary>
        /// Gets or sets the timestamp indicating when the report was generated.
        /// </summary>
        public DateTime GeneratedAt { get; set; }

        /// <summary>
        /// Gets or sets the total number of telemetry packages that were published
        /// successfully since the telemetry system started.
        /// </summary>
        public int TotalPublished { get; set; }

        /// <summary>
        /// Gets or sets the current number of telemetry packages pending publication in storage.
        /// </summary>
        public int TotalPending { get; set; }

        /// <summary>
        /// Gets or sets the aggregated telemetry publish summaries, grouped by source type.
        /// Each source type contains its respective sources and destination-level statistics.
        /// </summary>
        public Dictionary<TelemetrySourceTypes, SourceTypeSummary> SourceTypes { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="TelemetryReport"/> class,
        /// initializing the dictionary used for grouping by source type.
        /// </summary>
        public TelemetryReport()
        {
            SourceTypes = new Dictionary<TelemetrySourceTypes, SourceTypeSummary>();
        }

        /// <summary>
        /// Returns a human-readable string representation of the report,
        /// including summary statistics and breakdowns by source type and destination.
        /// </summary>
        /// <returns>A formatted string representing the current telemetry report.</returns>
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.AppendLine("===== Telemetry Report =====");
            sb.AppendLine($"Generated At     : {GeneratedAt:u}");
            sb.AppendLine($"Total Published  : {TotalPublished}");
            sb.AppendLine($"Total Pending    : {TotalPending}");
            sb.AppendLine();

            foreach (var sourceTypePair in SourceTypes)
            {
                sb.AppendLine($"--- Source Type: {sourceTypePair.Key} ---");

                foreach (var sourcePair in sourceTypePair.Value.Sources)
                {
                    sb.AppendLine($"  Source: {sourcePair.Key}");

                    foreach (var destinationPair in sourcePair.Value.Destinations)
                    {
                        var d = destinationPair.Value;
                        sb.AppendLine($"    {d.DestinationName}: Passed={d.Passed}, Failed={d.Failed}, Postponed={d.Postponed}, Unavailable={d.Unavailable}");
                    }

                    sb.AppendLine(); // spacing between sources
                }

                sb.AppendLine(); // spacing between source types
            }

            sb.AppendLine("============================");
            return sb.ToString();
        }
    }
}