Example #1
0
        public void TestGradingSetCleanUpTimeOutPlan()
        {
            Assert.AreEqual(0, StructGradingPlanSet.Plans.Count);

            GradingSet.Add(
                new Sensor {
                SensorID = 807, FactorType = 20, StructId = 71
            },
                new SensorAnalyzeResult {
                SensorId = 807, Score = 80, ThresholdAlarm = null
            });

            Assert.AreEqual(1, StructGradingPlanSet.Plans.Count);

            Thread.Sleep(80000);

            Console.WriteLine(StructGradingPlanSet.Plans.Count);
            Assert.AreEqual(0, StructGradingPlanSet.Plans.Count);

            // another
            GradingSet.Add(
                new Sensor {
                SensorID = 807, FactorType = 20, StructId = 71
            },
                new SensorAnalyzeResult {
                SensorId = 807, Score = 80, ThresholdAlarm = null
            });

            Assert.AreEqual(1, StructGradingPlanSet.Plans.Count);

            Thread.Sleep(80000);

            Console.WriteLine(StructGradingPlanSet.Plans.Count);
            Assert.AreEqual(0, StructGradingPlanSet.Plans.Count);
        }
Example #2
0
        /// <summary>
        /// 分析采集数据
        /// </summary>
        /// <param name="rslt"></param>
        public void ProcessResult(List <SensorAcqResult> source)
        {
            Log.Info("DataAnalyzer has recieved DACTaskResult, starts to analyze..");
            int count = 0;

            foreach (SensorAcqResult rslt in source)
            {
                if (rslt.IsOK)
                {
                    var sens       = rslt.Sensor.SensorID;
                    var thresholds = this.GetSensorThreshold(new[] { sens }); // 所有传感器阈值
                    if (rslt.IsOK && rslt.Data != null && rslt.ErrorCode == 0)
                    {
                        var sensor = rslt.Sensor;

                        var analyzingData = this.GetAnalyzingData(rslt);

                        if (analyzingData.Data == null || analyzingData.Data.Any(d => d == null))
                        {
                            Log.WarnFormat(
                                "data:[{0}] not meet the Analyze's condition",
                                rslt.Data.ThemeValues == null ? null : string.Join(",", rslt.Data.ThemeValues));
                            return;
                        }

                        var sensorThreshold = thresholds.Where(s => s.SensorId == sensor.SensorID).ToList();
                        // 当前传感器阈值

                        var sensorAnalyzeResult = this.AnalyzeSensorData(analyzingData, sensorThreshold);

                        // 添加到整体评分集合
                        GradingSet.Add(sensor, sensorAnalyzeResult);
                        // 发送阈值告警
                        if (sensorAnalyzeResult.ThresholdAlarm != null &&
                            sensorAnalyzeResult.ThresholdAlarm.AlarmDetails.Any())
                        {
                            try
                            {
                                Log.InfoFormat("Sensor:{0} generate a OVER THRESHOLD alarm, sending..", sensor.SensorID);
                                WarningHelper.SendWarning(
                                    (int)sensor.SensorID,
                                    (int)sensor.StructId,
                                    sensorAnalyzeResult.ThresholdAlarm);
                                Log.InfoFormat("Sensor:{0} alarm send success", sensor.SensorID);
                            }
                            catch (Exception e)
                            {
                                Log.ErrorFormat("Sensor:{0} alarm send error", e, sensor.SensorID);
                            }
                        }

                        count++;
                    }
                }
            }
            Log.InfoFormat("Data Analyzed, success:{0}", count);
        }
        public void TestThemeEnforceGrading()
        {
            Assert.AreEqual(0, StructGradingPlanSet.Plans.Count);

            GradingSet.Add(
                new Sensor {
                SensorID = 17, FactorType = 10, StructId = 2
            },
                new SensorAnalyzeResult {
                SensorId = 17, Score = 80, ThresholdAlarm = null
            });

            Assert.AreEqual(1, StructGradingPlanSet.Plans.Count);

            StructGradingPlanSet.Plans[0].ThemeScores[0].EnforceGrading();
            Assert.IsTrue(StructGradingPlanSet.Plans[0].ThemeScores[0].Completed);
            Assert.AreEqual(100, StructGradingPlanSet.Plans[0].ThemeScores[0].Score);
        }
Example #4
0
        public void TestGradingSet()
        {
            Assert.AreEqual(0, StructGradingPlanSet.Plans.Count);

            GradingSet.Add(
                new Sensor {
                SensorID = 17, FactorType = 10, StructId = 2
            },
                new SensorAnalyzeResult {
                SensorId = 17, Score = 80, ThresholdAlarm = null
            });

            Assert.AreEqual(1, StructGradingPlanSet.Plans.Count);

            GradingSet.Add(
                new Sensor {
                SensorID = 18, FactorType = 10, StructId = 2
            },
                new SensorAnalyzeResult {
                SensorId = 18, Score = 80, ThresholdAlarm = null
            });

            GradingSet.Add(
                new Sensor {
                SensorID = 19, FactorType = 10, StructId = 2
            },
                new SensorAnalyzeResult {
                SensorId = 19, Score = 80, ThresholdAlarm = null
            });

            GradingSet.Add(
                new Sensor {
                SensorID = 20, FactorType = 10, StructId = 2
            },
                new SensorAnalyzeResult {
                SensorId = 20, Score = 80, ThresholdAlarm = null
            });

            GradingSet.Add(
                new Sensor {
                SensorID = 21, FactorType = 10, StructId = 2
            },
                new SensorAnalyzeResult {
                SensorId = 21, Score = 80, ThresholdAlarm = null
            });

            Assert.AreEqual(1, StructGradingPlanSet.Plans.Count);

            GradingSet.Add(
                new Sensor {
                SensorID = 22, FactorType = 10, StructId = 2
            },
                new SensorAnalyzeResult {
                SensorId = 22, Score = 80, ThresholdAlarm = null
            });

            GradingSet.Add(
                new Sensor {
                SensorID = 23, FactorType = 17, StructId = 2
            },
                new SensorAnalyzeResult {
                SensorId = 23, Score = 80, ThresholdAlarm = null
            });

            GradingSet.Add(
                new Sensor {
                SensorID = 24, FactorType = 17, StructId = 2
            },
                new SensorAnalyzeResult {
                SensorId = 24, Score = 80, ThresholdAlarm = null
            });

            GradingSet.Add(
                new Sensor {
                SensorID = 26, FactorType = 9, StructId = 2
            },
                new SensorAnalyzeResult {
                SensorId = 26, Score = 80, ThresholdAlarm = null
            });

            GradingSet.Add(
                new Sensor {
                SensorID = 27, FactorType = 9, StructId = 2
            },
                new SensorAnalyzeResult {
                SensorId = 27, Score = 80, ThresholdAlarm = null
            });

            Assert.AreEqual(0, StructGradingPlanSet.Plans.Count);
        }