public List <ThresholdModel> GetByDeviceId(String deviceId) { return(_thresholdDao.GetByDeviceId(deviceId)); }
public void Run() { List <DeviceDataModel> dataNotInspected = _deviceDataDao.GetNotInspected(); Dictionary <String, List <DeviceDataModel> > sortedData = new Dictionary <string, List <DeviceDataModel> >(); List <String> deviceIds = new List <string>(); foreach (DeviceDataModel d in dataNotInspected) { if (!sortedData.ContainsKey(d.DeviceId)) { sortedData.Add(d.DeviceId, new List <DeviceDataModel>()); sortedData[d.DeviceId].Add(d); } else { sortedData[d.DeviceId].Add(d); } deviceIds.Add(d.DeviceId); } //TODO: Uniquify deviceIds = deviceIds.Distinct().ToList(); foreach (String did in deviceIds) { Dictionary <String, Tuple <String, int> > thresholdDic = _thresholdDao.GetByDeviceId(did); foreach (DeviceDataModel data in sortedData[did]) { String op = thresholdDic[data.IndexId].Item1; int threshold = thresholdDic[data.IndexId].Item2; Boolean abnormal = false; if (op == "equal") { if (Int32.Parse(data.IndexValue) != threshold) { abnormal = true; } } else if (op == "less") { if (Int32.Parse(data.IndexValue) <= threshold) { abnormal = true; } } else if (op == "greater") { if (Int32.Parse(data.IndexValue) >= threshold) { abnormal = true; } } if (abnormal == true) { AlarmInfoModel alarmInfo = new AlarmInfoModel(); alarmInfo.AlarmInfo = data.Id; alarmInfo.DeviceId = data.DeviceId; alarmInfo.IndexId = data.IndexId; alarmInfo.IndexName = data.IndexName; alarmInfo.IndexValue = data.IndexValue; alarmInfo.ThresholdValue = threshold.ToString(); alarmInfo.Timestamp = DateTime.Now; _alarmInfoDao.Create(alarmInfo); } } } }
public void Run() { List <DeviceDataModel> dataNotInspected = _deviceDataDao.GetNotInspected(); Dictionary <String, List <DeviceDataModel> > sortedData = new Dictionary <string, List <DeviceDataModel> >(); List <String> deviceIds = new List <string>(); foreach (DeviceDataModel d in dataNotInspected) { if (!sortedData.ContainsKey(d.DeviceId)) { sortedData.Add(d.DeviceId, new List <DeviceDataModel>()); sortedData[d.DeviceId].Add(d); } else { sortedData[d.DeviceId].Add(d); } deviceIds.Add(d.DeviceId); } deviceIds = deviceIds.Distinct().ToList(); Dictionary <String, String> operatorName = new Dictionary <string, string>(); operatorName.Add("equal", "="); operatorName.Add("greater", ">"); operatorName.Add("less", "<"); foreach (String did in deviceIds) { List <ThresholdModel> thresholdDic = _thresholdDao.GetByDeviceId(did); foreach (DeviceDataModel data in sortedData[did]) { var query = thresholdDic.AsQueryable() .Where(t => t.IndexId == data.IndexId) .ToList(); foreach (var th in query) { String op = th.Operator; double threshold = th.ThresholdValue; String svty = this._severityDao.GetById(int.Parse(th.Severity)).SeverityName; Boolean abnormal = false; if (op == "equal") { if (double.Parse(data.IndexValue) - threshold < 0.0001) { abnormal = true; } } else if (op == "less") { if (double.Parse(data.IndexValue) <= threshold) { abnormal = true; } } else if (op == "greater") { if (double.Parse(data.IndexValue) >= threshold) { abnormal = true; } } if (abnormal == true) { AlarmInfoModel alarmInfo = new AlarmInfoModel(); alarmInfo.AlarmInfo = th.Description; alarmInfo.DeviceId = data.DeviceId; alarmInfo.IndexId = data.IndexId; alarmInfo.IndexName = data.IndexName; alarmInfo.IndexValue = data.IndexValue; alarmInfo.ThresholdValue = operatorName[op] + threshold.ToString(); alarmInfo.Timestamp = DateTime.Now; alarmInfo.Severity = svty; _alarmInfoDao.Create(alarmInfo); } } } } }
public Dictionary <String, Tuple <String, int> > GetByDeviceId(String deviceId) { return(_thresholdDao.GetByDeviceId(deviceId)); }