示例#1
0
        /// <summary>
        /// 将指定的曲线数据转换为另一种点数的曲线数据。
        /// </summary>
        /// <param name="sourceValues">源数据数组。</param>
        /// <param name="convertedInto">转换后的曲线点数。</param>
        /// <param name="mergeOption">当转换后的点数小于目前曲线点数时,如何合并目前的数据。</param>
        /// <param name="splitOption">当转换后的点数大于目前曲线点数时,如何拆分目前的数据。</param>
        /// <returns>转换后的曲线数据,该数组的长度等于 convertedInto 参数指定的点数。</returns>
        public static decimal?[] ConvertTo(decimal?[] sourceValues, CurvePointOptions convertedInto, CurveMergeOptions mergeOption, CurveSplitOptions splitOption)
        {
            string strPoint = "";

            foreach (int intEnumValue in Enum.GetValues(typeof(CurvePointOptions)))
            {
                CurvePointOptions _SourceCurvePoint = (CurvePointOptions)intEnumValue;

                if (sourceValues.Length == _SourceCurvePoint.GetPointCount())
                {
                    if (_SourceCurvePoint > convertedInto)
                    {
                        if ((_SourceCurvePoint.GetPointCount() % convertedInto.GetPointCount()) == 0)
                        {
                            decimal?[] decValue         = new decimal?[convertedInto.GetPointCount()];
                            int        intCurveMergeNum = _SourceCurvePoint.GetPointCount() / convertedInto.GetPointCount();
                            for (int intIndex = 0; intIndex < decValue.Length; intIndex++)
                            {
                                ICurveMerge _CurveMerge = null;
                                switch (mergeOption)
                                {
                                case CurveMergeOptions.Addition:
                                    _CurveMerge = new CurveMergeAddition();
                                    break;

                                case CurveMergeOptions.Average:
                                    _CurveMerge = new CurveMergeAverage();
                                    break;

                                case CurveMergeOptions.First:
                                    _CurveMerge = new CurveMergeFirst();
                                    break;

                                case CurveMergeOptions.Maximum:
                                    _CurveMerge = new CurveMergeMaximum();
                                    break;

                                case CurveMergeOptions.Minimum:
                                    _CurveMerge = new CurveMergeMinimum();
                                    break;

                                default:
                                    throw new Exception("无 " + mergeOption.ToString() + " 数据转换方法。");
                                }

                                for (int intCurveMergeIndex = 0; intCurveMergeIndex < intCurveMergeNum; intCurveMergeIndex++)
                                {
                                    _CurveMerge.Value.Add(sourceValues[intIndex * intCurveMergeNum + intCurveMergeIndex]);
                                }
                                decValue[intIndex] = _CurveMerge.GetValue();
                            }
                            return(decValue);
                        }
                        else if (_SourceCurvePoint == CurvePointOptions.Point144 && convertedInto == CurvePointOptions.Point96)
                        {
                            //将144点转为96点。先将144点转为288点,然后将288点转为96点。
                            decimal?[] decValue288 = ConvertTo(sourceValues, CurvePointOptions.Point288, mergeOption, splitOption);
                            return(ConvertTo(decValue288, CurvePointOptions.Point96, mergeOption, splitOption));
                        }
                        else
                        {
                            throw new Exception("尚不支持将 " + _SourceCurvePoint.GetPointCount() + " 点数据转为 " + convertedInto.GetPointCount() + " 点数据。");
                        }
                    }
                    else if (_SourceCurvePoint < convertedInto)
                    {
                        if ((convertedInto.GetPointCount() % _SourceCurvePoint.GetPointCount()) == 0)
                        {
                            decimal?[] decValue         = new decimal?[convertedInto.GetPointCount()];
                            int        intCurveSplitNum = convertedInto.GetPointCount() / _SourceCurvePoint.GetPointCount();
                            for (int intIndex = 0; intIndex < sourceValues.Length; intIndex++)
                            {
                                if (sourceValues[intIndex] != null)
                                {
                                    for (int intCurveSplitIndex = 0; intCurveSplitIndex < intCurveSplitNum; intCurveSplitIndex++)
                                    {
                                        switch (splitOption)
                                        {
                                        case CurveSplitOptions.Division:
                                            decValue[intIndex * intCurveSplitNum + intCurveSplitIndex] = sourceValues[intIndex] / intCurveSplitNum;
                                            break;

                                        case CurveSplitOptions.Copy:
                                            decValue[intIndex * intCurveSplitNum + intCurveSplitIndex] = sourceValues[intIndex];
                                            break;

                                        default:
                                            throw new Exception("无 " + splitOption.ToString() + " 数据转换方法。");
                                        }
                                    }
                                }
                            }
                            return(decValue);
                        }
                        else if (_SourceCurvePoint == CurvePointOptions.Point96 && convertedInto == CurvePointOptions.Point144)
                        {
                            //将96点转为144点。先将96点转为288点,然后将288点转为144点。
                            decimal?[] decValue288 = ConvertTo(sourceValues, CurvePointOptions.Point288, mergeOption, splitOption);
                            return(ConvertTo(decValue288, CurvePointOptions.Point144, mergeOption, splitOption));
                        }
                        else
                        {
                            throw new Exception("尚不支持将 " + _SourceCurvePoint.GetPointCount() + " 点数据转为 " + convertedInto.GetPointCount() + " 点数据。");
                        }
                    }
                    else
                    {
                        return(sourceValues);
                    }
                }

                strPoint += "、" + _SourceCurvePoint.GetPointCount();
            }

            throw new Exception("源数据数组的长度必须等于 " + strPoint.Substring(1) + "。");
        }
