228 lines
6.8 KiB
C#
228 lines
6.8 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using MP.MONO.Core;
|
|
using MP.MONO.Core.DTO;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.MONO.Data.Controllers
|
|
{
|
|
/// <summary>
|
|
/// Classe per generazione dati simulati
|
|
/// </summary>
|
|
public class SimController : IDisposable
|
|
{
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database context
|
|
//Log.Info("Dispose di GWMSController");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce stato Macchina simulato come DTO
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public MachineDTO MachineGetStatus()
|
|
{
|
|
Random rand = new Random();
|
|
int maxRun = 5;
|
|
int maxExe = 7;
|
|
|
|
MachineDTO currMachDto = new MachineDTO()
|
|
{
|
|
Manufacturer = "Egalware",
|
|
Model = "SIM Machine",
|
|
Name = "DEMO 01",
|
|
SerNumber = "2022-0001",
|
|
Mode = $"{(Enums.MachRunMode)rand.Next(0, maxRun)}",
|
|
Status = $"{(Enums.MachExeStatus)rand.Next(0, maxExe)}"
|
|
};
|
|
|
|
return currMachDto;
|
|
}
|
|
|
|
|
|
public ProductionDTO MachineGetProd()
|
|
{
|
|
// !!!FIXME TODO... è fake...
|
|
|
|
Random rand = new Random();
|
|
int stdCycle = 5;
|
|
|
|
ProductionDTO currMachDto = new ProductionDTO()
|
|
{
|
|
Order = "ODL Test",
|
|
ItemCode = "ART.0000123",
|
|
ProgName = "P000012",
|
|
CurrQty = DateTime.Now.Minute + rand.Next(1, 40),
|
|
OrderQty = 100,
|
|
CycleTimeMin = rand.NextDouble() * stdCycle,
|
|
Message = "...simulated data..."
|
|
};
|
|
|
|
Task.Delay(400).Wait();
|
|
|
|
return currMachDto;
|
|
}
|
|
|
|
public List<DisplayDataDTO> MachineGetParameters()
|
|
{
|
|
List<DisplayDataDTO> answ = new List<DisplayDataDTO>();
|
|
|
|
// !!!FIXME TODO... è fake...
|
|
|
|
Random rand = new Random();
|
|
int stdCycle = 5;
|
|
|
|
#if false
|
|
var currVal = rand.NextDouble();
|
|
DisplayDataDTO displ01 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "OEE",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("P1"),
|
|
Type = "OEE-75-90"
|
|
};
|
|
answ.Add(displ01);
|
|
|
|
currVal = rand.NextDouble();
|
|
DisplayDataDTO displ02 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "Avail",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("P1"),
|
|
Type = "AVAIL-50-80"
|
|
};
|
|
answ.Add(displ02);
|
|
|
|
currVal = rand.NextDouble();
|
|
DisplayDataDTO displ03 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "Order fulfill",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("P1"),
|
|
Type = "ORDER"
|
|
};
|
|
answ.Add(displ03);
|
|
|
|
double minTCiclo = stdCycle * rand.NextDouble();
|
|
TimeSpan durTCycle = TimeSpan.FromMinutes(minTCiclo);
|
|
DisplayDataDTO displ04 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "Cycle time",
|
|
ValueNum = 0,
|
|
IsNumeric = false,
|
|
Value = $"{durTCycle.Hours:00}:{durTCycle.Minutes:00}:{durTCycle.Seconds:00}",
|
|
Type = "TCycle"
|
|
};
|
|
answ.Add(displ04);
|
|
#endif
|
|
double currVal = 0;
|
|
currVal = rand.Next(10, 120) * 100;
|
|
DisplayDataDTO displ01 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "SPEED",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N0"),
|
|
Type = "SPEED-5000-10000"
|
|
};
|
|
answ.Add(displ01);
|
|
|
|
currVal = rand.Next(10, 100) * 100;
|
|
DisplayDataDTO displ02 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "FEED",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N0"),
|
|
Type = "FEED-3000-5000"
|
|
};
|
|
answ.Add(displ02);
|
|
|
|
currVal = rand.NextDouble() * 1.2;
|
|
DisplayDataDTO displ03 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "SPINDLE LOAD",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("P0"),
|
|
Type = "ORDER"
|
|
};
|
|
answ.Add(displ03);
|
|
|
|
currVal = rand.NextDouble() * 5000;
|
|
DisplayDataDTO displ04 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "X POS",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N1"),
|
|
Type = "POS"
|
|
};
|
|
answ.Add(displ04);
|
|
|
|
currVal = rand.NextDouble() * 10000;
|
|
DisplayDataDTO displ05 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "Y POS",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N1"),
|
|
Type = "POS"
|
|
};
|
|
answ.Add(displ05);
|
|
|
|
currVal = rand.NextDouble() * -3000;
|
|
DisplayDataDTO displ06 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "Z POS",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N1"),
|
|
Type = "POS"
|
|
};
|
|
answ.Add(displ06);
|
|
|
|
|
|
Task.Delay(200).Wait();
|
|
|
|
return answ;
|
|
}
|
|
|
|
public Dictionary<string, string> GetCurrentParameters()
|
|
{
|
|
Dictionary<string, string>? ParametersList = new Dictionary<string, string>();
|
|
ParametersList.Add("Speed", $"{Random.Shared.Next(0, 5000)}");
|
|
ParametersList.Add("Feed", $"{Random.Shared.Next(0, 10000)}");
|
|
ParametersList.Add("Load", $"{Random.Shared.Next(0, 100)}");
|
|
//return ParametersList;
|
|
|
|
var newParamList = Enumerable.Range(1, 10)
|
|
.ToDictionary(x => $"Par{x:00}", x => $"{Random.Shared.Next(0, 1000)}");
|
|
foreach (var item in newParamList)
|
|
{
|
|
ParametersList.Add(item.Key, item.Value);
|
|
}
|
|
return ParametersList;
|
|
}
|
|
}
|
|
}
|