Esempio n. 1
0
        internal static void UpdateAlarmToday(ref Alarm_TodayModel alarmTodayModel, List <Alarm_TodayModel> alarmTodayModels, RealDataModel realDataModel,
                                              AnalogPointModel analogPointModel,
                                              Func <PointState, bool> isAlarmState)
        {
            if (alarmTodayModel == null)
            {
                NewAlarmAndSaveDatabase(out alarmTodayModel, alarmTodayModels, realDataModel, analogPointModel, isAlarmState);
            }
            else
            {
                alarmTodayModel.EndTime = realDataModel.RealDate;

                if (alarmTodayModel.IsRequireNew(realDataModel))
                {
                    // 有新的记录, 把老记录状态置1
                    alarmTodayModel.State = 1;
                }
                var realValue = realDataModel.RealValue.Value <float>();

                if (realValue > alarmTodayModel.AlarmValue &&
                    !alarmTodayModel.IsRequireNew(realDataModel))
                {
                    // 没有新记录情况下, 把报警值设置为最大值.
                    alarmTodayModel.AlarmValue = realValue;
                }

                if (isAlarmState((PointState)alarmTodayModel.AlarmState) &&
                    (alarmTodayModel.IsTimeToSave(realDataModel) || alarmTodayModel.IsRequireNew(realDataModel)))
                {
                    // 报警情况下, 写入数据库.
                    var newM = alarmTodayModel.DeepClone();
                    Alarm_TodayModel existM;
                    if ((existM = alarmTodayModels.FirstOrDefault(o => o.PointID == newM.PointID && o.StartTime == newM.StartTime && o.AlarmState == newM.AlarmState)) != null)
                    {
                        existM.State      = newM.State;
                        existM.AlarmValue = newM.AlarmValue;
                        existM.EndTime    = newM.EndTime;
                        existM.SpanTime   = (int)newM.EndTime.Subtract(newM.StartTime).TotalSeconds;
                    }
                    else
                    {
                        alarmTodayModels.Add(alarmTodayModel.DeepClone());
                    }
                }

                if (alarmTodayModel.IsRequireNew(realDataModel))
                {
                    // 有新记录.
                    NewAlarmAndSaveDatabase(out alarmTodayModel, alarmTodayModels, realDataModel, analogPointModel, isAlarmState);
                }
            }
        }
Esempio n. 2
0
        public static void UpdateDeviceFaultRun(ref DeviceFaultRunModel deviceFaultRunModel,
                                                List <DeviceFaultRunModel> deviceFaultRunModels,
                                                RealDataModel realDataModel,
                                                AnalogPointModel analogPointModel, Func <PointState, bool> isAlarmState)
        {
            if (deviceFaultRunModel == null)
            {
                NewAlarmAndSaveDatabase(out deviceFaultRunModel, deviceFaultRunModels, realDataModel, analogPointModel, isAlarmState);
            }
            else
            {
                deviceFaultRunModel.EndTime = realDataModel.RealDate;

                if (deviceFaultRunModel.IsRequireNew(realDataModel))
                {
                    // 有新的记录, 把老记录状态置1
                    deviceFaultRunModel.State = 1;
                }
                if (!deviceFaultRunModel.IsRequireNew(realDataModel))
                {
                    deviceFaultRunModel.PointState = realDataModel.RealState;
                }

                if (isAlarmState((PointState)deviceFaultRunModel.PointState) &&
                    (deviceFaultRunModel.IsTimeToSave(realDataModel) || deviceFaultRunModel.IsRequireNew(realDataModel)))
                {
                    // 报警情况下, 写入数据库.
                    var newM = deviceFaultRunModel.DeepClone();
                    DeviceFaultRunModel existM;
                    if ((existM = deviceFaultRunModels.FirstOrDefault(o => o.PointID == newM.PointID && o.StartTime == newM.StartTime && o.PointState == newM.PointState)) != null)
                    {
                        existM.State          = newM.State;
                        existM.PointState     = newM.PointState;
                        existM.PointStateName = Alarm_TodayModel.GetAlarmStateName((PointState)newM.PointState);
                        existM.EndTime        = newM.EndTime;
                        existM.SpanTime       = (int)newM.EndTime.Subtract(newM.StartTime).TotalSeconds;
                    }
                    else
                    {
                        deviceFaultRunModels.Add(deviceFaultRunModel.DeepClone());
                    }
                }

                if (deviceFaultRunModel.IsRequireNew(realDataModel))
                {
                    // 有新记录.
                    NewAlarmAndSaveDatabase(out deviceFaultRunModel, deviceFaultRunModels, realDataModel, analogPointModel, isAlarmState);
                }
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        private static DeviceFaultRunModel NewDeviceFaultRunModel(RealDataModel realDataModel, AnalogPointModel analogPointModel)
        {
            var model = new DeviceFaultRunModel();

            model.PointID        = analogPointModel.PointID;
            model.PointName      = analogPointModel.PointName;
            model.SubStationID   = analogPointModel.SubStationID;
            model.PortNO         = analogPointModel.PortNO;
            model.PointType      = (int)Models.PointType.Analog;
            model.Location       = analogPointModel.Location;
            model.PointState     = realDataModel.RealState;
            model.PointStateName = Alarm_TodayModel.GetAlarmStateName((PointState)realDataModel.RealState);
            model.FeedState      = realDataModel.FeedState;
            model.StartTime      = realDataModel.RealDate;
            model.EndTime        = realDataModel.RealDate;
            model.SpanTime       = 0;
            model.State          = 0;
            return(model);
        }
Esempio n. 5
0
 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);
     }
 }
