Exemplo n.º 1
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);
        }
Exemplo n.º 2
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()); // 直接写入数据库
            }
        }
Exemplo n.º 3
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());
                }
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 5
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()); // 直接写入数据库
            }
        }
Exemplo n.º 6
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);
                }
            }
        }
Exemplo n.º 7
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);
                }
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }