109 lines
4.2 KiB
C#
109 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
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();
|
|
|
|
/// <summary>
|
|
/// 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)
|
|
{
|
|
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;
|
|
// 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<string> IC_OX_getFlRows(DateTime dtStart, DateTime dtEnd, bool doProd, int valReq, int valTo, ref int idxCount)
|
|
{
|
|
List<string> rows = new List<string>();
|
|
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;
|
|
}
|
|
|
|
|
|
}
|
|
}
|