/// <summary>
        ///读取
        /// </summary>
        /// <param name="A"></param>
        /// <param name="B"></param>
        /// <returns></returns>
        public static PeriodNumerialStorage Combine(PeriodNumerialStorage A, PeriodNumerialStorage B)
        {
            PeriodNumerialStorage result = new PeriodNumerialStorage();

            //先加到一起
            foreach (var kv in A.KeyValues)
            {
                var dic = result.GetOrCreate(kv.Key);
                foreach (var item in kv.Value.KeyValues)
                {
                    dic[item.Key] = item.Value;
                }
            }

            foreach (var kv in B.KeyValues)
            {
                var dic = result.GetOrCreate(kv.Key);
                foreach (var item in kv.Value.KeyValues)
                {
                    dic[item.Key] = item.Value;
                }
            }

            //合并同类项
            Dictionary <string, List <Pair <TimePeriod> > > toCombies = new Dictionary <string, List <Pair <TimePeriod> > >();

            foreach (var kv in result.KeyValues)
            {
                //查找交叉,且数值相等的时段
                var crossed = new List <Pair <TimePeriod> >();
                toCombies[kv.Key] = crossed;
                List <TimePeriod> notLoopAgain = new List <TimePeriod>();
                foreach (var item1 in kv.Value.KeyValues)
                {
                    notLoopAgain.Add(item1.Key);
                    item1.Key.Tag = item1.Value;//保存数值
                    foreach (var item2 in kv.Value.KeyValues)
                    {
                        if (item1.Key == item2.Key || notLoopAgain.Contains(item2.Key) || item1.Value != item2.Value)
                        {
                            continue;
                        }
                        if (item2.Key.IsIntersect(item2.Key))
                        {
                            crossed.Add(new Pair <TimePeriod>(item1.Key, item2.Key));
                        }
                    }
                }
            }
            //移除
            foreach (var item in toCombies)
            {
                foreach (var kv in item.Value)
                {
                    result.Remove(item.Key, kv.First);
                    result.Remove(item.Key, kv.Second);
                }
            }

            //合并,再添加
            KeyValuePair <TimePeriod, double> kvs = new KeyValuePair <TimePeriod, double>();

            foreach (var item in toCombies)
            {
                var data = result.GetOrCreate(item.Key);
                foreach (var kv in item.Value)
                {
                    var newP = kv.First.Exppand(kv.Second);
                    data[newP] = (double)kv.First.Tag;
                }
            }
            return(result);
        }
Пример #2
0
 /// <summary>
 /// 默认构造函数
 /// </summary>
 private GlobalGlonassSlotFreqService()
 {
     this.Name = "全局自动GLONASS频率服务";
     SatTimePeriodValueStoarge = PeriodNumerialStorage.Read(Setting.GlonassSlotFreqFile);
 }