23 using System.Collections.Generic;
31 namespace Ntp.Analyzer.Graph
38 config = configuration;
42 timedReading =
new Dictionary<DateTime, HostReading>();
45 private readonly List<double> balance =
new List<double>();
47 private readonly List<double> delay =
new List<double>();
52 protected override string YLabel =>
"Milliseconds";
58 if (config.Delay.HasValue)
60 var delayPlot = SetupPlot(
"Delay", Color.DarkOrange, Time, delay);
64 if (config.Balance.HasValue)
66 var balancePlot = SetupPlot(
"Balanced offset", Color.DarkViolet, Time, balance);
76 peerMapper.
FilterTime = DateTime.UtcNow.Subtract(GraphTimeSpan);
78 if (config.Balance.HasValue)
80 foreach (var reading
in peerMapper)
82 Time.Add(config.GraphTime == DateTimeKind.Local ? reading.LocalTime : reading.UtcTime);
84 if (config.Offset.HasValue) Offset.Add(reading.Offset*config.Offset.Value);
87 if (config.Jitter.HasValue) Jitter.Add(reading.Jitter*config.Jitter.Value);
90 if (config.Delay.HasValue) delay.Add(reading.Delay*config.Delay.Value);
100 hostMapper.
FilterTime = DateTime.UtcNow.Subtract(GraphTimeSpan);
103 foreach (var hostReading
in hostMapper)
105 var indexTime = config.GraphTime == DateTimeKind.Local
106 ? hostReading.RoundedLocalTime
107 : hostReading.RoundedUtcTime;
109 if (!timedReading.ContainsKey(indexTime))
110 timedReading.Add(indexTime, hostReading);
114 foreach (var reading
in peerMapper)
116 Time.Add(config.GraphTime == DateTimeKind.Local ? reading.LocalTime : reading.UtcTime);
118 if (config.Offset.HasValue) Offset.Add(reading.Offset*config.Offset.Value);
119 else Offset.Add(0.0);
121 if (config.Jitter.HasValue) Jitter.Add(reading.Jitter*config.Jitter.Value);
122 else Jitter.Add(0.0);
124 if (config.Delay.HasValue) delay.Add(reading.Delay*config.Delay.Value);
127 var indexTime = config.GraphTime == DateTimeKind.Local
128 ? reading.RoundedLocalTime
129 : reading.RoundedUtcTime;
131 if (timedReading.ContainsKey(indexTime))
132 balance.Add(reading.Offset - timedReading[indexTime].Offset);
138 if (config.FilterFactor.HasValue)
146 Surface.Title = config.GetTitle(peer);
154 double totalOffset = 0.0;
155 double totalJitter = 0.0;
156 double totalDelay = 0.0;
157 double totalBalance = 0.0;
160 for (
int i = 0; i < Time.Count; i++)
162 totalOffset += Math.Abs(Offset[i]);
163 totalJitter += Math.Abs(Jitter[i]);
164 totalDelay += Math.Abs(delay[i]);
165 totalBalance += Math.Abs(balance[i]);
168 double avgOffset = totalOffset/Time.Count;
169 double avgJitter = totalJitter/Time.Count;
170 double avgDelay = totalDelay/Time.Count;
171 double avgBalance = totalBalance/Time.Count;
173 var indexes =
new List<int>();
176 for (
int i = 0; i < Time.Count; i++)
178 if (Math.Abs(Offset[i]) > avgOffset*config.FilterFactor ||
179 Math.Abs(Jitter[i]) > avgJitter*config.FilterFactor ||
180 Math.Abs(delay[i]) > avgDelay*config.FilterFactor ||
181 Math.Abs(balance[i]) > avgBalance*config.FilterFactor)
188 for (
int i = indexes.Count - 1; i >= 0; i--)
190 Time.RemoveAt(indexes[i]);
191 Offset.RemoveAt(indexes[i]);
192 Jitter.RemoveAt(indexes[i]);
193 delay.RemoveAt(indexes[i]);
194 balance.RemoveAt(indexes[i]);
A dispersion graph contains an series of offsets and jitter values together with a time coordinate...
DateTime FilterTime
Gets or sets the time to use when extracting data. Only readings with a timestamp later than FilterTi...
HostReadingDatabaseMapper HostReadings
Gets the host reading mapper.
PeerReadingDatabaseMapper PeerReadings
Gets the peer reading mapper.
Host FilterHost
Gets or sets the host
Peer FilterPeer
Gets or sets the peer to use when extracting data.
readonly IPeerGraphConfiguration config
Singleton facade class used to access memory persistent data.
void CleanSeries()
Cleans the value series from values out side boundaries.
readonly Dictionary< DateTime, HostReading > timedReading
PeerGraph(IPeerGraphConfiguration configuration, Host host, Peer peer)
override void PreRender()
static DataFace Instance
Gets the Singleton instance.