WaterfallInfo에 따른 그래프 변경 함수 예제

2021. 10. 16. 18:13프로그래밍

반응형

참고용

public bool AcquisitionBDTDatas(ushort unType, Dictionary<ushort, List<DataManagerUnit1.BDTWaterfallInfo>> dic, bool cType)
        {
            try
            {
                if (_infoBDT[unType - 1] == null) return false;
                if (dic == null) return false;

                DataManagerUnit1.BDTWaterfallInfo info = new DataManagerUnit1.BDTWaterfallInfo()
                {
                    dt = _infoBDT[unType - 1].dt,
                    unLTWaterfallGram = _infoBDT[unType - 1].unLTWaterfallGram,
                    unSTWaterfallGram = _infoBDT[unType - 1].unSTWaterfallGram,
                    btrTime = _infoBDT[unType - 1].btrTime,
                    unBPStartFrequency = _infoBDT[unType - 1].unBPStartFrequency,
                    unBPEndFrequency = _infoBDT[unType - 1].unBPEndFrequency,
                                    };

                bool isChanged = false;
                if (dic.ContainsKey(unType))
                {
                    if (dic[unType].Count > 0)
                    {
                        DataManagerUnit1.BDTWaterfallInfo prevInfo = dic[unType][0];
                        if (!info.btrTime.Equals(prevInfo.btrTime))
                        {
                            if (dic[unType].Count(item => item.disp_dt && item.dt.ToString("HH:mm").Equals(info.dt.ToString("HH:mm"))) <= 0)
                            {
                                if (cType) _startCompareBDTDT[unType - 1] = null;
                                else _startMainBDTDT[unType - 1] = null;
                            }
                                                                                    isChanged = true;
                        }
                        if (!isChanged && (!info.unBPStartFrequency.Equals(prevInfo.unBPStartFrequency) || !info.unBPEndFrequency.Equals(prevInfo.unBPEndFrequency)))
                            isChanged = true;
                    }
                }
                else
                {
                    dic.Add(unType, new List<DataManagerUnit1.BDTWaterfallInfo>());
                }
                info.changed = isChanged;

                if (unType.Equals(5))                 {
                    if (cType)
                    {
                        if (_startCompareBDTDT[unType - 1] == null)                         {
                            info.disp_dt = true;
                            _startCompareBDTDT[unType - 1] = info.dt;
                        }
                        else
                        {
                            TimeSpan ts = info.dt - _startCompareBDTDT[unType - 1].Value;
                            double minGap = info.btrTime / 5.0;
                            if (ts.TotalMinutes >= minGap)
                            {
                                info.disp_dt = true;
                                _startCompareBDTDT[unType - 1] = info.dt;
                            }
                        }
                    }
                    else
                    {
                        if (_startMainBDTDT[unType - 1] == null)                         {
                            info.disp_dt = true;
                            _startMainBDTDT[unType - 1] = info.dt;
                        }
                        else
                        {
                            TimeSpan ts = info.dt - _startMainBDTDT[unType - 1].Value;
                            double minGap = info.btrTime / 5.0;
                            if (ts.TotalMinutes >= minGap)
                            {
                                info.disp_dt = true;
                                _startMainBDTDT[unType - 1] = info.dt;
                            }
                        }
                    }
                }
                else
                {
                    if (cType)
                    {
                        if (_startCompareBDTDT[unType - 1] == null)                         {
                            info.disp_dt = true;
                            _startCompareBDTDT[unType - 1] = info.dt;
                        }
                        else
                        {
                            TimeSpan ts = info.dt - _startCompareBDTDT[unType - 1].Value;
                            double minGap = info.btrTime / 5.0;
                            if (ts.TotalMinutes >= minGap)
                            {
                                info.disp_dt = true;
                                _startCompareBDTDT[unType - 1] = info.dt;
                            }
                        }
                    }
                    else
                    {
                        if (_startMainBDTDT[unType - 1] == null)                         {
                            info.disp_dt = true;
                            _startMainBDTDT[unType - 1] = info.dt;
                        }
                        else
                        {
                            TimeSpan ts = info.dt - _startMainBDTDT[unType - 1].Value;
                            double minGap = info.btrTime / 10.0;
                            if (ts.TotalMinutes >= minGap)
                            {
                                info.disp_dt = true;
                                _startMainBDTDT[unType - 1] = info.dt;
                            }
                        }
                    }
                }
                if (cType)
                {
                    if (unType.Equals(1) || unType.Equals(3))                     {
                        int index = unType.Equals(1) ? 0 : 1;
                        if (_startCompareCBDTDT[index] == null)
                        {
                            info.disp_cdt = true;
                            _startCompareCBDTDT[index] = info.dt;
                        }
                        else
                        {
                            TimeSpan ts = info.dt - _startCompareCBDTDT[index].Value;
                            double minGap = info.btrTime / 5.0;
                            if (ts.TotalMinutes >= minGap)
                            {
                                info.disp_cdt = true;
                                _startCompareCBDTDT[index] = info.dt;
                            }
                        }
                    }
                }
                else
                {
                    if (unType.Equals(1) || unType.Equals(3))                     {
                        int index = unType.Equals(1) ? 0 : 1;
                        if (_startMainCBDTDT[index] == null)
                        {
                            info.disp_cdt = true;
                            _startMainCBDTDT[index] = info.dt;
                        }
                        else
                        {
                            TimeSpan ts = info.dt - _startMainCBDTDT[index].Value;
                            double minGap = info.btrTime / 5.0;
                            if (ts.TotalMinutes >= minGap)
                            {
                                info.disp_cdt = true;
                                _startMainCBDTDT[index] = info.dt;
                            }
                        }
                    }
                }

                dic[unType].Insert(0, info);
                if (dic[unType].Count > 1)
                {
                    while ((dic[unType].First().dt - dic[unType].Last().dt).TotalHours >= 4)
                    {
                        if (dic[unType][dic[unType].Count - 1] != null) dic[unType][dic[unType].Count - 1].Dispose();
                        dic[unType].RemoveAt(dic[unType].Count - 1);
                    }
                                                        }
                return true;
            }
            catch (Exception ee)
            {
                TraceManager.AddLog(string.Format("{0}r\n{1}", ee.StackTrace, ee.Message));
                TraceManager.AddLog(string.Format("{0}", dic));                 TraceManager.AddLog(string.Format("{0}", unType));                 System.Diagnostics.Debug.WriteLine(string.Format("{0}r\n{1}", ee.StackTrace, ee.Message));
                return false;
            }
        }
반응형