Moved standardDeviation

This commit is contained in:
2022-03-10 21:11:10 -07:00
parent b20bc99117
commit 87700e0370
2 changed files with 28 additions and 23 deletions

View File

@ -163,7 +163,7 @@ public class FileRead : Shared.FileRead, IFileRead
results.Item4.Add(new FileInfo(reportFullPath));
else
{
IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4, _StartX, _StartY, _EndX, _EndY, _ColorCollections, _PreviousTotalDeltaCollection, _LastText);
IProcessData iProcessData = new ProcessData(this, _Logistics, results.Item4, _StartX, _StartY, _EndX, _EndY, _ColorCollections);
if (iProcessData is not ProcessData processData)
throw new Exception(string.Concat("A) No Data - ", dateTime.Ticks));
string mid = processData.Text;
@ -173,8 +173,30 @@ public class FileRead : Shared.FileRead, IFileRead
_Logistics.ProcessJobID = iProcessData.GetCurrentReactor(this, _Logistics, _Reactors);
if (!iProcessData.Details.Any())
throw new Exception(string.Concat("B) No Data - ", dateTime.Ticks));
if (_LastText != processData.Text || _LastChange < DateTime.Now.AddMinutes(-30).Ticks)
if (processData.Text != _LastText || _LastChange < DateTime.Now.AddMinutes(-30).Ticks)
{
if (processData.Text != _LastText)
{
if (_PreviousTotalDeltaCollection.Count > 50)
{
double average = _PreviousTotalDeltaCollection.Average();
double sum = _PreviousTotalDeltaCollection.Sum(l => Math.Pow(l - average, 2));
double standardDeviation = Math.Sqrt(sum / _PreviousTotalDeltaCollection.Count);
double deviation = standardDeviation * 3;
double upper = average + deviation;
double lower = average - deviation;
string message = $"average:{average};sum:{sum};standardDeviation:{standardDeviation};upper:{upper};lower:{lower};TotalDelta:{processData.TotalDelta};Text:{processData.Text};_PreviousTotalDeltaCollection.Count:{_PreviousTotalDeltaCollection.Count};";
_Log.Debug(message);
if (processData.TotalDelta > upper || processData.TotalDelta < lower)
_SMTP.SendHighPriorityEmailMessage($"Exception:{_CellInstanceConnectionName}", message);
}
_PreviousTotalDeltaCollection.Add(processData.TotalDelta);
if (_PreviousTotalDeltaCollection.Count > short.MaxValue)
{
for (int i = 1; i < 500; i++)
_PreviousTotalDeltaCollection.RemoveAt(0);
}
}
_LastText = processData.Text;
_LastChange = DateTime.Now.Ticks;
results = iProcessData.GetResults(this, _Logistics, results.Item4);