/// <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 TestSendWarning() { WarningHelper.SendWarning( 17, 2, new ThresholdAlarm(17) { AlarmDetails = new[] { new ThresholdAlarmDetail("x方向位移", 2) } }); WarningHelper.SendWarning( 17, 2, new ThresholdAlarm(17) { AlarmDetails = new[] { new ThresholdAlarmDetail("x方向位移", 2) } }); }