modifiche x calcolo esatto mediana e fix reinit contatori

This commit is contained in:
Samuele E. Locatelli
2017-07-25 16:54:15 +02:00
parent aced3f08a4
commit 8a220d397d
3 changed files with 53 additions and 59 deletions
+16 -2
View File
@@ -460,12 +460,25 @@ namespace MTC
{
double answ = 0;
// restituisce la mediana SE valida, altrimenti null...
if (numElem > 1 && flWindSize > windSize)
if (numElem > 2 && flWindSize > windSize)
{
try
{
// calcolo mediana!
answ = Statistics.Median(lVal.ToArray());
//answ = Statistics.Median(lVal.ToArray());
// rif: https://blogs.msmvps.com/deborahk/linq-mean-median-and-mode/
var sortedNumbers = lVal.OrderBy(n => n);
int numCount = lVal.Count;
int indice50 = lVal.Count / 2;
if ((numCount % 2) == 0)
{
answ = ((sortedNumbers.ElementAt(indice50) + sortedNumbers.ElementAt(indice50 - 1)) / 2);
}
else
{
answ = sortedNumbers.ElementAt(indice50);
}
}
catch
{ }
@@ -483,6 +496,7 @@ namespace MTC
return (flWindSize > windSize && numElem > 1);
}
}
}
public static class TimingData
+36 -26
View File
@@ -2551,7 +2551,7 @@ namespace MTC_Adapter
{
lastWatchDog = setFlag;
}
retACK_DW = utils.setBitOnStFlag(retACK_DW, setFlag, 0); // imposto primo bit!!!
retACK_DW = utils.setBitOnStFlag(retACK_DW, setFlag, 0); // imposto primo bit!!!
// scrivo su area PLC SE variato
if (ACK_DW2 != (StFlag32)BitConverter.ToUInt32(retACK_DW, 0))
{
@@ -4561,25 +4561,30 @@ namespace MTC_Adapter
public bool procLubro(bool needSave)
{
uint delta = 0;
uint valore = 0;
string outString = string.Format("Lubro_[1-{0}]_Count: ", currAdpConf.nLubro);
for (int i = 0; i < currAdpConf.nLubro; i++)
{
delta = Convert.ToUInt32(istLubroCount[i].vcMedian) - currLubroCount[i];
// controllo delta < 50% max...
if (delta < uint.MaxValue / 2)
valore = Convert.ToUInt32(istLubroCount[i].vcMedian);
if (valore > currLubroCount[i])
{
//processo comunque sempre...
uint contTot = updateValUIntByIncr(i, delta, "Lubro_{0:00}_Count");
// passo valore totale all'adapter
vettLubro[i].mLubroNum.Value = contTot;
// controllo valore riferimento...
if (delta > 0)
delta = valore - currLubroCount[i];
// controllo delta < 50% max...
if (delta < uint.MaxValue / 2)
{
// segnalo necessità salvataggio!
needSave = true;
//processo comunque sempre...
uint contTot = updateValUIntByIncr(i, delta, "Lubro_{0:00}_Count");
// passo valore totale all'adapter
vettLubro[i].mLubroNum.Value = contTot;
// controllo valore riferimento...
if (delta > 0)
{
// segnalo necessità salvataggio!
needSave = true;
}
}
// ...aggiorno valore riferimento...
currLubroCount[i] = Convert.ToUInt32(istLubroCount[i].vcMedian);
currLubroCount[i] = valore;
}
outString += string.Format("{0} | ", vettLubro[i].mLubroNum.Value);
}
@@ -4595,29 +4600,34 @@ namespace MTC_Adapter
public bool procCounters(bool needSave)
{
uint delta = 0;
uint valore = 0;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mCounters.Length; i++)
{
// procedo solo SE HO FINESTRA VALIDA...
if (istCounters[i].vcValid)
{
delta = Convert.ToUInt32(istCounters[i].vcMedian) - currCounters[i];
// controllo delta < 50% max...
if (delta < uint.MaxValue / 2)
valore = Convert.ToUInt32(istCounters[i].vcMedian);
if (valore >= currCounters[i])
{
//processo comunque sempre...
uint contTot = updateValUIntByIncr(i, delta, "Counter_{0:000}");
// passo valore totale all'adapter
mCounters[i].Value = contTot;
// controllo valore riferimento...
if (delta > 0)
delta = valore - currCounters[i];
// controllo delta < 50% max...
if (delta < uint.MaxValue / 2)
{
// segnalo necessità salvataggio!
needSave = true;
//processo comunque sempre...
uint contTot = updateValUIntByIncr(i, delta, "Counter_{0:000}");
// passo valore totale all'adapter
mCounters[i].Value = contTot;
// controllo valore riferimento...
if (delta > 0)
{
// segnalo necessità salvataggio!
needSave = true;
}
}
// ...aggiorno valore riferimento...
currCounters[i] = Convert.ToUInt32(istCounters[i].vcMedian);
}
// ...aggiorno valore riferimento...
currCounters[i] = valore;
sb.AppendLine(mCounters[i].ToString().Replace("|", " | "));
}
}
@@ -1,31 +1 @@
ACC_TIME:0
ACC_TIME_WORK:0
Axis_01_AccTime:0
Axis_01_DistDone:0
Axis_01_InvDDone:0
Axis_02_AccTime:0
Axis_02_DistDone:0
Axis_02_InvDDone:0
Axis_03_AccTime:0
Axis_03_DistDone:0
Axis_03_InvDDone:0
Axis_04_AccTime:0
Axis_04_DistDone:0
Axis_04_InvDDone:0
Axis_05_AccTime:0
Axis_05_DistDone:0
Axis_05_InvDDone:0
Axis_06_AccTime:0
Axis_06_DistDone:0
Axis_06_InvDDone:0
Lubro_01_Count:0
Lubro_02_Count:0
ProtMagazzino_01_Count:0
ProtMagazzino_02_Count:0
SlittaTastatore_Count:0
UnOp_01_AccTime:0
UnOp_01_NumCU:0
VacAct_01_Count:0
VacAct_02_Count:0
VacPump_01_WrkTime:0
VacPump_02_WrkTime:0