From 3461efaf7677fac7b13cc314bdbee440dcddddd1 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 5 Jul 2022 17:14:05 +0200 Subject: [PATCH] Fix SIM - ok sim tools (decrescenti) - ok sim allarmi --- MP.MONO.ADAPTER.OPC/IobOpcUa.cs | 109 ++-------------------- MP.MONO.ANALYZER/MP.MONO.ANALYZER.csproj | 2 +- MP.MONO.ANALYZER/Resources/ChangeLog.html | 2 +- MP.MONO.ANALYZER/Resources/VersNum.txt | 2 +- MP.MONO.ANALYZER/Resources/manifest.xml | 2 +- MP.MONO.DECODER/MP.MONO.DECODER.csproj | 2 +- MP.MONO.DECODER/Resources/ChangeLog.html | 2 +- MP.MONO.DECODER/Resources/VersNum.txt | 2 +- MP.MONO.DECODER/Resources/manifest.xml | 2 +- MP.MONO.SIM/Resources/ChangeLog.html | 2 +- MP.MONO.SIM/Resources/VersNum.txt | 2 +- MP.MONO.SIM/Resources/manifest.xml | 2 +- MP.MONO.SIM/Simulator.cs | 108 ++++++++++++--------- MP.MONO.SIM/conf/SimTools.json | 26 +++--- MP.MONO.UI/MP.MONO.UI.csproj | 2 +- MP.MONO.UI/Resources/ChangeLog.html | 2 +- MP.MONO.UI/Resources/VersNum.txt | 2 +- MP.MONO.UI/Resources/manifest.xml | 2 +- 18 files changed, 100 insertions(+), 173 deletions(-) diff --git a/MP.MONO.ADAPTER.OPC/IobOpcUa.cs b/MP.MONO.ADAPTER.OPC/IobOpcUa.cs index 4640455..8aed9ff 100644 --- a/MP.MONO.ADAPTER.OPC/IobOpcUa.cs +++ b/MP.MONO.ADAPTER.OPC/IobOpcUa.cs @@ -786,17 +786,18 @@ namespace MP.MONO.ADAPTER.OPC currItem.Value = rawDataVal; } logTrace($"R&S | ParamKList | {uuid} | {currItem.Value}"); - // parametri: inviati come DTO -#if false + // genero un dictionary di valori stringa / double e lo serializzo... var dataDict = ParamStatus.ToDictionary(x => x.Title, x => x.Value); string payloadParams = JsonConvert.SerializeObject(dataDict); // invio saveAndSendMessage(Constants.PARAMS_ACT_KEY, Constants.PARAMS_RAW_QUEUE, payloadParams); -#endif +#if false + // parametri: inviati come DTO string payloadParams = JsonConvert.SerializeObject(ParamStatus); // invio - saveAndSendMessage(Constants.PARAMS_CURR_KEY, Constants.PARAMS_M_QUEUE, payloadParams); + saveAndSendMessage(Constants.PARAMS_CURR_KEY, Constants.PARAMS_M_QUEUE, payloadParams); +#endif } // Allarmi @@ -1237,121 +1238,23 @@ namespace MP.MONO.ADAPTER.OPC /// private void setupGroupConf() { - // leggo e salvo conf varie... - - // ActLog -#if false - string fullPath = Path.Combine(configPath, "ActLog.json"); - if (File.Exists(fullPath)) - { - var rawData = File.ReadAllText(fullPath); - if (!string.IsNullOrEmpty(rawData)) - { - ActLogStatus = JsonConvert.DeserializeObject>(rawData); - // salvo in redis! - redisDb.StringSetAsync(Constants.ACTLOG_CONF_KEY, JsonConvert.SerializeObject(ActLogStatus)); - // calcolo l'elenco dei cod univoci da gestire e lo salvo... - ActLogKList = ActLogStatus.Select(x => x.ExtCode).ToList(); - } - } -#endif + // leggo e salvo conf varie (dati x decodifica e gestione) ActLogStatus = confManager.getActLog(); ActLogKList = ActLogStatus.Select(x => x.ExtCode).ToList(); -#if false - fullPath = Path.Combine(configPath, "Tools.json"); - if (File.Exists(fullPath)) - { - var rawData = File.ReadAllText(fullPath); - if (!string.IsNullOrEmpty(rawData)) - { - ToolStatus = JsonConvert.DeserializeObject>(rawData); - // salvo in redis! - redisDb.StringSetAsync(Constants.TOOLS_CONF_KEY, JsonConvert.SerializeObject(ToolStatus)); - // calcolo l'elenco dei cod univoci da gestire e lo salvo... - ToolKList = ToolStatus.Select(x => x.ExtCode).ToList(); - } - } -#endif - ToolStatus = confManager.getTools(); ToolKList = ActLogStatus.Select(x => x.ExtCode).ToList(); -#if false - fullPath = Path.Combine(configPath, "Parameters.json"); - if (File.Exists(fullPath)) - { - var rawData = File.ReadAllText(fullPath); - if (!string.IsNullOrEmpty(rawData)) - { - ParamStatus = JsonConvert.DeserializeObject>(rawData); - // salvo in redis! - redisDb.StringSetAsync(Constants.PARAMS_CONF_KEY, JsonConvert.SerializeObject(ParamStatus)); - // calcolo l'elenco dei cod univoci da gestire e lo salvo... - ParamKList = ParamStatus.Select(x => x.ExtCode).ToList(); - } - } -#endif - ParamStatus = confManager.getParamsConf(); ParamKList = ParamStatus.Select(x => x.ExtCode).ToList(); - -#if false - fullPath = Path.Combine(configPath, "Alarms.json"); - if (File.Exists(fullPath)) - { - var rawData = File.ReadAllText(fullPath); - if (!string.IsNullOrEmpty(rawData)) - { - AlarmsStatus = JsonConvert.DeserializeObject>(rawData); - // salvo in redis! - redisDb.StringSetAsync(Constants.ALARMS_ADAP_CONF_KEY, JsonConvert.SerializeObject(AlarmsStatus)); - // calcolo l'elenco dei cod univoci da gestire e lo salvo... - AlarmsKList = AlarmsStatus.Select(x => x.ExtCode).ToList(); - } - } -#endif - AlarmsStatus = confManager.getAlarmsConf(); AlarmsKList = AlarmsStatus.Select(x => x.ExtCode).ToList(); -#if false - fullPath = Path.Combine(configPath, "MPStatus.json"); - if (File.Exists(fullPath)) - { - var rawData = File.ReadAllText(fullPath); - if (!string.IsNullOrEmpty(rawData)) - { - MPStatus = JsonConvert.DeserializeObject>(rawData); - // salvo in redis! - redisDb.StringSetAsync(Constants.MP_STATUS_CONF_KEY, JsonConvert.SerializeObject(MPStatus)); - // calcolo l'elenco dei cod univoci da gestire e lo salvo... - MPKList = MPStatus.Select(x => x.ExtCode).ToList(); - } - } -#endif - MPStatus = confManager.getMPStatusConf(); MPKList = MPStatus.Select(x => x.ExtCode).ToList(); -#if false - fullPath = Path.Combine(configPath, "Counters.json"); - if (File.Exists(fullPath)) - { - var rawData = File.ReadAllText(fullPath); - if (!string.IsNullOrEmpty(rawData)) - { - CountStatus = JsonConvert.DeserializeObject>(rawData); - // salvo in redis! - redisDb.StringSetAsync(Constants.CNT_STATUS_CONF_KEY, JsonConvert.SerializeObject(CountStatus)); - // calcolo l'elenco dei cod univoci da gestire e lo salvo... - CountKList = CountStatus.Select(x => x.ExtCode).ToList(); - } - } -#endif - CountStatus = confManager.getCountersConf(); CountKList = CountStatus.Select(x => x.ExtCode).ToList(); diff --git a/MP.MONO.ANALYZER/MP.MONO.ANALYZER.csproj b/MP.MONO.ANALYZER/MP.MONO.ANALYZER.csproj index 0054c74..35e5092 100644 --- a/MP.MONO.ANALYZER/MP.MONO.ANALYZER.csproj +++ b/MP.MONO.ANALYZER/MP.MONO.ANALYZER.csproj @@ -6,7 +6,7 @@ enable enable AnyCPU;x86;x64 - 1.2.2207.515 + 1.2.2207.517 diff --git a/MP.MONO.ANALYZER/Resources/ChangeLog.html b/MP.MONO.ANALYZER/Resources/ChangeLog.html index ebd9c0d..e44fe41 100644 --- a/MP.MONO.ANALYZER/Resources/ChangeLog.html +++ b/MP.MONO.ANALYZER/Resources/ChangeLog.html @@ -1,6 +1,6 @@ MAPO-MONO -