示例#2
0
        /// <summary>
        /// 将指定的曲线段数据转换为另一种点数的曲线段数据。
        /// </summary>
        /// <param name="sourceCurvePoint">源数据的曲线点数,该参数为 0:00:00 至 23:59:59 完整的曲线数据点数。</param>
        /// <param name="sourceStartTimeNum">源数据第一个点的数值对应的时间。</param>
        /// <param name="sourceValues">源数据数组。</param>
        /// <param name="convertedInto">转换后的曲线点数。</param>
        /// <param name="mergeOption">当转换后的点数小于目前曲线点数时,如何合并目前的数据。</param>
        /// <param name="splitOption">当转换后的点数大于目前曲线点数时,如何拆分目前的数据。</param>
        /// <returns>转换后的曲线数据,该数组的长度等于 convertedInto 参数指定的点数。</returns>
        public static decimal?[] ConvertTo(CurvePointOptions sourceCurvePoint, int sourceStartTimeNum, decimal?[] sourceValues, CurvePointOptions convertedInto, CurveMergeOptions mergeOption, CurveSplitOptions splitOption)
        {
            if (sourceCurvePoint == convertedInto)
            {
                return(sourceValues);
            }
            else
            {
                sourceStartTimeNum = sourceCurvePoint.FormatTimeNum(sourceStartTimeNum);

                if (sourceValues == null && sourceValues.Length == 0)
                {
                    throw new Exception("传入的 sourceValues 数据数组长度需要大于 0。");
                }

                int intEndIndex = sourceCurvePoint.GetPointIndex(sourceStartTimeNum) + sourceValues.Length - 1;
                if (intEndIndex >= sourceCurvePoint.GetPointCount())
                {
                    throw new Exception("传入的 sourceValues 数据数组长度超出了一天的范围。");
                }

                int sourceEndTimeNum    = sourceCurvePoint.GetTimeNum(intEndIndex);
                int intIntoStartTimeNum = convertedInto.FormatTimeNum(sourceStartTimeNum);    //转换后的开始时间

                if (sourceCurvePoint > convertedInto)
                {
                    if ((sourceCurvePoint.GetPointCount() % convertedInto.GetPointCount()) == 0)
                    {
                        int        intIntoEndTimeNum      = convertedInto.FormatTimeNum(sourceEndTimeNum);                              //转换后的结束时间
                        int        intIntoPointCount      = convertedInto.GetTimeSpanPoint(intIntoStartTimeNum, intIntoEndTimeNum) + 1; //转换后的数据点数
                        decimal?[] decValue               = new decimal?[intIntoPointCount];
                        int        intSourceIntoDiffPoint = sourceCurvePoint.GetTimeSpanPoint(intIntoStartTimeNum, sourceStartTimeNum); //源数据起始点与目标数据起始点相差的点数。
                        int        intCurveMergeNum       = sourceCurvePoint.GetPointCount() / convertedInto.GetPointCount();           //转换后数据的一个点对应源数据的几个点

                        for (int intIndex = 0; intIndex < decValue.Length; intIndex++)
                        {
                            AC.Base.Drives.CurveValue.ICurveMerge _CurveMerge = null;
                            switch (mergeOption)
                            {
                            case CurveMergeOptions.Addition:
                                _CurveMerge = new AC.Base.Drives.CurveValue.CurveMergeAddition();
                                break;

                            case CurveMergeOptions.Average:
                                _CurveMerge = new AC.Base.Drives.CurveValue.CurveMergeAverage();
                                break;

                            case CurveMergeOptions.First:
                                _CurveMerge = new AC.Base.Drives.CurveValue.CurveMergeFirst();
                                break;

                            case CurveMergeOptions.Maximum:
                                _CurveMerge = new AC.Base.Drives.CurveValue.CurveMergeMaximum();
                                break;

                            case CurveMergeOptions.Minimum:
                                _CurveMerge = new AC.Base.Drives.CurveValue.CurveMergeMinimum();
                                break;

                            default:
                                throw new Exception("无 " + mergeOption.ToString() + " 数据转换方法。");
                            }

                            int intIntoTimeNum = convertedInto.GetTimeNum(intIntoStartTimeNum, intIndex);
                            for (int intCurveMergeIndex = 0; intCurveMergeIndex < intCurveMergeNum; intCurveMergeIndex++)
                            {
                                int intSourceTimeNum = sourceCurvePoint.GetTimeNum(intIntoTimeNum, intCurveMergeIndex);
                                if (sourceStartTimeNum <= intSourceTimeNum && intSourceTimeNum <= sourceEndTimeNum)
                                {
                                    _CurveMerge.Value.Add(sourceValues[intIndex * intCurveMergeNum + intCurveMergeIndex - intSourceIntoDiffPoint]);
                                }
                            }
                            decValue[intIndex] = _CurveMerge.GetValue();
                        }
                        return(decValue);
                    }
                    else if (sourceCurvePoint == CurvePointOptions.Point144 && convertedInto == CurvePointOptions.Point96)
                    {
                        //将144点转为96点。先将144点转为288点,然后将288点转为96点。
                        decimal?[] decValue288 = ConvertTo(CurvePointOptions.Point144, sourceStartTimeNum, sourceValues, CurvePointOptions.Point288, mergeOption, splitOption);
                        return(ConvertTo(CurvePointOptions.Point288, sourceStartTimeNum, decValue288, CurvePointOptions.Point96, mergeOption, splitOption));
                    }
                    else
                    {
                        throw new Exception("尚不支持将 " + sourceCurvePoint.GetPointCount() + " 点数据转为 " + convertedInto.GetPointCount() + " 点数据。");
                    }
                }
                else
                {
                    //sourceCurvePoint < convertedInto
                    if ((convertedInto.GetPointCount() % sourceCurvePoint.GetPointCount()) == 0)
                    {
                        int        intIntoEndTimeNum = convertedInto.GetTimeNum(sourceCurvePoint.GetTimeNum(sourceEndTimeNum, 1), -1); //转换后的结束时间。源时间加一个点的时间转成目标时间后,再计算目标时间减一个点的时间
                        int        intIntoPointCount = convertedInto.GetTimeSpanPoint(intIntoStartTimeNum, intIntoEndTimeNum) + 1;     //转换后的数据点数
                        decimal?[] decValue          = new decimal?[intIntoPointCount];
                        int        intCurveSplitNum  = convertedInto.GetPointCount() / sourceCurvePoint.GetPointCount();               //源数据的一个点对应转换后数据的几个点

                        for (int intIndex = 0; intIndex < sourceValues.Length; intIndex++)
                        {
                            if (sourceValues[intIndex] != null)
                            {
                                for (int intCurveSplitIndex = 0; intCurveSplitIndex < intCurveSplitNum; intCurveSplitIndex++)
                                {
                                    switch (splitOption)
                                    {
                                    case CurveSplitOptions.Division:
                                        decValue[intIndex * intCurveSplitNum + intCurveSplitIndex] = sourceValues[intIndex] / intCurveSplitNum;
                                        break;

                                    case CurveSplitOptions.Copy:
                                        decValue[intIndex * intCurveSplitNum + intCurveSplitIndex] = sourceValues[intIndex];
                                        break;

                                    default:
                                        throw new Exception("无 " + splitOption.ToString() + " 数据转换方法。");
                                    }
                                }
                            }
                        }
                        return(decValue);
                    }
                    else if (sourceCurvePoint == CurvePointOptions.Point96 && convertedInto == CurvePointOptions.Point144)
                    {
                        //将96点转为144点。先将96点转为288点,然后将288点转为144点。
                        decimal?[] decValue288 = ConvertTo(CurvePointOptions.Point96, sourceStartTimeNum, sourceValues, CurvePointOptions.Point288, mergeOption, splitOption);
                        return(ConvertTo(CurvePointOptions.Point288, sourceStartTimeNum, decValue288, CurvePointOptions.Point144, mergeOption, splitOption));
                    }
                    else
                    {
                        throw new Exception("尚不支持将 " + sourceCurvePoint.GetPointCount() + " 点数据转为 " + convertedInto.GetPointCount() + " 点数据。");
                    }
                }
            }
        }