Moved standardDeviation
This commit is contained in:
parent
b20bc99117
commit
87700e0370
@ -163,7 +163,7 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
results.Item4.Add(new FileInfo(reportFullPath));
|
results.Item4.Add(new FileInfo(reportFullPath));
|
||||||
else
|
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)
|
if (iProcessData is not ProcessData processData)
|
||||||
throw new Exception(string.Concat("A) No Data - ", dateTime.Ticks));
|
throw new Exception(string.Concat("A) No Data - ", dateTime.Ticks));
|
||||||
string mid = processData.Text;
|
string mid = processData.Text;
|
||||||
@ -173,8 +173,30 @@ public class FileRead : Shared.FileRead, IFileRead
|
|||||||
_Logistics.ProcessJobID = iProcessData.GetCurrentReactor(this, _Logistics, _Reactors);
|
_Logistics.ProcessJobID = iProcessData.GetCurrentReactor(this, _Logistics, _Reactors);
|
||||||
if (!iProcessData.Details.Any())
|
if (!iProcessData.Details.Any())
|
||||||
throw new Exception(string.Concat("B) No Data - ", dateTime.Ticks));
|
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;
|
_LastText = processData.Text;
|
||||||
_LastChange = DateTime.Now.Ticks;
|
_LastChange = DateTime.Now.Ticks;
|
||||||
results = iProcessData.GetResults(this, _Logistics, results.Item4);
|
results = iProcessData.GetResults(this, _Logistics, results.Item4);
|
||||||
|
@ -8,8 +8,6 @@ using System.Drawing;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using Tesseract;
|
|
||||||
|
|
||||||
namespace Adaptation.FileHandlers.jpeg;
|
namespace Adaptation.FileHandlers.jpeg;
|
||||||
|
|
||||||
@ -31,7 +29,7 @@ public class ProcessData : IProcessData
|
|||||||
|
|
||||||
List<object> Shared.Properties.IProcessData.Details => _Details;
|
List<object> Shared.Properties.IProcessData.Details => _Details;
|
||||||
|
|
||||||
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, List<(string, Color[])> colorCollections, List<int> previousTotalDeltaCollection, string lastText)
|
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, List<(string, Color[])> colorCollections)
|
||||||
{
|
{
|
||||||
if (logistics is null)
|
if (logistics is null)
|
||||||
{ }
|
{ }
|
||||||
@ -40,7 +38,7 @@ public class ProcessData : IProcessData
|
|||||||
_Details = new List<object>();
|
_Details = new List<object>();
|
||||||
MesEntity = logistics.MesEntity;
|
MesEntity = logistics.MesEntity;
|
||||||
_Log = LogManager.GetLogger(typeof(ProcessData));
|
_Log = LogManager.GetLogger(typeof(ProcessData));
|
||||||
Parse(fileRead, fileInfoCollection, startX, startY, endX, endY, colorCollections, previousTotalDeltaCollection, lastText);
|
Parse(fileRead, fileInfoCollection, startX, startY, endX, endY, colorCollections);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string Get(string value, bool useSplitForMID)
|
private static string Get(string value, bool useSplitForMID)
|
||||||
@ -220,7 +218,7 @@ public class ProcessData : IProcessData
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Parse(IFileRead fileRead, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, List<(string, Color[])> colorCollections, List<int> previousTotalDeltaCollection, string lastText)
|
private void Parse(IFileRead fileRead, List<FileInfo> fileInfoCollection, int startX, int startY, int endX, int endY, List<(string, Color[])> colorCollections)
|
||||||
{
|
{
|
||||||
Red = 0;
|
Red = 0;
|
||||||
Green = 0;
|
Green = 0;
|
||||||
@ -269,25 +267,10 @@ public class ProcessData : IProcessData
|
|||||||
string textFileName = Get(fileRead, ".txt", $"{TotalDelta} - {Text}");
|
string textFileName = Get(fileRead, ".txt", $"{TotalDelta} - {Text}");
|
||||||
if (!fileRead.IsEAFHosted)
|
if (!fileRead.IsEAFHosted)
|
||||||
{
|
{
|
||||||
|
_Log.Debug(textFileName);
|
||||||
fileInfoCollection.Add(new FileInfo(textFileName));
|
fileInfoCollection.Add(new FileInfo(textFileName));
|
||||||
SaveText(Red, Green, Text, textFileName, totalDeltaCollection);
|
SaveText(Red, Green, Text, textFileName, totalDeltaCollection);
|
||||||
}
|
}
|
||||||
if (Text != lastText && 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:{TotalDelta};Text:{Text};previousTotalDeltaCollection.Count:{previousTotalDeltaCollection.Count};";
|
|
||||||
_Log.Debug(message);
|
|
||||||
if (TotalDelta > upper)
|
|
||||||
throw new Exception(message);
|
|
||||||
if (TotalDelta < lower)
|
|
||||||
throw new Exception(message);
|
|
||||||
}
|
|
||||||
previousTotalDeltaCollection.Add(TotalDelta);
|
|
||||||
_Details.Add(Text);
|
_Details.Add(Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user