private double SALongDurationByType(String tags, int alarmType, double alarmDuration) { double Result = 0.0f; String[] Tags = tags.Split(','); List <int?> Durations = new List <int?>(); int? Duration = 0; using (KPI_OverLimitRecordDal DataAccess = new KPI_OverLimitRecordDal()) { foreach (String TagID in Tags) { if (!IsCalcShift) { Duration = (from p in DataAccess.GetOverLimitRecords(BeginTime, EndTime, TagID, alarmType) where p.Duration >= alarmDuration select p.Duration).Sum(); Durations.Add(Duration); } if (IsCalcShift) { Duration = (from p in DataAccess.GetShiftOverLimitRecords(BeginTime, EndTime, TagID, alarmType) where p.Duration >= alarmDuration select p.Duration).Sum(); Durations.Add(Duration); } } } Result = Convert.ToDouble(Durations.Sum()); //超限时长单位:秒 Result = Result / 60; //超限时长转换为分钟 return(Result); }
/// <summary> /// 启动报警,向KPI_OverLimitRecord表中添加数据 /// </summary> /// <param name="faultConfiguration">报警配置信息</param> /// <param name="alarmType">报警类型 1=超高限,2=超高高限,3=超更高</param> /// <param name="alarmTime">开始报警时间</param> /// <param name="maxValue">超标极值</param> /// <param name="standardValue">标准值</param> private void StartAlarm(OverLimitConfigEntity faultConfiguration, int alarmType, DateTime alarmTime, double standardValue, double maxValue) { //Console.WriteLine(String.Format("测点{0}的报警类型是:{1}报警值是:{2}", faultConfiguration.TagDesc, alarmType, maxValue)); try { KPI_OverLimitRecordEntity entity = new KPI_OverLimitRecordEntity(); entity.AlarmID = Guid.NewGuid() + ""; entity.UnitID = faultConfiguration.UnitID; entity.TagID = faultConfiguration.TagName; entity.AlarmType = alarmType; entity.AlarmStartTime = alarmTime; entity.StandardValue = Convert.ToDecimal(standardValue); entity.Offset = Convert.ToDecimal(maxValue - standardValue); entity.Duration = 0; entity.AlarmValue = Convert.ToDecimal(maxValue); String Period = ""; String Shift = ""; GetShiftAndPeriod(faultConfiguration.UnitID, out Shift, out Period, alarmTime); entity.Shift = Shift; entity.Period = Period; using (KPI_OverLimitRecordDal DataAccess = new KPI_OverLimitRecordDal()) { if (DataAccess.ExistsOverLimitRecord(entity)) { DataAccess.UpdateAlarmMaxValue(entity); return; } DataAccess.AddOverLimitRecord(entity); } } catch (Exception ex) { m_Logger.InfoFormat("StartAlarm安全指标超限报警计算错误,错误信息是:{0},调用栈信息是:{1}", ex.Message, ex.StackTrace); m_Logger.Error(ex.Message, ex); } }
/// <summary> /// 解除报警,更新KPI_OverLimitRecord表中数据 /// </summary> /// <param name="faultConfiguration">报警配置信息</param> /// <param name="alarmType">报警类型 1=超高限,2=超高高限,3=超更高;</param> /// <param name="alarmTime">解除报警时间</param> private void StopAlarm(OverLimitConfigEntity faultConfiguration, int alarmType, DateTime alarmTime) { try { KPI_OverLimitRecordEntity entity = new KPI_OverLimitRecordEntity(); entity.TagID = faultConfiguration.TagName; entity.AlarmStartTime = alarmTime; entity.AlarmType = alarmType; using (KPI_OverLimitRecordDal DataAccess = new KPI_OverLimitRecordDal()) { DataAccess.UpdateOverLimitRecord(entity); } } catch (Exception ex) { LogUtil.LogMessage(string.Format("安全指标超限报警计算错误,错误信息是:{0},调用栈信息是:{1}", ex.Message, ex.StackTrace)); } }
/// <summary> /// 解除报警,更新KPI_OverLimitRecord表中数据 /// </summary> /// <param name="faultConfiguration">报警配置信息</param> /// <param name="alarmType">报警类型 1=超高限,2=超高高限,3=超更高;</param> /// <param name="alarmTime">解除报警时间</param> private void StopAlarm(OverLimitConfigEntity faultConfiguration, int alarmType, DateTime alarmTime) { try { KPI_OverLimitRecordEntity entity = new KPI_OverLimitRecordEntity(); entity.TagID = faultConfiguration.TagName; entity.AlarmEndTime = alarmTime; entity.AlarmType = alarmType; using (KPI_OverLimitRecordDal DataAccess = new KPI_OverLimitRecordDal()) { DataAccess.UpdateOverLimitRecord(entity); } } catch (Exception ex) { m_Logger.InfoFormat("StopAlarm安全指标超限报警计算错误,错误信息是:{0},调用栈信息是:{1}", ex.Message, ex.StackTrace); m_Logger.Error(ex.Message, ex); } }
private double SALongCount(string tags, double alarmDuration) { //double Result = 0.0f; String[] Tags = tags.Split(','); List <int> Counts = new List <int>(); int Count; /*List<int?> Durations = new List<int?>(); * int? Duration = 0; * using (KPI_OverLimitRecordDal DataAccess = new KPI_OverLimitRecordDal()) { * foreach (String TagID in Tags) { * Duration = (from p in DataAccess.GetOverLimitRecords(BeginTime, EndTime, TagID) * where p.Duration >= alarmDuration * select p.Duration).Sum(); * Durations.Add(Duration); * } * } * foreach (int? duration in Durations) { * if (duration.HasValue) Result += duration.Value / alarmDuration; * }*/ List <KPI_OverLimitRecordEntity> OverRecords; using (KPI_OverLimitRecordDal DataAccess = new KPI_OverLimitRecordDal()) { foreach (String TagID in Tags) { if (!IsCalcShift) { OverRecords = DataAccess.GetOverLimitRecords(BeginTime, EndTime, TagID); Count = (from p in OverRecords where p.Duration >= alarmDuration select p.Duration).Count(); Counts.Add(Count); } if (IsCalcShift) { OverRecords = DataAccess.GetShiftOverLimitRecords(BeginTime, EndTime, TagID); Count = (from p in OverRecords where p.Duration >= alarmDuration select p.Duration).Count(); Counts.Add(Count); } } } return(Counts.Sum()); }
private object GetAlarmCount(String tags, double alarmDuration) { String[] Tags = tags.Split(','); List <int?> Durations = new List <int?>(); double Duration = 0.0f;//指标超限时长(单位:秒) using (KPI_OverLimitRecordDal DataAccess = new KPI_OverLimitRecordDal()) { foreach (String TagID in Tags) { Durations.Add(DataAccess.GetOverLimitRecords(BeginTime, EndTime, TagID).Sum(p => p.Duration)); } } if (Durations.Count > 0) { Duration = Durations.Max().Value; } return(Math.Ceiling(Duration / alarmDuration)); }
/// <summary> /// 交接时关闭上一班报警 /// </summary> /// <param name="faultConfiguration"></param> private void StopLastShiftAlarm(OverLimitConfigEntity faultConfiguration) { KPI_UnitEntity Entity = KPI_UnitDal.GetEntity(faultConfiguration.UnitID); if (Entity == null) { return; } String strWorkID = Entity.WorkID; String strStartTime = ""; String strEndTime = ""; String Shift = ""; String Period = ""; String strCurrentMinute = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00"); KPI_WorkDal.GetShiftAndPeriod(strWorkID, strCurrentMinute, ref Shift, ref Period, ref strStartTime, ref strEndTime); DateTime ShiftStartTime = Convert.ToDateTime(strStartTime); DateTime CurrentTime = DateTime.Now; TimeSpan Span = CurrentTime - ShiftStartTime; double TotalMinutes = Span.TotalMinutes; if (TotalMinutes <= 10) { try { using (KPI_OverLimitRecordDal DataAccess = new KPI_OverLimitRecordDal()) { KPI_OverLimitRecordEntity entity = new KPI_OverLimitRecordEntity(); for (int i = 1; i < 4; i++) { entity.TagID = faultConfiguration.TagName; entity.AlarmStartTime = ShiftStartTime; entity.AlarmType = i; DataAccess.UpdateOverLimitRecord(entity); } } } catch (Exception ex) { m_Logger.InfoFormat("StopLastShiftAlarm安全指标超限报警计算错误,错误信息是:{0},调用栈信息是:{1}", ex.Message, ex.StackTrace); m_Logger.Error(ex); } } }
private double SACountByType(string tags, int alarmType) { double Result = 0.0f; String[] Tags = tags.Split(','); List <int> Durations = new List <int>(); using (KPI_OverLimitRecordDal DataAccess = new KPI_OverLimitRecordDal()) { foreach (String TagID in Tags) { if (!IsCalcShift) { Durations.Add(DataAccess.GetOverLimitRecords(BeginTime, EndTime, TagID, alarmType).Count()); } if (IsCalcShift) { Durations.Add(DataAccess.GetShiftOverLimitRecords(BeginTime, EndTime, TagID, alarmType).Count()); } } } Result = Durations.Sum(); return(Result); }
private double SADurationByType(String tags, int alarmType) { double Result = 0.0f; String[] Tags = tags.Split(','); List <int?> Durations = new List <int?>(); using (KPI_OverLimitRecordDal DataAccess = new KPI_OverLimitRecordDal()) { foreach (String TagID in Tags) { if (!IsCalcShift) { Durations.Add(DataAccess.GetOverLimitRecords(BeginTime, EndTime, TagID, alarmType).Sum(p => p.Duration)); } if (IsCalcShift) { Durations.Add(DataAccess.GetShiftOverLimitRecords(BeginTime, EndTime, TagID, alarmType).Sum(p => p.Duration)); } } } Result = Convert.ToDouble(Durations.Sum()); //超限时长单位:秒 Result = Math.Ceiling(Result / 60); //超限时长转换为分钟 return(Result); }