private static void NewAlarmAndSaveDatabase(out DeviceFaultRunModel deviceFaultRunModel, List <DeviceFaultRunModel> deviceFaultRunModels, RealDataModel realDataModel, AnalogPointModel analogPointModel, Func <PointState, bool> isAlarmState) { deviceFaultRunModel = NewDeviceFaultRunModel(realDataModel, analogPointModel); var newStartTime = deviceFaultRunModel.StartTime; var valueState = deviceFaultRunModel.PointState; var existSameStartTime = deviceFaultRunModels.Find(o => newStartTime.Subtract(o.StartTime).TotalSeconds < 1 && o.PointState == valueState); if (existSameStartTime != null) { // 只有当开始时间和结束时间不一致的时候, 排除初始化出现主键冲突问题. deviceFaultRunModels.Remove(existSameStartTime); LogD.Warn($"分站{deviceFaultRunModel.PointID} 状态{existSameStartTime.PointState}出现一秒内多次状态报警状态改变, 会发生主键冲突."); } if (isAlarmState((PointState)deviceFaultRunModel.PointState)) { deviceFaultRunModels.Add(deviceFaultRunModel.DeepClone()); // 直接写入数据库 } }
private void UpdateAnalogOff(DateTime now) { LogD.Info($"传感器[{PointID}]状态为真正断线..."); var value = "模拟量断线"; var valueState = PointState.OFF; //是真正的断线 RealDataModel.Update(now, value, valueState); _analogRunModel.Update(RealDataModel); _analogRunModels.Add(_analogRunModel); AnalogStatisticModel.UpdateAnalogStatistic(ref _analogStatisticModel, _analogStatisticModels, RealDataModel, this); AnalogAlarmModel.UpdateAnalogAlarm(ref _analogAlarmModel, _analogAlarmModels, RealDataModel, this, IsAlarmState); Alarm_TodayModel.UpdateAlarmToday(ref _alarmTodayModel, _alarmTodayModels, RealDataModel, this, IsAlarmState); DeviceFaultRunModel.UpdateDeviceFaultRun(ref _deviceFaultRunModel, _deviceFaultRunModels, RealDataModel, this, IsAlarmState); }
internal void Update(DateTime now, SubStationData substationData) { RealDataModel.Update(now, "正常", PointState.OK); AnalogPointModels.ForEach(p => p.Update(now, substationData.SensorRealDataInfos)); try { lock (_lock) { FluxPointModels.ForEach(p => p.Update(now, AnalogPointModels.Select(p => p.RealDataModel).ToList())); } SubStationRunModel.UpdateSubStationRun(ref _subStationRunModel, _subStationRunModels, RealDataModel, this); } catch (Exception ex) { LogD.Error(ex.ToString()); } }
internal void Update(DateTime now) { _analogOffCount++; if (new[] { PointState.UnKnow, PointState.Init }.All(o => o != (PointState)RealDataModel.RealState) && _analogOffCount <= DasConfig.SensorTimeoutCount) { LogD.Info($"传感器[{PointID}]处于断线屏蔽次数之内:当前屏蔽次数:{_analogOffCount}"); RealDataModel.Update(now); //处于屏蔽次数之内 _analogRunModels.Add(_analogRunModel); AnalogStatisticModel.UpdateAnalogStatistic(ref _analogStatisticModel, _analogStatisticModels, RealDataModel, this); AnalogAlarmModel.UpdateAnalogAlarm(ref _analogAlarmModel, _analogAlarmModels, RealDataModel, this, IsAlarmState); Alarm_TodayModel.UpdateAlarmToday(ref _alarmTodayModel, _alarmTodayModels, RealDataModel, this, IsAlarmState); DeviceFaultRunModel.UpdateDeviceFaultRun(ref _deviceFaultRunModel, _deviceFaultRunModels, RealDataModel, this, IsAlarmState); } else { UpdateAnalogOff(now); } }
private float CheckReal(RealDataModel realDataModel, float?placeholder = null) { var state = (PointState)realDataModel.RealState; switch (state) { case PointState.OK: case PointState.UpperLimitEarlyWarning: case PointState.UpperLimitResume: case PointState.UpperLimitSwitchingOff: case PointState.UpperLimitWarning: case PointState.LowerLimitEarlyWarning: case PointState.LowerLimitResume: case PointState.LowerLimitSwitchingOff: case PointState.LowerLimitWarning: break; default: if (placeholder == null) { throw new Exception($"传感器 {realDataModel} {state} "); } else { return(placeholder.Value); } } #if DEBUG if (Math.Abs(_realTime.Subtract(realDataModel.RealDate).TotalSeconds) > 300) #else if (Math.Abs(_realTime.Subtract(realDataModel.RealDate).TotalSeconds) > 120) #endif { LogD.Info($"传感器 {realDataModel} 时间超过1分钟"); } if (!float.TryParse(realDataModel.RealValue, out float floatValue)) { } return(floatValue); }
/// <summary> /// 进行实际计算 /// </summary> private void CalcFluxRun(TimeSpan spanTime, out float tmpConcertReal, out float tmpTemptReal, out float tmpFluxReal, out float tmpPressure, out float tmpNegativePress, out float tmpAbsolutePress, out double flux, out double pureFlux, out double industFlux, out double industPureFlux) { //标矿混合流量实时 tmpFluxReal = CheckReal(_fluxReal); //标矿流量 tmpTemptReal = CheckReal(_temperatureReal, 20); tmpConcertReal = CheckReal(_concentrationReal); tmpPressure = CheckReal(_pressureReal); tmpNegativePress = tmpPressure; CalcPressure(tmpPressure, ref tmpNegativePress, out tmpAbsolutePress); /* * float tmpFluxValue = 0; * * * if (IsIndustrialFlux) * { * tmpFluxValue = (tmpFluxReal * tmpAbsolutePress * 293) / (101.325f * (273 + tmpTemptReal)); * } */ if (!IsIndustrialFlux) { //tmpFluxReal为标矿混合流量实时 // 标况纯流量实时值 PureFluxReal = (tmpFluxReal * tmpConcertReal / 100).ToString("F2"); // 标况混合流量累计 flux = tmpFluxReal * spanTime.TotalSeconds / 60; // 标况纯流量累计 pureFlux = flux * tmpConcertReal / 100; float tmpIndustFluxReal; if (tmpAbsolutePress == 0) { LogD.Info("绝压是0"); tmpIndustFluxReal = 0f; } else { // 工况混合量实时 tmpIndustFluxReal = (101.325f * (273 + tmpTemptReal) / (tmpAbsolutePress * 293)) * tmpFluxReal; } IndustFluxReal = tmpIndustFluxReal.ToString("F2"); IndustPureFluxReal = (tmpIndustFluxReal * tmpConcertReal / 100).ToString("F2"); // 工况混合流量累计 industFlux = tmpIndustFluxReal * spanTime.TotalSeconds / 60; // 工况纯流量累计 industPureFlux = industFlux * tmpConcertReal / 100; AbsolutePressReal = tmpAbsolutePress.ToString("F2"); } else { //工况纯流量实时值 IndustPureFluxReal = (tmpFluxReal * tmpConcertReal / 100).ToString("F2"); //工况混合流量 IndustFluxReal = tmpFluxReal.ToString("F2"); //工况混合流量累计 industFlux = tmpFluxReal * spanTime.TotalSeconds / 60; // 工况纯流量累计 industPureFlux = industFlux * tmpConcertReal / 100; if (tmpAbsolutePress == 0) { LogD.Info("绝压是0"); } var tmpFluxRealback = (tmpAbsolutePress * 293) / (101.325f * (273 + tmpTemptReal)) * tmpFluxReal; // 标况混合量实时 PureFluxReal = (tmpFluxRealback * tmpConcertReal / 100).ToString("F2"); //PureFluxReal = tmpFluxRealback .ToString("F2"); 标况混合流量实时值 // 标况混合流量累计 flux = tmpFluxRealback * spanTime.TotalSeconds / 60; // 标况纯流量累计 pureFlux = flux * tmpConcertReal / 100; AbsolutePressReal = tmpAbsolutePress.ToString("F2"); } }