示例#1
0
 private bool IsTimeToSave(RealDataModel realDataModel)
 {
     // 如果大于10秒, 那么写入数据, 延续报警.
     //if (realDataModel.RealTime.Subtract(_lastSaveTime).TotalSeconds >= 10)
     //_lastSaveTime = realDataModel.RealTime;
     return(true);
 }
示例#2
0
        private static AnalogAlarmModel NewAnalogAlarmModel(RealDataModel realData, AnalogPointModel analogPointModel)
        {
            var model = new AnalogAlarmModel();

            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.MaxValue     = realData.RealValue.Value <float>();
            model.MaxValueTime = realData.RealDate;
            model.MinValue     = realData.RealValue.Value <float>();
            model.MinValueTime = realData.RealDate;
            model.AvgValue     = realData.RealValue.Value <float>();
            model.SumValue    += realData.RealValue.Value <float>();
            model.AbnormalFeed = 0;
            model.SumCount++;
            model.State    = 0;
            model.SpanTime = 0;
            return(model);
        }
示例#3
0
        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()); // 直接写入数据库
            }
        }
示例#4
0
        internal static void UpdateAnalogAlarm(ref AnalogAlarmModel analogAlarmModel,
                                               List <AnalogAlarmModel> analogAlarmModels,
                                               RealDataModel realDataModel, AnalogPointModel analogPointModel,
                                               Func <PointState, bool> isAlarmState)
        {
            if (analogAlarmModel == null)
            {
                NewAlarmAndSaveDatabase(out analogAlarmModel, analogAlarmModels, realDataModel, analogPointModel, isAlarmState);
            }
            else
            {
                analogAlarmModel.EndTime = realDataModel.RealDate;

                if (analogAlarmModel.IsRequireNew(realDataModel))
                {
                    // 有新的记录, 把老记录状态置1
                    analogAlarmModel.State = 1;
                }
                if (isAlarmState((PointState)analogAlarmModel.AlarmState) &&
                    (analogAlarmModel.IsTimeToSave(realDataModel) || analogAlarmModel.IsRequireNew(realDataModel)))
                {
                    // 报警情况下, 当状态改变或者时间大于10秒时候, 写入数据库.
                    var newM = analogAlarmModel.DeepClone();
                    AnalogAlarmModel existM;
                    if ((existM = analogAlarmModels.FirstOrDefault(o => o.PointID == newM.PointID && o.StartTime == newM.StartTime && o.AlarmState == newM.AlarmState)) != null)
                    {
                        existM.State    = newM.State;
                        existM.EndTime  = newM.EndTime;
                        existM.SpanTime = (int)newM.EndTime.Subtract(newM.StartTime).TotalSeconds;
                    }
                    else
                    {
                        analogAlarmModels.Add(newM);
                    }
                }
                var realValue = realDataModel.RealValue.Value <float>();
                if (realValue < analogAlarmModel.MinValue)
                {
                    analogAlarmModel.MinValue     = realValue;
                    analogAlarmModel.MinValueTime = realDataModel.RealDate;
                }
                else if (realValue > analogAlarmModel.MaxValue)
                {
                    analogAlarmModel.MaxValue     = realValue;
                    analogAlarmModel.MaxValueTime = realDataModel.RealDate;
                }

                analogAlarmModel.SumValue += realValue;
                analogAlarmModel.SumCount++;

                if (analogAlarmModel.IsRequireNew(realDataModel))
                {
                    // 有新记录.
                    NewAlarmAndSaveDatabase(out analogAlarmModel, analogAlarmModels, realDataModel, analogPointModel, isAlarmState);
                }
            }
        }
示例#5
0
        public static void UpdateAnalogStatistic(ref AnalogStatisticModel analogStatisticModel,
                                                 List <AnalogStatisticModel> analogStatisticModels,
                                                 RealDataModel realDataModel, AnalogPointModel model)
        {
            if (analogStatisticModel == null)
            {
                analogStatisticModel = NewAnalogStatisticModel(realDataModel, model);
                analogStatisticModels.Add(analogStatisticModel);
            }
            else
            {
                if (!realDataModel.IaAnalogOK)
                {
                    return;
                }
                var realValue = realDataModel.RealValue.Value <float>();
                if (realValue < analogStatisticModel.MinValue)
                {
                    analogStatisticModel.MinValue     = realValue;
                    analogStatisticModel.MinValueTime = realDataModel.RealDate;
                }
                else if (realValue > analogStatisticModel.MaxValue)
                {
                    analogStatisticModel.MaxValue     = realValue;
                    analogStatisticModel.MaxValueTime = realDataModel.RealDate;
                    analogStatisticModel.State        = realDataModel.RealState;
                }

                analogStatisticModel.SumValue += realValue;
                analogStatisticModel.SumCount++;
                if (analogStatisticModel.IsTimeToSave(realDataModel))
                {
                    var newM = analogStatisticModel.DeepClone();
                    AnalogStatisticModel existM;
                    if ((existM = analogStatisticModels.FirstOrDefault(o => o.PointID == newM.PointID && o.StartTime == newM.StartTime)) != null)
                    {
                        existM.SumCount     = newM.SumCount;
                        existM.SumValue     = newM.SumValue;
                        existM.MaxValueTime = newM.MaxValueTime;
                        existM.MaxValue     = newM.MaxValue;
                        existM.MinValue     = newM.MinValue;
                        existM.MinValueTime = newM.MinValueTime;
                    }
                    else
                    {
                        analogStatisticModels.Add(analogStatisticModel.DeepClone());
                    }
                }

                if (analogStatisticModel.IsRequireNew(realDataModel))
                {
                    // 需要新增加一条数据.
                    analogStatisticModel = NewAnalogStatisticModel(realDataModel, model);
                    analogStatisticModels.Add(analogStatisticModel.DeepClone());
                }
            }
        }
