-
+
diff --git a/MP.MONO.UI/Pages/Stats.razor b/MP.MONO.UI/Pages/MachStats.razor
similarity index 65%
rename from MP.MONO.UI/Pages/Stats.razor
rename to MP.MONO.UI/Pages/MachStats.razor
index 4097b04..94fb65e 100644
--- a/MP.MONO.UI/Pages/Stats.razor
+++ b/MP.MONO.UI/Pages/MachStats.razor
@@ -1,13 +1,13 @@
-@page "/Stats"
+@page "/MachStats"
diff --git a/MP.MONO.UI/Shared/NavMenu.razor b/MP.MONO.UI/Shared/NavMenu.razor
index 75fe493..c61feb2 100644
--- a/MP.MONO.UI/Shared/NavMenu.razor
+++ b/MP.MONO.UI/Shared/NavMenu.razor
@@ -16,7 +16,7 @@
-
+
STATS
diff --git a/MachineSim/MachineSim.csproj b/MachineSim/MachineSim.csproj
index de17984..82a98b7 100644
--- a/MachineSim/MachineSim.csproj
+++ b/MachineSim/MachineSim.csproj
@@ -21,6 +21,9 @@
+
+ Always
+
Always
diff --git a/MachineSim/Program.cs b/MachineSim/Program.cs
index 7ef8281..ed08d3e 100644
--- a/MachineSim/Program.cs
+++ b/MachineSim/Program.cs
@@ -30,11 +30,13 @@ Thread threadStatus = new Thread(simStatus);
Thread threadAlarms = new Thread(simAlarms);
Thread threadParams = new Thread(simParameters);
Thread threadProd = new Thread(simProd);
+Thread threadMachStat = new Thread(simMachStat);
threadStatus.Start();
threadAlarms.Start();
threadParams.Start();
threadProd.Start();
+threadMachStat.Start();
///
/// Hash Redis contenente i dati MP di una specifico TYPE (es StatusMacchina, StateMachineIngressi, ...)
@@ -105,7 +107,7 @@ void simStatus()
do
{
// recupero uno stato simulato
- var newStatus = currSimGen.MachineGetStatus();
+ var newStatus = currSimGen.getStatus();
string rawData = JsonConvert.SerializeObject(newStatus);
saveAndSendMessage(mHash("Machine:Status:Current"), rawData, "status", rawData);
@@ -122,10 +124,27 @@ void simProd()
do
{
// recupero uno stato simulato
- var newStatus = currSimGen.MachineGetProd();
+ var newStatus = currSimGen.getProd();
string rawData = JsonConvert.SerializeObject(newStatus);
saveAndSendMessage(mHash("Machine:Production:Current"), rawData, "production", rawData);
+ // attesa random
+ Thread.Sleep(rand.Next(minPeriod, maxPeriod));
+ } while (true);
+}
+
+void simMachStat()
+{
+ int minPeriod = 3000;
+ int maxPeriod = 5000;
+
+ do
+ {
+ // recupero uno stato simulato
+ var newVal = currSimGen.getProdStats();
+ string rawData = JsonConvert.SerializeObject(newVal);
+ saveAndSendMessage(mHash("Machine:MachStats:Current"), rawData, "machstats", rawData);
+
// attesa random
Thread.Sleep(rand.Next(minPeriod, maxPeriod));
} while (true);
diff --git a/MachineSim/SimMachStat.json b/MachineSim/SimMachStat.json
new file mode 100644
index 0000000..702cc02
--- /dev/null
+++ b/MachineSim/SimMachStat.json
@@ -0,0 +1,14 @@
+[
+ {
+ "Order": 0,
+ "Type": "OEE-75-90",
+ "Title": "OEE",
+ "Value": "0.5",
+ "ValueNum": 0.5,
+ "MinVal": 0.4,
+ "MaxVal": 1,
+ "SimMean": 0.2,
+ "SimStd": 0.2,
+ "DisplFormat": "P1"
+ }
+]
\ No newline at end of file
diff --git a/MachineSim/Simulator.cs b/MachineSim/Simulator.cs
index 7380025..0932610 100644
--- a/MachineSim/Simulator.cs
+++ b/MachineSim/Simulator.cs
@@ -2,11 +2,6 @@
using MP.MONO.Core;
using MP.MONO.Core.DTO;
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace MachineSim
{
@@ -15,13 +10,18 @@ namespace MachineSim
///
public class Simulator
{
- protected string basePath = "";
- protected string paramFileName = "SimParams.json";
+ #region Protected Fields
+ protected string basePath = "";
+ protected List currSimMachStat = new List();
+ protected List currSimPar = new List();
+ protected string paramFileName = "SimParams.json";
protected Random rand = new Random();
- protected List? currSimPar = new List();
+ #endregion Protected Fields
+
+ #region Public Constructors
public Simulator(string _basePath)
{
@@ -29,7 +29,11 @@ namespace MachineSim
setupConfig();
}
- private void setupConfig()
+ #endregion Public Constructors
+
+ #region Private Methods
+
+ private void setupConf(string paramFileName, ref List localObj)
{
string fullPath = Path.Combine(basePath, paramFileName);
if (File.Exists(fullPath))
@@ -37,28 +41,38 @@ namespace MachineSim
var rawData = File.ReadAllText(fullPath);
if (!string.IsNullOrEmpty(rawData))
{
- currSimPar = JsonConvert.DeserializeObject>(rawData);
+ localObj = JsonConvert.DeserializeObject>(rawData);
}
}
}
- ///
- /// Calcola prox valore simulato dati i parametri rand configurati
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public double simNext(double CurrVal, double MinVal, double MaxVal, double sMean, double sStd)
+ private void setupConfig()
{
- double innov = Normal.Sample(sMean, sStd);
- CurrVal += innov;
- // verifico estremi...
- CurrVal = CurrVal > MaxVal ? MaxVal : CurrVal;
- CurrVal = CurrVal < MinVal ? MinVal : CurrVal;
- return CurrVal;
+ // setup conf parametri
+ setupConf("SimParams.json", ref currSimPar);
+ // setup conf machStat
+ setupConf("SimMachStat.json", ref currSimMachStat);
+ }
+
+ #endregion Private Methods
+
+ #region Public Methods
+
+ public List getAlarms()
+ {
+ List activeAlarms = new List();
+ //int alarmCode = rand.Next(0, 255);
+ int alarmCode = rand.Next(0, 160);
+ // se >= 128 --> 0 (no alarm)
+ alarmCode = alarmCode <= 127 ? alarmCode : 0;
+ for (int i = 0; i < 8; i++)
+ {
+ if ((alarmCode & (1 << i)) != 0)
+ {
+ activeAlarms.Add($"Alarm {i:000}");
+ }
+ }
+ return activeAlarms;
}
public List getParameters()
@@ -134,18 +148,14 @@ namespace MachineSim
Value = $"{durTCycle.Hours:00}:{durTCycle.Minutes:00}:{durTCycle.Seconds:00}",
Type = "TCycle"
};
- answ.Add(displ04);
+ answ.Add(displ04);
#endif
return answ;
}
- public ProductionDTO MachineGetProd()
+ public ProductionDTO getProd()
{
-
-#if false
- Random rand = new Random();
-#endif
int stdCycle = 5;
ProductionDTO currMachDto = new ProductionDTO()
@@ -161,16 +171,38 @@ namespace MachineSim
return currMachDto;
}
+ public List getProdStats()
+ {
+ List answ = new List();
+
+ // genero a partire dall'elenco configurato da simulare...
+ answ = currSimMachStat.Select(i => new DisplayDataDTO()
+ {
+ IsNumeric = i.IsNumeric,
+ MaxVal = i.MaxVal,
+ MinVal = i.MinVal,
+ Order = i.Order,
+ Title = i.Title,
+ Type = i.Type,
+ ValueNum = simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd),
+ DisplFormat = i.DisplFormat
+ //Value = $"{getNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd):N3}",
+ }).ToList();
+
+ foreach (var item in answ)
+ {
+ item.Value = $"{item.ValueNum.ToString(item.DisplFormat)}";
+ }
+
+ return answ;
+ }
///
/// Restituisce stato Macchina simulato come DTO
///
///
- public MachineDTO MachineGetStatus()
+ public MachineDTO getStatus()
{
-#if false
- Random rand = new Random();
-#endif
int maxRun = 5;
int maxExe = 7;
@@ -187,21 +219,25 @@ namespace MachineSim
return currMachDto;
}
- public List getAlarms()
+ ///
+ /// Calcola prox valore simulato dati i parametri rand configurati
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public double simNext(double CurrVal, double MinVal, double MaxVal, double sMean, double sStd)
{
- List activeAlarms = new List();
- //int alarmCode = rand.Next(0, 255);
- int alarmCode = rand.Next(0, 160);
- // se >= 128 --> 0 (no alarm)
- alarmCode = alarmCode <= 127 ? alarmCode : 0;
- for (int i = 0; i < 8; i++)
- {
- if ((alarmCode & (1 << i)) != 0)
- {
- activeAlarms.Add($"Alarm {i:000}");
- }
- }
- return activeAlarms;
+ double innov = Normal.Sample(sMean, sStd);
+ CurrVal += innov;
+ // verifico estremi...
+ CurrVal = CurrVal > MaxVal ? MaxVal : CurrVal;
+ CurrVal = CurrVal < MinVal ? MinVal : CurrVal;
+ return CurrVal;
}
+
+ #endregion Public Methods
}
-}
+}
\ No newline at end of file