NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Analyzer.Graph.PeerGraph Class Reference
Inheritance diagram for Ntp.Analyzer.Graph.PeerGraph:
Collaboration diagram for Ntp.Analyzer.Graph.PeerGraph:

Public Member Functions

 PeerGraph (IPeerGraphConfiguration configuration, Host host, Peer peer)
 
- Public Member Functions inherited from Ntp.Analyzer.Graph.GraphBase
Stream Generate ()
 
Stream Render ()
 

Protected Member Functions

override void AddPlots ()
 
override void LoadData ()
 
override void PreRender ()
 
- Protected Member Functions inherited from Ntp.Analyzer.Graph.DispersionGraph
 DispersionGraph (IDispersionGraphConfiguration configuration)
 
- Protected Member Functions inherited from Ntp.Analyzer.Graph.GraphBase
 GraphBase (IGraphBaseConfiguration baseConfig)
 
LinePlot SetupPlot (string name, Color color, IList time, IList data)
 

Protected Attributes

override string YLabel => "Milliseconds"
 
- Protected Attributes inherited from Ntp.Analyzer.Graph.DispersionGraph
readonly List< double > Jitter
 
readonly List< double > Offset
 
readonly List< DateTime > Time
 
- Protected Attributes inherited from Ntp.Analyzer.Graph.GraphBase
TimeSpan GraphTimeSpan => new TimeSpan(baseConfig.Timespan, 0, 0, 0)
 

Private Member Functions

void CleanSeries ()
 Cleans the value series from values out side boundaries. More...
 

Private Attributes

readonly List< double > balance = new List<double>()
 
readonly IPeerGraphConfiguration config
 
readonly List< double > delay = new List<double>()
 
readonly Host host
 
readonly Peer peer
 
readonly Dictionary< DateTime, HostReadingtimedReading
 

Additional Inherited Members

- Public Attributes inherited from Ntp.Analyzer.Graph.GraphBase
IEnumerable< StreamDestinationDestinations => destinations
 
string ImageFileExtension => "png"
 
- Properties inherited from Ntp.Analyzer.Graph.GraphBase
PlotSurface2D Surface [get, private set]
 
abstract string YLabel [get]
 
- Properties inherited from Ntp.Analyzer.Export.IStreamGenerator
IEnumerable< StreamDestinationDestinations [get]
 

Detailed Description

Definition at line 33 of file PeerGraph.cs.

Constructor & Destructor Documentation

Ntp.Analyzer.Graph.PeerGraph.PeerGraph ( IPeerGraphConfiguration  configuration,
Host  host,
Peer  peer 
)
inline

Definition at line 35 of file PeerGraph.cs.

36  : base(configuration)
37  {
38  config = configuration;
39  this.host = host;
40  this.peer = peer;
41 
42  timedReading = new Dictionary<DateTime, HostReading>();
43  }
readonly IPeerGraphConfiguration config
Definition: PeerGraph.cs:46
readonly Dictionary< DateTime, HostReading > timedReading
Definition: PeerGraph.cs:50

Member Function Documentation

override void Ntp.Analyzer.Graph.PeerGraph.AddPlots ( )
inlineprotectedvirtual

Reimplemented from Ntp.Analyzer.Graph.DispersionGraph.

Definition at line 54 of file PeerGraph.cs.

55  {
56  base.AddPlots();
57 
58  if (config.Delay.HasValue)
59  {
60  var delayPlot = SetupPlot("Delay", Color.DarkOrange, Time, delay);
61  Surface.Add(delayPlot, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.YAxisPosition.Left);
62  }
63 
64  if (config.Balance.HasValue)
65  {
66  var balancePlot = SetupPlot("Balanced offset", Color.DarkViolet, Time, balance);
67  Surface.Add(balancePlot, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.YAxisPosition.Left);
68  }
69  }
readonly List< DateTime > Time
readonly IPeerGraphConfiguration config
Definition: PeerGraph.cs:46
readonly List< double > delay
Definition: PeerGraph.cs:47
readonly List< double > balance
Definition: PeerGraph.cs:45
LinePlot SetupPlot(string name, Color color, IList time, IList data)
Definition: GraphBase.cs:158
void Ntp.Analyzer.Graph.PeerGraph.CleanSeries ( )
inlineprivate

Cleans the value series from values out side boundaries.

Definition at line 152 of file PeerGraph.cs.

153  {
154  double totalOffset = 0.0;
155  double totalJitter = 0.0;
156  double totalDelay = 0.0;
157  double totalBalance = 0.0;
158 
159  // Calculate mean value
160  for (int i = 0; i < Time.Count; i++)
161  {
162  totalOffset += Math.Abs(Offset[i]);
163  totalJitter += Math.Abs(Jitter[i]);
164  totalDelay += Math.Abs(delay[i]);
165  totalBalance += Math.Abs(balance[i]);
166  }
167 
168  double avgOffset = totalOffset/Time.Count;
169  double avgJitter = totalJitter/Time.Count;
170  double avgDelay = totalDelay/Time.Count;
171  double avgBalance = totalBalance/Time.Count;
172 
173  var indexes = new List<int>();
174 
175  // Find invalid values
176  for (int i = 0; i < Time.Count; i++)
177  {
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)
182  {
183  indexes.Add(i);
184  }
185  }
186 
187  // Remove invalid values
188  for (int i = indexes.Count - 1; i >= 0; i--)
189  {
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]);
195  }
196  }
readonly List< double > Jitter
readonly List< DateTime > Time
readonly IPeerGraphConfiguration config
Definition: PeerGraph.cs:46
readonly List< double > Offset
readonly List< double > delay
Definition: PeerGraph.cs:47
readonly List< double > balance
Definition: PeerGraph.cs:45
override void Ntp.Analyzer.Graph.PeerGraph.LoadData ( )
inlineprotectedvirtual

