OK x sim file fluxlog

This commit is contained in:
Samuele Locatelli
2023-05-04 19:28:01 +02:00
parent b11f14b235
commit f543810385
4 changed files with 91 additions and 70 deletions
+48 -25
View File
@@ -26,19 +26,16 @@ namespace MapoDataFiller.Filler
/// Restituisce elenco righe da caricare sul DB dato periodo indicato
/// </summary>
/// <param name="fillMode"></param>
/// <param name="fileOutReq"></param>
/// <param name="currDay"></param>
/// <returns></returns>
public SimBlock GetDataRows(string fillMode, string fileOutReq, DayConf currDay)
public SimBlock GetDataRows(string fillMode, DayConf currDay)
{
SimBlock answ = new SimBlock();
List<string> flRows = new List<string>();
List<string> evRows = new List<string>();
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<string> IC_OX_getFlRows(DateTime dtStart, DateTime dtEnd, bool doProd, int valReq, int valTo, ref int idxCount)
/// <summary>
/// Simulo un blocco dati FL
/// </summary>
/// <param name="dtStart"></param>
/// <param name="dtEnd"></param>
/// <param name="doProd"></param>
/// <param name="valReq"></param>
/// <param name="valTo"></param>
/// <param name="idxCount"></param>
/// <returns></returns>
protected List<string> IC_OX_getFlRows(DateTime dtStart, DateTime dtEnd, bool doProd, int valReq, ref int idxCount, ref int valCurr)
{
List<string> rows = new List<string>();
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;
}
-2
View File
@@ -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";
}
+43 -42
View File
@@ -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();
}
}
// 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);
}
}
-1
View File
@@ -2,6 +2,5 @@
ConfDir: C:\temp\Interclays
FillMode: Interclays02
HasHeader: true
FileOutReq: FL
TimeTable: Interclays02.csv
OutFolder: C:\temp\Interclays\Out