From 42cd703d0d7bad8014e79992a798120d2fbcf496 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 8 May 2023 17:45:46 +0200 Subject: [PATCH] update x simulazione FL interclays01 --- MapoDataFiller/Filler/InterClays.cs | 216 ++++++++++++++++++++++++---- MapoDataFiller/FluxStats.cs | 4 +- 2 files changed, 192 insertions(+), 28 deletions(-) diff --git a/MapoDataFiller/Filler/InterClays.cs b/MapoDataFiller/Filler/InterClays.cs index e432578..0ec463a 100644 --- a/MapoDataFiller/Filler/InterClays.cs +++ b/MapoDataFiller/Filler/InterClays.cs @@ -51,24 +51,14 @@ // verifico il tipo di CodIOB if (CodIOB == "INTERCL_01") { - // verifico se DEVO finire caricamento... - if (valCurr < valReq) - { - doProd = true; - } - else - { - // tiro a dadi x decidere SE ho pesate nel periodo... 30% dei casi - doProd = (rnd.Next(0, 100) <= 30); + // tiro a dadi x decidere SE LAVORA periodo... 60% dei casi + doProd = (rnd.Next(0, 100) <= 60); - // FluxLOG: SE ho pesate --> genero target - valReq = doProd ? rnd.Next(valMin / valStep, valMax / valStep) * valStep : 0; - } // FluxLOG: genero righe FL x periodo e sommo - nextRowsFL = IC_OX_getFlRows(dtStart, dtEnd, doProd, valReq, ref idxFl, ref valCurr); + nextRowsFL = IC_ESS_getFlRows(CodIOB, dtStart, dtEnd, doProd, ref idxFl); - // EvList: genero righe FL x periodo e sommo - nextRowsEV = IC_OX_getEvRows(dtStart, dtEnd, doProd, ref idxEv); + // EvList: genero righe EV x periodo e sommo + nextRowsEV = IC_ESS_getEvRows(CodIOB, dtStart, dtEnd, doProd, ref idxEv); } else if (CodIOB == "INTERCL_02") { @@ -86,10 +76,10 @@ valReq = doProd ? rnd.Next(valMin / valStep, valMax / valStep) * valStep : 0; } // FluxLOG: genero righe FL x periodo e sommo - nextRowsFL = IC_OX_getFlRows(dtStart, dtEnd, doProd, valReq, ref idxFl, ref valCurr); + nextRowsFL = IC_OX_getFlRows(CodIOB, dtStart, dtEnd, doProd, valReq, ref idxFl, ref valCurr); - // EvList: genero righe FL x periodo e sommo - nextRowsEV = IC_OX_getEvRows(dtStart, dtEnd, doProd, ref idxEv); + // EvList: genero righe EV x periodo e sommo + nextRowsEV = IC_OX_getEvRows(CodIOB, dtStart, dtEnd, doProd, ref idxEv); } // accodo FL answ.FlList.AddRange(nextRowsFL); @@ -129,12 +119,13 @@ /// /// Simulo un blocco dati FL /// + /// /// /// /// /// /// - protected List IC_OX_getEvRows(DateTime dtStart, DateTime dtEnd, bool doProd, ref int idxCount) + protected List IC_OX_getEvRows(string CodIOB, DateTime dtStart, DateTime dtEnd, bool doProd, ref int idxCount) { List rows = new List(); DateTime dtCurs = dtStart.AddMilliseconds(rnd.Next(1000, 60000)); @@ -144,9 +135,9 @@ // se produce registro poweron... if (doProd) { - currRow = $"INTERCL_02;{dtStart.AddSeconds(5):yyyy-MM-dd HH:mm:ss.fff};16;ND;[{idxCount++}] 23;0;-"; + currRow = $"{CodIOB};{dtStart.AddSeconds(5):yyyy-MM-dd HH:mm:ss.fff};16;ND;[{idxCount++}] 23;0;-"; rows.Add(currRow); - currRow = $"INTERCL_02;{dtEnd.AddSeconds(-5):yyyy-MM-dd HH:mm:ss.fff};15;ND;[{idxCount++}] 01;0;-"; + currRow = $"{CodIOB};{dtEnd.AddSeconds(-5):yyyy-MM-dd HH:mm:ss.fff};15;ND;[{idxCount++}] 01;0;-"; rows.Add(currRow); } // se NON produce alterno valori spenta/accesa @@ -155,10 +146,10 @@ // genera i dati secondo lo schema configurato... con periodo da 15" a 15 min di pausa while (dtCurs < dtEnd) { - currRow = $"INTERCL_02;{dtCurs:yyyy-MM-dd HH:mm:ss.fff};15;ND;[{idxCount++}] 01;0;-"; + currRow = $"{CodIOB};{dtCurs:yyyy-MM-dd HH:mm:ss.fff};15;ND;[{idxCount++}] 01;0;-"; rows.Add(currRow); dtCurs = dtCurs.AddSeconds(rnd.Next(60 * 5, 60 * 15)); - currRow = $"INTERCL_02;{dtCurs:yyyy-MM-dd HH:mm:ss.fff};14;ND;[{idxCount++}] 00;0;-"; + currRow = $"{CodIOB};{dtCurs:yyyy-MM-dd HH:mm:ss.fff};14;ND;[{idxCount++}] 00;0;-"; rows.Add(currRow); dtCurs = dtCurs.AddMilliseconds(rnd.Next(500, 5000)); // reset counter @@ -171,6 +162,7 @@ /// /// Simulo un blocco dati FL /// + /// /// /// /// @@ -178,7 +170,7 @@ /// /// /// - protected List IC_OX_getFlRows(DateTime dtStart, DateTime dtEnd, bool doProd, int valReq, ref int idxCount, ref int valCurr) + protected List IC_OX_getFlRows(string CodIOB, DateTime dtStart, DateTime dtEnd, bool doProd, int valReq, ref int idxCount, ref int valCurr) { List rows = new List(); DateTime dtCurs = dtStart; @@ -190,10 +182,10 @@ // genera i dati secondo lo schema configurato... while (dtCurs < dtEnd) { - currRow = $"INTERCL_02;{dtCurs:yyyy-MM-dd HH:mm:ss.fff};kgImp;{valReq};{idxCount++}"; + currRow = $"{CodIOB};{dtCurs:yyyy-MM-dd HH:mm:ss.fff};kgImp;{valReq};{idxCount++}"; rows.Add(currRow); dtCurs = dtCurs.AddMilliseconds(rnd.Next(50, 300)); - currRow = $"INTERCL_02;{dtCurs:yyyy-MM-dd HH:mm:ss.fff};kgAct;{valCurr};{idxCount++}"; + currRow = $"{CodIOB};{dtCurs:yyyy-MM-dd HH:mm:ss.fff};kgAct;{valCurr};{idxCount++}"; rows.Add(currRow); dtCurs = dtCurs.AddMilliseconds(rnd.Next(27000, 33000)); // incremento peso... SE <= max... @@ -207,6 +199,178 @@ return rows; } + + /// + /// Simulo un blocco dati FL + /// + /// + /// + /// + /// + /// + /// + protected List IC_ESS_getEvRows(string CodIOB, DateTime dtStart, DateTime dtEnd, bool doProd, ref int idxCount) + { + List rows = new List(); + DateTime dtCurs = dtStart.AddMilliseconds(rnd.Next(1000, 60000)); + string currRow = ""; + // reset counter + idxCount = idxCount <= 9999 ? idxCount : 0; + // se produce registro poweron... + if (doProd) + { + currRow = $"{CodIOB};{dtStart.AddSeconds(5):yyyy-MM-dd HH:mm:ss.fff};16;ND;[{idxCount++}] 23;0;-"; + rows.Add(currRow); + currRow = $"{CodIOB};{dtEnd.AddSeconds(-5):yyyy-MM-dd HH:mm:ss.fff};15;ND;[{idxCount++}] 01;0;-"; + rows.Add(currRow); + } + // se NON produce alterno valori spenta/accesa + else + { + // genera i dati secondo lo schema configurato... con periodo da 15" a 15 min di pausa + while (dtCurs < dtEnd) + { + currRow = $"{CodIOB};{dtCurs:yyyy-MM-dd HH:mm:ss.fff};15;ND;[{idxCount++}] 01;0;-"; + rows.Add(currRow); + dtCurs = dtCurs.AddSeconds(rnd.Next(60 * 5, 60 * 15)); + currRow = $"{CodIOB};{dtCurs:yyyy-MM-dd HH:mm:ss.fff};14;ND;[{idxCount++}] 00;0;-"; + rows.Add(currRow); + dtCurs = dtCurs.AddMilliseconds(rnd.Next(500, 5000)); + // reset counter + idxCount = idxCount <= 9999 ? idxCount : 0; + } + } + return rows; + } + + /// + /// Simulo un blocco dati FL + /// + /// + /// + /// + /// + /// + /// + /// + /// + protected List IC_ESS_getFlRows(string CodIOB, DateTime dtStart, DateTime dtEnd, bool doProd, ref int idxCount) + { + List rows = new List(); + DateTime dtCurs = dtStart; + int simInt = 0; + double simReal = 0; + double simDTime = 0; + // se è do prod --> simulo 50° percentile in su, altrimenti primi 50 percentili... + string currRow = ""; + // reset counter + idxCount = idxCount <= 9999 ? idxCount : 0; + // genera i dati secondo lo schema configurato... + while (dtCurs < dtEnd) + { + // in primis genero gli items INT + if (currSetup.SetupSimInt.Count > 0) + { + foreach (var item in currSetup.SetupSimInt) + { + simInt = simValInt(doProd, item.Key, item.Value); + currRow = $"{CodIOB};{dtCurs:yyyy-MM-dd HH:mm:ss.fff};{item.Key};{simInt};{idxCount++}"; + rows.Add(currRow); + dtCurs = dtCurs.AddMilliseconds(rnd.Next(5, 50)); + } + } + + // poi gli item FLOAT + if (currSetup.SetupSimReal.Count > 0) + { + foreach (var item in currSetup.SetupSimReal) + { + simReal = simValReal(doProd, item.Key, item.Value); + currRow = $"{CodIOB};{dtCurs:yyyy-MM-dd HH:mm:ss.fff};{item.Key};{simInt};{idxCount++}"; + rows.Add(currRow); + dtCurs = dtCurs.AddMilliseconds(rnd.Next(5, 50)); + } + } + + // infine certo gli items basati su datetime + + + +#if false + currRow = $"{CodIOB};{dtCurs:yyyy-MM-dd HH:mm:ss.fff};kgImp;{valReq};{idxCount++}"; + rows.Add(currRow); + dtCurs = dtCurs.AddMilliseconds(rnd.Next(50, 300)); + currRow = $"{CodIOB};{dtCurs:yyyy-MM-dd HH:mm:ss.fff};kgAct;{valCurr};{idxCount++}"; + rows.Add(currRow); + // incremento peso... SE <= max... + if (valCurr < valTo) + { + valCurr += rnd.Next(stepMin / valStep, stepMax / valStep) * valStep; + } +#endif + dtCurs = dtCurs.AddMilliseconds(rnd.Next(27000, 33000)); + // reset counter + idxCount = idxCount <= 9999 ? idxCount : 0; + } + return rows; + } + /// + /// Simulazione valore int secondo tab transcodifica: + /// doProd=true --> simulo 50° percentile in su, altrimenti primi 50 percentili... + /// + /// + /// + /// + /// + protected int simValInt(bool doProd, string codFlux, Dictionary transcMap) + { + int result = 0; + // se è in prod --> 50° perc in su... + int rawSim = rnd.Next(0, 50) + (doProd ? 50 : 0); + if (currSetup.SetupSimInt.ContainsKey(codFlux)) + { + // transcodifico + var val0 = transcMap + .Where(x => x.Key <= rawSim) + .OrderByDescending(x => x.Value) + .FirstOrDefault(); + var val1 = transcMap + .Where(x => x.Key >= rawSim) + .OrderBy(x => x.Value) + .FirstOrDefault(); + result = val0.Value + (int)Math.Round((double)(val1.Value - val0.Value) * (rawSim - val0.Key) / (val1.Key - val0.Key), 0); + } + return result; + } + /// + /// Simulazione valore int secondo tab transcodifica: + /// doProd=true --> simulo 50° percentile in su, altrimenti primi 50 percentili... + /// + /// + /// + /// + /// + protected double simValReal(bool doProd, string codFlux, Dictionary transcMap) + { + double result = 0; + // se è in prod --> 50° perc in su... + int rawSim = rnd.Next(0, 50) + (doProd ? 50 : 0); + if (currSetup.SetupSimInt.ContainsKey(codFlux)) + { + // transcodifico + var val0 = transcMap + .Where(x => x.Key <= rawSim) + .OrderByDescending(x => x.Value) + .FirstOrDefault(); + var val1 = transcMap + .Where(x => x.Key >= rawSim) + .OrderBy(x => x.Value) + .FirstOrDefault(); + result = val0.Value + Math.Round((val1.Value - val0.Value) * (rawSim - val0.Key) / (val1.Key - val0.Key), 0); + } + return result; + } + #endregion Protected Methods } } \ No newline at end of file diff --git a/MapoDataFiller/FluxStats.cs b/MapoDataFiller/FluxStats.cs index c90a84f..202bdd5 100644 --- a/MapoDataFiller/FluxStats.cs +++ b/MapoDataFiller/FluxStats.cs @@ -12,8 +12,8 @@ namespace MapoDataFiller public class SimSetup { public Dictionary> SetupSimInt { get; set; } = new Dictionary>(); - public Dictionary> SetupSimFloat { get; set; } = new Dictionary>(); - public Dictionary> SetupDtData { get; set; } = new Dictionary>(); + public Dictionary> SetupSimReal { get; set; } = new Dictionary>(); + public Dictionary> SetupDtData { get; set; } = new Dictionary>(); public static SimSetup readConf(string filePath) {