11' Dynamic Bandwidth Monitor
22' Leak detection method implemented in a real-time data historian
3- ' Copyright (C) 2014-2022 J.H. Fitié, Vitens N.V.
3+ ' Copyright (C) 2014-2025 J.H. Fitié, Vitens N.V.
44'
55' This file is part of DBM.
66'
@@ -22,6 +22,7 @@ Imports System
2222Imports System.Collections.Generic
2323Imports System.Double
2424Imports System.Threading
25+ Imports Vitens.DynamicBandwidthMonitor.DBMParameters
2526
2627
2728Namespace Vitens.DynamicBandwidthMonitor
@@ -30,8 +31,12 @@ Namespace Vitens.DynamicBandwidthMonitor
3031 Public Class DBMDataStore
3132
3233
34+ Private Shared ReadOnly MaxDataStoreSize As Integer =
35+ ( 365 +ComparePatterns* 7 )* 24 * 60 * 60 \CalculationInterval+EMAPreviousPeriods
36+
37+
3338 Private _lock As New Object ' Object for exclusive lock on critical section.
34- Private _dataStore As New Dictionary (Of DateTime, Double ) ' In-memory data
39+ Private _dataStore As New SortedDictionary (Of DateTime, Double ) ' In-mem
3540
3641
3742 Public Sub AddData(timestamp As DateTime, data As Object )
@@ -46,7 +51,13 @@ Namespace Vitens.DynamicBandwidthMonitor
4651 Try
4752
4853 If Not _dataStore.ContainsKey(timestamp) Then
54+
55+ While _dataStore.Count >= MaxDataStoreSize ' Limit size
56+ _dataStore.Remove(_dataStore.Keys.First()) ' Remove oldest
57+ End While
58+
4959 _dataStore.Add(timestamp, DirectCast (data, Double ))
60+
5061 End If
5162
5263 Finally
0 commit comments