Esempio n. 6
0
        private static Alarm_TodayModel NewAlarmTodayModel(RealDataModel realData, AnalogPointModel analogPointModel)
        {
            var model = new Alarm_TodayModel();

            model.PointID        = realData.PointID;
            model.SubStationID   = realData.SubStationID;
            model.PortNO         = realData.PortNO;
            model.PointName      = realData.PointName;
            model.Location       = analogPointModel.Location;
            model.StartTime      = realData.RealDate;
            model.EndTime        = realData.RealDate;
            model.AlarmValue     = realData.RealValue.Value <float>();
            model.AlarmState     = realData.RealState;
            model.AlarmStateName = GetAlarmStateName((PointState)realData.RealState);
            model.State          = 0;
            model.StartTime      = realData.RealDate;
            model.EndTime        = realData.RealDate;
            model.SpanTime       = 0;
            model.TableType      = 2;
            return(model);
        }
Esempio n. 7
0
        internal void Update(DateTime now, List <SensorRealDataInfo> sensorRealDataInfos)
        {
            var sensorRealData = sensorRealDataInfos.FirstOrDefault(p => p.EquipCodes.Exists(q => q == EquipCode));

            if (sensorRealData.IsAnalogOk)
            {
                _analogOffCount = 0;
                PointState valueState = PointState.OK;
                HandleAnalogAlarm(sensorRealData.Value, ref valueState);
                RealDataModel.Update(now, sensorRealData.Value.ToString("f2"), 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);
            }
            else
            {
                Update(now);
            }
        }
Esempio n. 8
0
        private static void NewAlarmAndSaveDatabase(out Alarm_TodayModel alarmTodayModel, List <Alarm_TodayModel> alarmTodayModels,
                                                    RealDataModel realDataModel, AnalogPointModel analogPointModel, Func <PointState, bool> isAlarmState)
        {
            // 需要新增加一条数据.
            alarmTodayModel = NewAlarmTodayModel(realDataModel, analogPointModel);

            var newStartTime       = alarmTodayModel.StartTime;
            var valueState         = alarmTodayModel.AlarmState;
            var existSameStartTime = alarmTodayModels.Find(o => newStartTime.Subtract(o.StartTime).TotalSeconds < 1 &&
                                                           o.AlarmState == valueState);

            if (existSameStartTime != null)
            {
                // 只有当开始时间和结束时间不一致的时候, 排除初始化出现主键冲突问题.
                alarmTodayModels.Remove(existSameStartTime);

                LogD.Warn($"分站{alarmTodayModel.PointID} 状态{existSameStartTime.AlarmState}出现一秒内多次状态报警状态改变, 会发生主键冲突.");
            }

            if (isAlarmState((PointState)alarmTodayModel.AlarmState))
            {
                alarmTodayModels.Add(alarmTodayModel.DeepClone()); // 直接写入数据库
            }
        }