public static void Add(Sensor sensor, SensorAnalyzeResult sensorAnalyzeResult) { var item = new GradingItem { SensorId = (int)sensor.SensorID, StructId = (int)sensor.StructId, FactorId = (int)sensor.FactorType, Score = sensorAnalyzeResult.Score }; StructGradingPlanSet.UpdatePlan(item); }
/// <summary> /// 数据分析(默认满分) /// </summary> /// <param name="data"></param> /// <param name="thresholds"></param> public SensorAnalyzeResult AnalyzeSensorData(AnalyzingData data, IList <SensorThreshold> thresholds) { var rslt = new SensorAnalyzeResult(); rslt.SensorId = (int)data.SensorId; rslt.Score = 100; rslt.ThresholdAlarm = null; if (!thresholds.Any() || data.Data == null) { // 未配置阈值,默认以无告警处理 return(rslt); } var sensor = DbAccessor.GetSensorInfo((int)data.SensorId).AsEnumerable().FirstOrDefault(); var sensorData = data.Data; var alarm = new ThresholdAlarm((int)data.SensorId); // 遍历各监测项 for (int i = 0; i < sensorData.Count(); i++) { int itemId = i + 1; var threshold = thresholds.FirstOrDefault(t => t.ItemId == itemId); if (threshold != null) { var itemName = this.GetItemName(sensor, itemId); var totalLvl = threshold.LevelNumber; // 查询落在哪个阈值区域 foreach (var sensorThreshold in threshold.Thresholds) { if (sensorData[i] >= sensorThreshold.Down && sensorData[i] <= sensorThreshold.Up) { rslt.Score -= (int)((1 - (double)sensorThreshold.Level / totalLvl) / sensorData.Count * 100); var alarmDetail = new ThresholdAlarmDetail(itemName, sensorThreshold.Level); alarm.AlarmDetails.Add(alarmDetail); break; } } } } if (alarm.AlarmDetails.Count > 0) { rslt.ThresholdAlarm = alarm; } return(rslt); }