Implements Ntp.Analyzer.Graph.GraphBase.

Definition at line 71 of file PeerGraph.cs.

References Ntp.Analyzer.Data.Sql.FilteredSqlDatabaseMapper< T >.FilterHost, Ntp.Analyzer.Data.Sql.FilteredSqlDatabaseMapper< T >.FilterPeer, Ntp.Analyzer.Data.Sql.FilteredSqlDatabaseMapper< T >.FilterTime, Ntp.Analyzer.Data.DataFace.HostReadings, Ntp.Analyzer.Data.DataFace.Instance, and Ntp.Analyzer.Data.DataFace.PeerReadings.

72  {
74  peerMapper.FilterHost = host;
75  peerMapper.FilterPeer = peer;
76  peerMapper.FilterTime = DateTime.UtcNow.Subtract(GraphTimeSpan);
77 
78  if (config.Balance.HasValue)
79  {
80  foreach (var reading in peerMapper)
81  {
82  Time.Add(config.GraphTime == DateTimeKind.Local ? reading.LocalTime : reading.UtcTime);
83 
84  if (config.Offset.HasValue) Offset.Add(reading.Offset*config.Offset.Value);
85  else Offset.Add(0.0);
86 
87  if (config.Jitter.HasValue) Jitter.Add(reading.Jitter*config.Jitter.Value);
88  else Jitter.Add(0.0);
89 
90  if (config.Delay.HasValue) delay.Add(reading.Delay*config.Delay.Value);
91  else delay.Add(0.0);
92 
93  balance.Add(0.0);
94  }
95  }
96  else
97  {
99  hostMapper.FilterHost = host;
100  hostMapper.FilterTime = DateTime.UtcNow.Subtract(GraphTimeSpan);
101 
102  // Prepare balance data
103  foreach (var hostReading in hostMapper)
104  {
105  var indexTime = config.GraphTime == DateTimeKind.Local
106  ? hostReading.RoundedLocalTime
107  : hostReading.RoundedUtcTime;
108 
109  if (!timedReading.ContainsKey(indexTime))
110  timedReading.Add(indexTime, hostReading);
111  }
112 
113  // Add
114  foreach (var reading in peerMapper)
115  {
116  Time.Add(config.GraphTime == DateTimeKind.Local ? reading.LocalTime : reading.UtcTime);
117 
118  if (config.Offset.HasValue) Offset.Add(reading.Offset*config.Offset.Value);
119  else Offset.Add(0.0);
120 
121  if (config.Jitter.HasValue) Jitter.Add(reading.Jitter*config.Jitter.Value);
122  else Jitter.Add(0.0);
123 
124  if (config.Delay.HasValue) delay.Add(reading.Delay*config.Delay.Value);
125  else delay.Add(0.0);
126 
127  var indexTime = config.GraphTime == DateTimeKind.Local
128  ? reading.RoundedLocalTime
129  : reading.RoundedUtcTime;
130 
131  if (timedReading.ContainsKey(indexTime))
132  balance.Add(reading.Offset - timedReading[indexTime].Offset);
133  else
134  balance.Add(0.0);
135  }
136  }
137 
138  if (config.FilterFactor.HasValue)
139  CleanSeries();
140  }
readonly List< double > Jitter
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.
Definition: DataFace.cs:75
PeerReadingDatabaseMapper PeerReadings
Gets the peer reading mapper.
Definition: DataFace.cs:87
readonly List< DateTime > Time
Peer FilterPeer
Gets or sets the peer to use when extracting data.
readonly IPeerGraphConfiguration config
Definition: PeerGraph.cs:46
readonly List< double > Offset
Singleton facade class used to access memory persistent data.
Definition: DataFace.cs:30
void CleanSeries()
Cleans the value series from values out side boundaries.
Definition: PeerGraph.cs:152
readonly Dictionary< DateTime, HostReading > timedReading
Definition: PeerGraph.cs:50
readonly List< double > delay
Definition: PeerGraph.cs:47
readonly List< double > balance
Definition: PeerGraph.cs:45
static DataFace Instance
Gets the Singleton instance.
Definition: DataFace.cs:51
override void Ntp.Analyzer.Graph.PeerGraph.PreRender ( )
inlineprotectedvirtual

Reimplemented from Ntp.Analyzer.Graph.GraphBase.

Definition at line 142 of file PeerGraph.cs.

143  {
144  base.PreRender();
145 
146  Surface.Title = config.GetTitle(peer);
147  }
readonly IPeerGraphConfiguration config
Definition: PeerGraph.cs:46
string GetTitle(NamedObject namedObject)

Member Data Documentation

readonly List<double> Ntp.Analyzer.Graph.PeerGraph.balance = new List<double>()
private

Definition at line 45 of file PeerGraph.cs.

readonly IPeerGraphConfiguration Ntp.Analyzer.Graph.PeerGraph.config
private

Definition at line 46 of file PeerGraph.cs.

readonly List<double> Ntp.Analyzer.Graph.PeerGraph.delay = new List<double>()
private

Definition at line 47 of file PeerGraph.cs.

readonly Host Ntp.Analyzer.Graph.PeerGraph.host
private

Definition at line 48 of file PeerGraph.cs.

readonly Peer Ntp.Analyzer.Graph.PeerGraph.peer
private

Definition at line 49 of file PeerGraph.cs.

readonly Dictionary<DateTime, HostReading> Ntp.Analyzer.Graph.PeerGraph.timedReading
private

Definition at line 50 of file PeerGraph.cs.

override string Ntp.Analyzer.Graph.PeerGraph.YLabel => "Milliseconds"
protected

Definition at line 52 of file PeerGraph.cs.


The documentation for this class was generated from the following file: