public void ParseCriterionTest()
        {
            Repo.Initialize();
            RuntimeRepo.RtData = new RtData();
            var ctParser = new MockCriterionParser();

            var ct = @"(SpectrumIntegration(@Spectrum_Bearing_In_Y,0.8*@Speed,1.2*@Speed,#SPECTRUMINTERVAL*60)*1.5)<SpectrumIntegration(@Spectrum_Bearing_In_Y,1.8*@Speed,2.2*@Speed,#SPECTRUMINTERVAL*60)";

            //简单的开始测 没有实时数据,最后SpectrumIntegration应该返回-1
            ct = @"SpectrumIntegration(@Spectrum_Bearing_In_Y,0.8*@Speed,1.2*@Speed,#SPECTRUMINTERVAL*60)==-1";

            var vars        = CriterionParser.MatchConsts(ct);
            var consts      = Repo.Consts;
            var missingVars = new List <string>();

            foreach (var vr in vars)
            {
                if (consts.ContainsKey(vr))
                {
                    ct = ct.Replace(vr, consts[vr].ToString());
                }
                else
                {
                    missingVars.AddSingle(vr);
                }
            }
            Assert.IsTrue(!missingVars.Any());

            ct = ct.Replace("@Spectrum_Bearing_In_Y", "2");
            ct = ct.Replace("@Speed", "0");

            var a = ctParser.EvaluateExpression(ct);

            Assert.IsTrue(a);
        }
Ejemplo n.º 2
0
        public DataDictionary ParseCriterionRtDataStr(string ctRtDataStr)
        {
            var result  = new DataDictionary();
            var matches = CriterionParser.MatchCriterionRtDataDict(ctRtDataStr);

            foreach (var match in matches)
            {
                var keyvaluepair = match.Split(':');
                if (keyvaluepair.Length == 2)
                {
                    var key   = keyvaluepair[0];
                    var value = keyvaluepair[1];
                    if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(value))
                    {
                        double v;
                        if (double.TryParse(keyvaluepair[1], out v))
                        {
                            result.Add(keyvaluepair[0], v);
                        }
                    }
                }
            }
            return(result);
        }
 public DiagnoseController()
 {
     _ctParser = new CriterionParser();
     _icParser = new InferComboParser();
 }