diff --git a/MapoDataFiller/Filler/InterClays.cs b/MapoDataFiller/Filler/InterClays.cs index 1b529d1..dea50f4 100644 --- a/MapoDataFiller/Filler/InterClays.cs +++ b/MapoDataFiller/Filler/InterClays.cs @@ -26,19 +26,16 @@ namespace MapoDataFiller.Filler /// Restituisce elenco righe da caricare sul DB dato periodo indicato /// /// - /// /// /// - public SimBlock GetDataRows(string fillMode, string fileOutReq, DayConf currDay) + public SimBlock GetDataRows(string fillMode, 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; + int valCurr = 0; // simulo periodi int numPer = rnd.Next(10, numPerMax); // calcolo durata media periodi in minuti @@ -46,59 +43,85 @@ namespace MapoDataFiller.Filler double preDelay = avgDurPer / 2; // imposto cursore DateTime dtStart = currDay.dtStart.AddMinutes(preDelay); - DateTime dtEnd = currDay.dtEnd; + DateTime dtEnd = dtStart; // 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}"); + answ.FlList.Add($"INTERCL_02;{dtStart:yyyy-MM-dd HH:mm:ss.fff};IOB-STATUS;IOB Started;{idxFl}"); + answ.EvList.Add($"INTERCL_02;{dtStart:yyyy-MM-dd HH:mm:ss.fff};14;ND;[{idxEv}] 00;0;-"); // calcolo durata successivi while (dtEnd < currDay.dtEnd) { - dtStart = dtStart.AddSeconds(30); + dtStart = dtEnd.AddSeconds(rnd.Next(25,35)); 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); + // verifico se DEVO finire caricamento... + if (valCurr < valReq) + { + doProd = true; + } + else + { - /*---------------------------------------- - // Gestione FluxLOG - ----------------------------------------*/ - // SE ho pesate --> genero target - valReq = doProd ? rnd.Next(valMin / valStep, valMax / valStep) * valStep : 0; - valAct = valReq + rnd.Next(0, valStep) * valStep; + // tiro a dadi x decidere SE ho pesate nel periodo... 5% dei casi + doProd = (rnd.Next(0, 100) <= 5); + + // FluxLOG: SE ho pesate --> genero target + valReq = doProd ? rnd.Next(valMin / valStep, valMax / valStep) * valStep : 0; + } // genero righe x periodo e sommo - var nextRows = IC_OX_getFlRows(dtStart, dtEnd, doProd, valReq, valAct, ref idxFl); + var nextRows = IC_OX_getFlRows(dtStart, dtEnd, doProd, valReq, ref idxFl, ref valCurr); // sommo righe answ.FlList.AddRange(nextRows); + + + /*---------------------------------------- // Gestione EventList ----------------------------------------*/ + } + + // aggiungo chiusura eventi... + dtStart = dtEnd.AddSeconds(rnd.Next(25, 35)); + answ.EvList.Add($"INTERCL_02;{dtStart:yyyy-MM-dd HH:mm:ss.fff};15;ND;[{idxEv}++] 01;0;-"); + dtStart = dtEnd.AddSeconds(rnd.Next(80, 180)); + answ.EvList.Add($"INTERCL_02;{dtStart:yyyy-MM-dd HH:mm:ss.fff};14;ND;[{idxEv}++] 00;0;-"); + // 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) + /// + /// Simulo un blocco dati FL + /// + /// + /// + /// + /// + /// + /// + /// + protected List IC_OX_getFlRows(DateTime dtStart, DateTime dtEnd, bool doProd, int valReq, ref int idxCount, ref int valCurr) { List rows = new List(); DateTime dtCurs = dtStart; + int valTo = doProd ? valReq + rnd.Next(0, valStep) * valStep : 0; + valCurr = valReq > 0 ? valCurr : 0; 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++}"; + currRow = $"INTERCL_02;{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... if (valCurr < valTo) { - valCurr += rnd.Next(stepMin, stepMax); + valCurr += rnd.Next(stepMin / valStep, stepMax / valStep) * valStep; } + // reset counter + idxCount = idxCount <= 9999 ? idxCount : 0; } return rows; } diff --git a/MapoDataFiller/MConf.cs b/MapoDataFiller/MConf.cs index 4144717..22c5366 100644 --- a/MapoDataFiller/MConf.cs +++ b/MapoDataFiller/MConf.cs @@ -15,7 +15,6 @@ namespace MapoDataFiller public string ConfDir { get; set; } = ""; public string FillMode { get; set; } = ""; public bool HasHeader { get; set; } = false; - public string FileOutReq { get; set; } = ""; public string TimeTable { get; set; } = ""; public string OutFolder { get; set; } = ""; @@ -24,7 +23,6 @@ namespace MapoDataFiller ConfDir = @"C:\temp\Interclays\"; FillMode = "NONE"; HasHeader = false; - FileOutReq = "FL"; TimeTable = "Demo.csv"; OutFolder = @"C:\temp\Interclays\Out"; } diff --git a/MapoDataFiller/Program.cs b/MapoDataFiller/Program.cs index c804a96..f209a4e 100644 --- a/MapoDataFiller/Program.cs +++ b/MapoDataFiller/Program.cs @@ -47,48 +47,49 @@ while (!headOK) headOK = AnsiConsole.Confirm("Confermi HasHeader?"); } -// verifico se devo generare i file... -if (currConf.FileOutReq == "FL") +// leggo timetable +string filePath = Path.Combine(currConf.ConfDir, currConf.TimeTable); +if (File.Exists(filePath)) { - // leggo timetable - string filePath = Path.Combine(currConf.ConfDir, currConf.TimeTable); - if (File.Exists(filePath)) + var righe = File.ReadAllLines(filePath).ToList(); + // se devo saltare + if (currConf.HasHeader) { - var righe = File.ReadAllLines(filePath).ToList(); - // se devo saltare - if (currConf.HasHeader) - { - righe = righe.Skip(1).ToList(); - } - // svuoto cartella output - if(!Directory.Exists(currConf.OutFolder)) - { - Directory.CreateDirectory(currConf.OutFolder); - } - var fileList = Directory.GetFiles(currConf.OutFolder); - foreach ( var file in fileList ) - { - File.Delete(file); - } - - // verifico quale oggetto sim avviare... x ora SOLO interclays - InterClays currSim = new InterClays(); - // ciclo su ogni record - foreach (var riga in righe) - { - // recupero dati del giorno corrente - var giornata = new DayConf("CsvDateDur", riga); - - var elencoRighe = currSim.GetDataRows(currConf.FillMode, currConf.FileOutReq, giornata); - // scrivo sul file mensile i dati del singolo giorno... - string monthFile = Path.Combine("", $"{currConf.FillMode}_{currConf.FileOutReq}_{giornata.dtStart:yyyy-MM}.csv"); - string fileOutPath=Path.Combine(currConf.OutFolder, monthFile); - if(!File.Exists(fileOutPath)) - { - File.Create(fileOutPath); - } - // vado in append... - File.AppendAllLines(fileOutPath, elencoRighe); - } + righe = righe.Skip(1).ToList(); } -} \ No newline at end of file + // svuoto cartella output + if (!Directory.Exists(currConf.OutFolder)) + { + Directory.CreateDirectory(currConf.OutFolder); + } + var fileList = Directory.GetFiles(currConf.OutFolder); + foreach (var file in fileList) + { + File.Delete(file); + } + + // verifico quale oggetto sim avviare... x ora SOLO interclays + InterClays currSim = new InterClays(); + // ciclo su ogni record + foreach (var riga in righe) + { + // recupero dati del giorno corrente + var giornata = new DayConf("CsvDateDur", riga); + + var simDataBlock = currSim.GetDataRows(currConf.FillMode, giornata); + // scrivo sul file mensile i dati del singolo giorno... + string pathFileFL = Path.Combine(currConf.OutFolder, $"{currConf.FillMode}_FL_{giornata.dtStart:yyyy-MM}.csv"); + if (!File.Exists(pathFileFL)) + { + File.WriteAllText(pathFileFL,""); + } + string pathFileEL = Path.Combine(currConf.OutFolder, $"{currConf.FillMode}_EL_{giornata.dtStart:yyyy-MM}.csv"); + if (!File.Exists(pathFileEL)) + { + File.WriteAllText(pathFileEL, ""); + } + // vado in append... + File.AppendAllLines(pathFileFL, simDataBlock.FlList); + File.AppendAllLines(pathFileEL, simDataBlock.EvList); + } +} diff --git a/MapoDataFiller/conf.yaml b/MapoDataFiller/conf.yaml index a185368..34ae8e5 100644 --- a/MapoDataFiller/conf.yaml +++ b/MapoDataFiller/conf.yaml @@ -2,6 +2,5 @@ ConfDir: C:\temp\Interclays FillMode: Interclays02 HasHeader: true -FileOutReq: FL TimeTable: Interclays02.csv OutFolder: C:\temp\Interclays\Out