示例#6
0
 public bool IsRequireNew(RealDataModel realDataModel)
 {
     // 如果状态变动, 那么写入一条数据.
     if (PointState != realDataModel.RealState)
     {
         return(true);
     }
     return(false);
 }
示例#7
0
        private void InitRealDataModel(RealDataModel realDataModel)
        {
            realDataModel.PointID      = $"{SubStationID:D3}000";
            realDataModel.PointName    = this.SubStationName;
            realDataModel.SubStationID = this.SubStationID;
            realDataModel.PointType    = (int)this.PointType;
            realDataModel.PortNO       = 0;

            realDataModel.Update(DateTime.Now, "初始化", PointState.Init, FeedState.Init);
        }
示例#8
0
        /// <summary>
        /// 新增一条AnalogAlarm记录, 并且把它保存到数据库中.
        /// </summary>
        private static void NewAlarmAndSaveDatabase(out AnalogAlarmModel analogAlarmModel, List <AnalogAlarmModel> analogAlarmModels,
                                                    RealDataModel realDataModel, AnalogPointModel analogPointModel, Func <PointState, bool> isAlarmState)
        {
            // 需要新增加一条数据.
            analogAlarmModel = NewAnalogAlarmModel(realDataModel, analogPointModel);

            if (isAlarmState((PointState)analogAlarmModel.AlarmState))
            {
                analogAlarmModels.Add(analogAlarmModel.DeepClone()); // 直接写入数据库
            }
        }
示例#9
0
        /// <summary>
        /// 将5个参数的实时模型初始化
        /// </summary>
        private void InitRealData(string code, ref RealDataModel realModel)
        {
            if (realModel == null)
            {
                realModel = new RealDataModel();
            }

            realModel.PointID   = code;
            realModel.RealValue = "初始化";
            realModel.RealState = 1;
            realModel.RealDate  = DateTime.Now;
        }
示例#10
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);
                }
            }
        }
示例#11
0
        public bool IsRequireNew(RealDataModel realDataModel)
        {
            //// 如果大于5分钟, 那么写入一条数据.
            //if (realDataModel.RealTime.Subtract(_lastSaveFiveTime).TotalMinutes >= 5)
            //{
            //    _lastSaveFiveTime = realDataModel.RealTime;
            //    return true;
            //}

            if (AlarmState != realDataModel.RealState)
            {
                return(true);
            }
            return(false);
        }
示例#12
0
        internal void InitPointModel()
        {
            RealDataModel.PointID      = PointID;
            RealDataModel.PointName    = PointName;
            RealDataModel.PortNO       = PortNO;
            RealDataModel.PointType    = (int)PointType.Analog;
            RealDataModel.SubStationID = SubStationID;
            RealDataModel.Update(DateTime.Now, "初始化", PointState.Init);

            _analogRunModel.PointID      = PointID;
            _analogRunModel.PointName    = PointName;
            _analogRunModel.SubStationID = SubStationID;
            _analogRunModel.PortNO       = PortNO;
            _analogRunModel.Location     = Location;
        }
示例#13
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);
        }
示例#14
0
 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());
     }
 }
示例#15
0
        internal void UpdateBitError(DateTime now)
        {
            var value = "通信误码";
            var state = PointState.BitError;

            _bitErrorCount++;
            if (_bitErrorCount >= 3)
            {
                // 连续大于三次才算通信误码.
                RealDataModel.Update(now, value, state);
            }
            else
            {
                // 只更新时间
                RealDataModel.Update(now);
            }
            SubStationRunModel.UpdateSubStationRun(ref _subStationRunModel, _subStationRunModels, RealDataModel, this);
        }
