update x simulazione FL interclays01

This commit is contained in:
Samuele Locatelli
2023-05-08 17:45:46 +02:00
parent c77e776ca7
commit 42cd703d0d
2 changed files with 192 additions and 28 deletions
+190 -26
View File
@@ -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 @@
/// <summary>
/// Simulo un blocco dati FL
/// </summary>
/// <param name="CodIOB"></param>
/// <param name="dtStart"></param>
/// <param name="dtEnd"></param>
/// <param name="doProd"></param>
/// <param name="idxCount"></param>
/// <returns></returns>
protected List<string> IC_OX_getEvRows(DateTime dtStart, DateTime dtEnd, bool doProd, ref int idxCount)
protected List<string> IC_OX_getEvRows(string CodIOB, DateTime dtStart, DateTime dtEnd, bool doProd, ref int idxCount)
{
List<string> rows = new List<string>();
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 @@
/// <summary>
/// Simulo un blocco dati FL
/// </summary>
/// <param name="CodIOB"></param>
/// <param name="dtStart"></param>
/// <param name="dtEnd"></param>
/// <param name="doProd"></param>
@@ -178,7 +170,7 @@
/// <param name="idxCount"></param>
/// <param name="valCurr"></param>
/// <returns></returns>
protected List<string> IC_OX_getFlRows(DateTime dtStart, DateTime dtEnd, bool doProd, int valReq, ref int idxCount, ref int valCurr)
protected List<string> IC_OX_getFlRows(string CodIOB, DateTime dtStart, DateTime dtEnd, bool doProd, int valReq, ref int idxCount, ref int valCurr)
{
List<string> rows = new List<string>();
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;
}
/// <summary>
/// Simulo un blocco dati FL
/// </summary>
/// <param name="CodIOB"></param>
/// <param name="dtStart"></param>
/// <param name="dtEnd"></param>
/// <param name="doProd"></param>
/// <param name="idxCount"></param>
/// <returns></returns>
protected List<string> IC_ESS_getEvRows(string CodIOB, DateTime dtStart, DateTime dtEnd, bool doProd, ref int idxCount)
{
List<string> rows = new List<string>();
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;
}
/// <summary>
/// Simulo un blocco dati FL
/// </summary>
/// <param name="CodIOB"></param>
/// <param name="dtStart"></param>
/// <param name="dtEnd"></param>
/// <param name="doProd"></param>
/// <param name="valReq"></param>
/// <param name="idxCount"></param>
/// <param name="valCurr"></param>
/// <returns></returns>
protected List<string> IC_ESS_getFlRows(string CodIOB, DateTime dtStart, DateTime dtEnd, bool doProd, ref int idxCount)
{
List<string> rows = new List<string>();
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;
}
/// <summary>
/// Simulazione valore int secondo tab transcodifica:
/// doProd=true --> simulo 50° percentile in su, altrimenti primi 50 percentili...
/// </summary>
/// <param name="doProd"></param>
/// <param name="codFlux"></param>
/// <param name="transcMap"></param>
/// <returns></returns>
protected int simValInt(bool doProd, string codFlux, Dictionary<int, int> 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;
}
/// <summary>
/// Simulazione valore int secondo tab transcodifica:
/// doProd=true --> simulo 50° percentile in su, altrimenti primi 50 percentili...
/// </summary>
/// <param name="doProd"></param>
/// <param name="codFlux"></param>
/// <param name="transcMap"></param>
/// <returns></returns>
protected double simValReal(bool doProd, string codFlux, Dictionary<int, double> 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
}
}
+2 -2
View File
@@ -12,8 +12,8 @@ namespace MapoDataFiller
public class SimSetup
{
public Dictionary<string, Dictionary<int, int>> SetupSimInt { get; set; } = new Dictionary<string, Dictionary<int, int>>();
public Dictionary<string, Dictionary<int, float>> SetupSimFloat { get; set; } = new Dictionary<string, Dictionary<int, float>>();
public Dictionary<string, Dictionary<DateTime, float>> SetupDtData { get; set; } = new Dictionary<string, Dictionary<DateTime, float>>();
public Dictionary<string, Dictionary<int, double>> SetupSimReal { get; set; } = new Dictionary<string, Dictionary<int, double>>();
public Dictionary<string, Dictionary<DateTime, double>> SetupDtData { get; set; } = new Dictionary<string, Dictionary<DateTime, double>>();
public static SimSetup readConf(string filePath)
{