Version: 1.2.2207.515

+

Version: 1.2.2207.517


Release Note:
  • diff --git a/MP.MONO.ANALYZER/Resources/VersNum.txt b/MP.MONO.ANALYZER/Resources/VersNum.txt index 920c248..9145d08 100644 --- a/MP.MONO.ANALYZER/Resources/VersNum.txt +++ b/MP.MONO.ANALYZER/Resources/VersNum.txt @@ -1 +1 @@ -1.2.2207.515 +1.2.2207.517 diff --git a/MP.MONO.ANALYZER/Resources/manifest.xml b/MP.MONO.ANALYZER/Resources/manifest.xml index 2a7d509..3b8d0ee 100644 --- a/MP.MONO.ANALYZER/Resources/manifest.xml +++ b/MP.MONO.ANALYZER/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.2.2207.515 + 1.2.2207.517 http://nexus.steamware.net/repository/SWS/MP.MONO.ANALYZER/stable/LAST/MP.Mon.zip http://nexus.steamware.net/repository/SWS/MP.MONO.ANALYZER/stable/LAST/ChangeLog.html false diff --git a/MP.MONO.DECODER/MP.MONO.DECODER.csproj b/MP.MONO.DECODER/MP.MONO.DECODER.csproj index d80905b..03976f4 100644 --- a/MP.MONO.DECODER/MP.MONO.DECODER.csproj +++ b/MP.MONO.DECODER/MP.MONO.DECODER.csproj @@ -6,7 +6,7 @@ enable enable AnyCPU;x86;x64 - 1.2.2207.515 + 1.2.2207.517 diff --git a/MP.MONO.DECODER/Resources/ChangeLog.html b/MP.MONO.DECODER/Resources/ChangeLog.html index ebd9c0d..e44fe41 100644 --- a/MP.MONO.DECODER/Resources/ChangeLog.html +++ b/MP.MONO.DECODER/Resources/ChangeLog.html @@ -1,6 +1,6 @@ MAPO-MONO -

    Version: 1.2.2207.515

    +

    Version: 1.2.2207.517


    Release Note:
    • diff --git a/MP.MONO.DECODER/Resources/VersNum.txt b/MP.MONO.DECODER/Resources/VersNum.txt index 920c248..9145d08 100644 --- a/MP.MONO.DECODER/Resources/VersNum.txt +++ b/MP.MONO.DECODER/Resources/VersNum.txt @@ -1 +1 @@ -1.2.2207.515 +1.2.2207.517 diff --git a/MP.MONO.DECODER/Resources/manifest.xml b/MP.MONO.DECODER/Resources/manifest.xml index 0e586bf..48654d5 100644 --- a/MP.MONO.DECODER/Resources/manifest.xml +++ b/MP.MONO.DECODER/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.2.2207.515 + 1.2.2207.517 http://nexus.steamware.net/repository/SWS/MP.MONO.DECODER/stable/LAST/MP.Mon.zip http://nexus.steamware.net/repository/SWS/MP.MONO.DECODER/stable/LAST/ChangeLog.html false diff --git a/MP.MONO.SIM/Resources/ChangeLog.html b/MP.MONO.SIM/Resources/ChangeLog.html index ebd9c0d..e44fe41 100644 --- a/MP.MONO.SIM/Resources/ChangeLog.html +++ b/MP.MONO.SIM/Resources/ChangeLog.html @@ -1,6 +1,6 @@ MAPO-MONO -

      Version: 1.2.2207.515

      +

      Version: 1.2.2207.517


      Release Note:
      • diff --git a/MP.MONO.SIM/Resources/VersNum.txt b/MP.MONO.SIM/Resources/VersNum.txt index 920c248..9145d08 100644 --- a/MP.MONO.SIM/Resources/VersNum.txt +++ b/MP.MONO.SIM/Resources/VersNum.txt @@ -1 +1 @@ -1.2.2207.515 +1.2.2207.517 diff --git a/MP.MONO.SIM/Resources/manifest.xml b/MP.MONO.SIM/Resources/manifest.xml index dade80b..e333ad2 100644 --- a/MP.MONO.SIM/Resources/manifest.xml +++ b/MP.MONO.SIM/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.2.2207.515 + 1.2.2207.517 http://nexus.steamware.net/repository/SWS/MP.MONO.SIM/stable/LAST/MP.Mon.zip http://nexus.steamware.net/repository/SWS/MP.MONO.SIM/stable/LAST/ChangeLog.html false diff --git a/MP.MONO.SIM/Simulator.cs b/MP.MONO.SIM/Simulator.cs index 8feddc6..f7e1c61 100644 --- a/MP.MONO.SIM/Simulator.cs +++ b/MP.MONO.SIM/Simulator.cs @@ -54,7 +54,7 @@ namespace MachineSim Order = i.Order, Title = i.Title, Type = i.Type, - ValueNum = simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd), + ValueNum = simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd, 1), DisplFormat = i.DisplFormat }).ToList(); @@ -160,9 +160,8 @@ namespace MachineSim Order = i.Order, Title = i.Title, Type = i.Type, - ValueNum = simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd), + ValueNum = simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd, 1), DisplFormat = i.DisplFormat - //Value = $"{getNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd):N3}", }).ToList(); foreach (var item in answ) @@ -186,9 +185,8 @@ namespace MachineSim Order = i.Order, Title = i.Title, Type = i.Type, - ValueNum = simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd, i.IsBoolean, i.TrueRatio), + ValueNum = simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd, i.IsBoolean ? 2 : 1, i.TrueRatio), DisplFormat = i.DisplFormat - //Value = $"{getNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd):N3}", }).ToList(); foreach (var item in answ) @@ -212,7 +210,7 @@ namespace MachineSim Order = i.Order, Title = i.Title, Type = i.Type, - ValueNum = simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd), + ValueNum = simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd, 1), DisplFormat = i.DisplFormat, CssIcon = i.CssIcon, EnablePlot = i.EnablePlot, @@ -231,7 +229,7 @@ namespace MachineSim { Dictionary answ = new Dictionary(); // genero a partire dall'elenco configurato da simulare... - answ = currSimPar.ToDictionary(i => i.Title, i => simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd)); + answ = currSimPar.ToDictionary(i => i.Title, i => simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd, 1)); return answ; } @@ -334,14 +332,19 @@ namespace MachineSim Order = i.Order, Title = i.Title, Type = i.Type, - ValueNum = simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd), + ValueNum = simNext(i.ValueNum, i.MinVal, i.MaxVal, i.SimMean, i.SimStd, 3), 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)}"; + // aggiorno con ultimo valore simulato... + var simItem = currSimTools.FirstOrDefault(x => x.Title == item.Title); + if (simItem != null) + { + simItem.ValueNum = item.ValueNum; + } } return answ; @@ -361,46 +364,67 @@ namespace MachineSim /// /// /// - /// /// + /// Modalità simulazione + /// 1 = std, RandomWalk + trend periodico con memoria + /// 2 = boolean + /// 3 = trend secondo valore mean (crescente se >0, decrescente se <0) + /// /// - public double simNext(double CurrVal, double MinVal, double MaxVal, double sMean, double sStd, bool isBoolean = false, double trueRatio = 0.5) + public double simNext(double CurrVal, double MinVal, double MaxVal, double sMean, double sStd, int simMode = 1, double trueRatio = 0.5) { + double innov = 0; + double trend = 0; // se è boolean --> simulazione 0/1 rapida con % ratio indicata - if (isBoolean) + switch (simMode) { - CurrVal = rand.Next(10000) <= trueRatio * 10000 ? 1 : 0; - } - // simulazione complessa con memoria - else - { - // innovazione stocastica di base - double innov = Normal.Sample(sMean, sStd); - // innovazione deterministica: - int resto = (DateTime.Now.Second % 10); - double trend = 0; - switch (resto) - { - case 0: - case 1: - case 2: - trend = sMean + 15 * sStd; - break; + case 2: + CurrVal = rand.Next(10000) <= trueRatio * 10000 ? 1 : 0; + break; + case 3: + innov = Normal.Sample(sMean, sStd); + trend = rand.NextDouble() * 2 * sMean; + double delta = innov + trend; + // il delta deve essere dello stesso segno della media... + if (delta * sMean < 0) + { + delta = delta * -1; + } + CurrVal += delta; + // verifico estremi... + CurrVal = CurrVal > MaxVal ? MinVal : CurrVal; + CurrVal = CurrVal < MinVal ? MaxVal : CurrVal; + break; + case 1: + default: + // innovazione stocastica di base + innov = Normal.Sample(sMean, sStd); + int multFact = rand.Next(1, 6); + // innovazione deterministica: + int resto = (DateTime.Now.Second % 10); + trend = 0; + switch (resto) + { + case 0: + case 1: + case 7: + trend = sMean + multFact * sStd; + break; - case 5: - case 6: - case 7: - trend = -(sMean + 15 * sStd); - break; + case 2: + case 5: + case 6: + trend = -(sMean + multFact * sStd); + break; - default: - break; - } - - CurrVal += innov + trend; - // verifico estremi... - CurrVal = CurrVal > MaxVal ? MaxVal : CurrVal; - CurrVal = CurrVal < MinVal ? MinVal : CurrVal; + default: + break; + } + CurrVal += innov + trend; + // verifico estremi... + CurrVal = CurrVal > MaxVal ? MaxVal : CurrVal; + CurrVal = CurrVal < MinVal ? MinVal : CurrVal; + break; } return CurrVal; } diff --git a/MP.MONO.SIM/conf/SimTools.json b/MP.MONO.SIM/conf/SimTools.json index 90f4a95..9845efb 100644 --- a/MP.MONO.SIM/conf/SimTools.json +++ b/MP.MONO.SIM/conf/SimTools.json @@ -3,22 +3,22 @@ "Order": 0, "Type": "TOOL", "Title": "Tool 01 life", - "Value": "1000", - "ValueNum": 1000, + "Value": "99", + "ValueNum": 99, "MinVal": 0, - "MaxVal": 2000, - "SimMean": -1, - "SimStd": 1, + "MaxVal": 100, + "SimMean": -1.5, + "SimStd": 0.5, "DisplFormat": "N1" }, { "Order": 1, "Type": "TOOL", "Title": "Tool 02 life", - "Value": "800", - "ValueNum": 800, + "Value": "85", + "ValueNum": 85, "MinVal": 0, - "MaxVal": 2000, + "MaxVal": 100, "SimMean": -1, "SimStd": 1, "DisplFormat": "N1" @@ -27,12 +27,12 @@ "Order": 2, "Type": "TOOL", "Title": "Tool 03 life", - "Value": "700", - "ValueNum": 700, + "Value": "70", + "ValueNum": 70, "MinVal": 0, - "MaxVal": 2000, - "SimMean": -1, - "SimStd": 1, + "MaxVal": 100, + "SimMean": -2.5, + "SimStd": 2, "DisplFormat": "N1" } ] \ No newline at end of file diff --git a/MP.MONO.UI/MP.MONO.UI.csproj b/MP.MONO.UI/MP.MONO.UI.csproj index 05e9e70..5fd7755 100644 --- a/MP.MONO.UI/MP.MONO.UI.csproj +++ b/MP.MONO.UI/MP.MONO.UI.csproj @@ -5,7 +5,7 @@ enable enable AnyCPU;x86;x64 - 1.2.2207.515 + 1.2.2207.517 diff --git a/MP.MONO.UI/Resources/ChangeLog.html b/MP.MONO.UI/Resources/ChangeLog.html index ebd9c0d..e44fe41 100644 --- a/MP.MONO.UI/Resources/ChangeLog.html +++ b/MP.MONO.UI/Resources/ChangeLog.html @@ -1,6 +1,6 @@ MAPO-MONO -

        Version: 1.2.2207.515

        +

        Version: 1.2.2207.517


        Release Note:
        • diff --git a/MP.MONO.UI/Resources/VersNum.txt b/MP.MONO.UI/Resources/VersNum.txt index 920c248..9145d08 100644 --- a/MP.MONO.UI/Resources/VersNum.txt +++ b/MP.MONO.UI/Resources/VersNum.txt @@ -1 +1 @@ -1.2.2207.515 +1.2.2207.517 diff --git a/MP.MONO.UI/Resources/manifest.xml b/MP.MONO.UI/Resources/manifest.xml index 242775e..03001db 100644 --- a/MP.MONO.UI/Resources/manifest.xml +++ b/MP.MONO.UI/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.2.2207.515 + 1.2.2207.517 http://nexus.steamware.net/repository/SWS/MP.MONO.UI/stable/LAST/MP.Mon.zip http://nexus.steamware.net/repository/SWS/MP.MONO.UI/stable/LAST/ChangeLog.html false