示例#16
0
        private static SubStationRunModel NewSubStationRunModel(RealDataModel realDataModel, SubStationModel subStationModel)
        {
            var model = new SubStationRunModel();

            model.SubStationID         = realDataModel.SubStationID;
            model.SubStationName       = subStationModel.SubStationName;
            model.Location             = subStationModel.Location;
            model.SubStationState      = realDataModel.RealState;
            model.SubStationStateValue = realDataModel.RealValue;
            model.StartTime            = realDataModel.RealDate;
            model.EndTime       = realDataModel.RealDate;
            model.SpanTime      = 0;
            model.State         = 0;
            model.Treatement    = "";
            model.TreatmentTime = DateTime.Now;
            model.Writer        = 0;
            return(model);
        }
示例#17
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);
     }
 }
示例#18
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);
        }
示例#19
0
        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);
        }
示例#20
0
        public bool IsRequireNew(RealDataModel realDataModel)
        {
            // 如果大于5分钟, 那么写入一条数据.
            //if (realDataModel.RealDate.Subtract(_lastSaveTime).TotalMinutes >= 5)
            //{
            //    return true;
            //}

            // 如果值或状态变动, 并且时间大于10秒, 那么写入一条数据.
            if (SubStationState != realDataModel.RealState ||
                SubStationStateValue != realDataModel.RealValue)
            {
                //if (realDataModel.RealTime.Subtract(_lastSaveTime).TotalSeconds >= 10)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#21
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);
        }
示例#22
0
        public static void UpdateSubStationRun(ref SubStationRunModel subStationRunModel,
                                               List <SubStationRunModel> subStationRunModels,
                                               RealDataModel realDataModel, SubStationModel subStationModel)
        {
            if (subStationRunModel == null)
            {
                subStationRunModel       = NewSubStationRunModel(realDataModel, subStationModel);
                subStationRunModel.State = 0;
                subStationRunModels.Add(subStationRunModel.DeepClone());
            }
            else
            {
                subStationRunModel.EndTime = realDataModel.RealDate;

                if (subStationRunModel.IsTimeToSave(realDataModel))
                {
                    var newM = subStationRunModel.DeepClone();
                    SubStationRunModel existM;
                    if ((existM = subStationRunModels.FirstOrDefault(o => o.Key == newM.Key)) != null)
                    {
                        existM.EndTime              = newM.EndTime;
                        existM.SubStationState      = newM.SubStationState;
                        existM.SubStationStateValue = newM.SubStationStateValue;
                        existM.SpanTime             = (int)newM.EndTime.Subtract(existM.StartTime).TotalSeconds;
                    }
                    else
                    {
                        subStationRunModels.Add(subStationRunModel.DeepClone());
                    }
                }

                if (subStationRunModel.IsRequireNew(realDataModel))
                {
                    // 需要新增加一条数据.
                    subStationRunModel       = NewSubStationRunModel(realDataModel, subStationModel);
                    subStationRunModel.State = 0;
                    subStationRunModels.Add(subStationRunModel.DeepClone());
                }
            }
        }
示例#23
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);
            }
        }
示例#24
0
        private static AnalogStatisticModel NewAnalogStatisticModel(RealDataModel realDataModel, AnalogPointModel analogPointModel)
        {
            var model = new AnalogStatisticModel();

            model.PointID         = realDataModel.PointID;
            model.PointName       = realDataModel.PointName;
            model.SubStationID    = realDataModel.SubStationID;
            model.PortNO          = realDataModel.PortNO;
            model.Location        = analogPointModel.Location;
            model.UnitName        = analogPointModel.UnitName;
            model.MonitoringValue = realDataModel.RealValue;
            model.State           = realDataModel.RealState;
            model.StartTime       = RoundDown(realDataModel.RealDate, TimeSpan.FromMinutes(5));
            model.EndTime         = RoundUp(realDataModel.RealDate, TimeSpan.FromMinutes(5));
            model.MinValue        = realDataModel.RealValue.Value <float>();
            model.MinValueTime    = realDataModel.RealDate;
            model.MaxValue        = realDataModel.RealValue.Value <float>();
            model.MaxValueTime    = realDataModel.RealDate;
            model.SumValue        = realDataModel.RealValue.Value <float>();
            model.SumCount        = 1;
            model.AvgValue        = realDataModel.RealValue;
            return(model);
        }
示例#25
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);
                }
            }
        }
示例#26
0
 public bool IsRequireNew(RealDataModel realDataModel)
 {
     // 如果大于5分钟, 那么写入一条数据.
     return(RoundDown(realDataModel.RealDate, TimeSpan.FromMinutes(5)) != StartTime);
 }
示例#27
0
 public void Update(RealDataModel model)
 {
     MonitoringValue = model.RealValue;
     MonitoringTime  = model.RealDate;
     ValueState      = model.RealState;
 }