Пример #1
0
        /// <summary>
        /// 生成时段产品
        /// </summary>
        /// <returns></returns>
        public PeriodRmsedNumeralStoarge GetProduct()
        {
            PeriodRmsedNumeralStoarge result = new PeriodRmsedNumeralStoarge();
            var keys = this.Keys;

            foreach (var key in keys)
            {
                var vals = this.Get(key);
                result[key] = BuildProduct(vals);
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 解析
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public static PeriodRmsedNumeralStoarge Parse(ObjectTableStorage table)
        {
            var storage = new PeriodRmsedNumeralStoarge();

            foreach (var row in table.BufferedValues)
            {
                var    paramName  = row["Name"].ToString();
                var    timePeriod = TimePeriod.Parse(row["TimePeriod"].ToString());
                double val        = Double.NaN;
                double rms        = Double.NaN;
                if (row.ContainsKey("Value"))
                {
                    val = double.Parse(row["Value"].ToString());
                }
                if (row.ContainsKey("Rms"))
                {
                    rms = double.Parse(row["Rms"].ToString());
                }
                storage.GetOrCreate(paramName)[timePeriod] = new RmsedNumeral(val, rms);
            }
            return(storage);
        }
Пример #3
0
        /// <summary>
        ///读取
        /// </summary>
        /// <param name="A"></param>
        /// <param name="B"></param>
        /// <returns></returns>
        public static PeriodRmsedNumeralStoarge Combine(PeriodRmsedNumeralStoarge A, PeriodRmsedNumeralStoarge B)
        {
            PeriodRmsedNumeralStoarge result = new PeriodRmsedNumeralStoarge();

            //先加到一起
            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] = (RmsedNumeral)kv.First.Tag;
                }
            }
            return(result);
        }