diff --git a/MapoDataFiller/Filler/InterClays.cs b/MapoDataFiller/Filler/InterClays.cs index d5f5b8f..1b529d1 100644 --- a/MapoDataFiller/Filler/InterClays.cs +++ b/MapoDataFiller/Filler/InterClays.cs @@ -8,6 +8,19 @@ namespace MapoDataFiller.Filler { public class InterClays { + protected int valStep = 10; + protected int valMin = 500; + protected int valMax = 15000; + protected int numSec = 30; + protected int stepMin = 50; + protected int stepMax = 150; + + protected int waitMin = 10; + protected int waitMax = 240; + + protected int numPerMax = 50; + + protected Random rnd = new Random(); /// /// Restituisce elenco righe da caricare sul DB dato periodo indicato @@ -16,11 +29,80 @@ namespace MapoDataFiller.Filler /// /// /// - public List GetDataRows(string fillMode, string fileOutReq, DayConf currDay) + public SimBlock GetDataRows(string fillMode, string fileOutReq, DayConf currDay) + { + SimBlock answ = new SimBlock(); + List flRows = new List(); + List evRows = new List(); + int idxEv = 0; + int idxFl = 0; + bool doProd = false; + int valReq = 0; + int valAct = 0; + // simulo periodi + int numPer = rnd.Next(10, numPerMax); + // calcolo durata media periodi in minuti + double avgDurPer = (currDay.dtEnd.Subtract(currDay.dtStart).TotalMinutes) / numPer; + double preDelay = avgDurPer / 2; + // imposto cursore + DateTime dtStart = currDay.dtStart.AddMinutes(preDelay); + DateTime dtEnd = currDay.dtEnd; + // per prima cosa aggiungo start dopo un delay di max 1/2 periodo... + flRows.Add($"INTERCL_02;{dtStart:yyyy-MM-dd HH:mm:ss.fff};IOB-STATUS;IOB Started;{idxFl}"); + evRows.Add($"INTERCL_02;{dtStart:yyyy-MM-dd HH:mm:ss.fff};14;ND;-;1;{idxEv}"); + // calcolo durata successivi + while (dtEnd < currDay.dtEnd) + { + dtStart = dtStart.AddSeconds(30); + dtEnd = dtStart.AddMinutes(avgDurPer * rnd.Next(600, 1400) / 1000); + // tiro a dadi x decidere SE ho pesate nel periodo... 5% dei casi + doProd = (rnd.Next(0, 100) <= 5); + + /*---------------------------------------- + // Gestione FluxLOG + ----------------------------------------*/ + // SE ho pesate --> genero target + valReq = doProd ? rnd.Next(valMin / valStep, valMax / valStep) * valStep : 0; + valAct = valReq + rnd.Next(0, valStep) * valStep; + // genero righe x periodo e sommo + var nextRows = IC_OX_getFlRows(dtStart, dtEnd, doProd, valReq, valAct, ref idxFl); + // sommo righe + answ.FlList.AddRange(nextRows); + + /*---------------------------------------- + // Gestione EventList + ----------------------------------------*/ + } + // ritorno + answ.EvList = evRows; + answ.FlList = flRows; + return answ; + } + + protected List IC_OX_getFlRows(DateTime dtStart, DateTime dtEnd, bool doProd, int valReq, int valTo, ref int idxCount) { List rows = new List(); - + DateTime dtCurs = dtStart; + string currRow = ""; + int valCurr = 0; + // genera i dati secondo lo schema configurato... + while (dtCurs < dtEnd) + { + currRow = $"INTERCL_02;{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;{valReq};{idxCount++}"; + rows.Add(currRow); + dtCurs = dtCurs.AddMilliseconds(rnd.Next(27000, 33000)); + // incremento peso... SE <= max... + if (valCurr < valTo) + { + valCurr += rnd.Next(stepMin, stepMax); + } + } return rows; } + + } } diff --git a/MapoDataFiller/SimBlock.cs b/MapoDataFiller/SimBlock.cs new file mode 100644 index 0000000..80e5262 --- /dev/null +++ b/MapoDataFiller/SimBlock.cs @@ -0,0 +1,12 @@ +namespace MapoDataFiller +{ + public class SimBlock + { + #region Public Properties + + public List EvList { get; set; } = new List(); + public List FlList { get; set; } = new List(); + + #endregion Public Properties + } +} \ No newline at end of file