Ejemplo n.º 1
0
        //  public async Task<ICursor> GetCursorAsync<T>(Signal signal, string fragment)
        /// <summary>
        /// 使用Cursor读取大数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="signal"></param>
        /// <param name="fragment"></param>
        /// <returns></returns>
        public async Task <ICursor> GetCursorAsync(Signal signal, string dataFragment)
        {
            var waveSig = signal as FixedIntervalWaveSignal;

            if (waveSig == null)
            {
                throw new Exception(ErrorMessages.NotValidSignalError);
            }
            WaveFragment frag = null;

            try
            {
                frag = WaveFragment.Parse(waveSig, dataFragment);
            }
            catch (Exception)
            {
                throw new Exception(ErrorMessages.NotValidSignalFragmentError);
            }

            var startIndex = (long)Math.Ceiling((frag.Start - waveSig.StartTime) / waveSig.SampleInterval);
            var count      = (long)Math.Floor((frag.End - frag.Start) / waveSig.SampleInterval / frag.DecimationFactor) + 1;

            return(await myStorageEngine.GetCursorAsync <T>(waveSig.Id, new List <long> {
                startIndex
            }, new List <long> {
                count
            }, new List <long> {
                frag.DecimationFactor
            }));
        }
Ejemplo n.º 2
0
        public async Task <object> GetDataAsync(Signal signal, string fragment, string format)
        {
            var          waveSig = signal as FixedIntervalWaveSignal;
            WaveFragment frag    = WaveFragment.Parse(waveSig, fragment);

            var startIndex = (long)Math.Ceiling((frag.Start - waveSig.StartTime) / waveSig.SampleInterval);
            var count      = (long)Math.Floor((frag.End - frag.Start) / waveSig.SampleInterval / frag.DecimationFactor) + 1;

            ICursor <double> myCursor = (ICursor <double>) await GetCursorAsync(signal, fragment);

            //  ICursor<double> myCursor = new Cursor<double>(myCoreService, signal, fragment);

            List <double> resultArray = new List <double>();

            //防止读时越界 review cursor 目前一次只能读1000个点?
            while (myCursor.LeftPoint > 1000)
            {
                resultArray.AddRange(await myCursor.Read(1000));
            }
            if (myCursor.LeftPoint > 0)
            {
                resultArray.AddRange(await myCursor.Read(myCursor.LeftPoint));
            }
            if (format == "complex")
            {
                return(new FixedIntervalWaveComplex <double>
                {
                    Title = waveSig.Path,
                    Start = startIndex * waveSig.SampleInterval + waveSig.StartTime,
                    End = waveSig.StartTime + ((count - 1) * frag.DecimationFactor + startIndex) * waveSig.SampleInterval,
                    Count = count,
                    Data = resultArray,
                    DecimatedSampleInterval = waveSig.SampleInterval * frag.DecimationFactor,
                    OrignalSampleInterval = waveSig.SampleInterval,
                    DecimationFactor = frag.DecimationFactor,
                    StartIndex = startIndex,
                    Unit = waveSig.Unit
                });
            }
            else if (format == "point")
            {
                var points = new List <SignalPoint <double> >();
                //添加中间详细点
                double x = frag.Start;
                foreach (var data in resultArray)
                {
                    points.Add(new SignalPoint <double>(x, data));
                    x += waveSig.SampleInterval * frag.DecimationFactor;
                }
                return(points);
            }
            else
            {
                return(resultArray);
            }
        }
Ejemplo n.º 3
0
        public async Task <ICursor> GetCursorAsync(Signal signal, string dataFragment)
        {
            var waveSig = signal as FixedIntervalWaveSignal;

            if (waveSig == null)
            {
                throw new Exception(ErrorMessages.NotValidSignalError);
            }
            if (signal.ExtraInformation.Keys.Contains("expression"))
            {
                string code = (string)signal.ExtraInformation["expression"];
                if (code.Contains("JDBC.Signal"))
                {
                    MatchCollection         mc        = Regex.Matches(code, "(?<=JDBC.Signal\\(\").*?(?=\"\\))");
                    List <Match>            matchList = mc.Cast <Match>().ToList();
                    FixedIntervalWaveSignal codeSig   = (FixedIntervalWaveSignal)await myCoreService.GetOneByPathAsync(matchList.FirstOrDefault().Value);

                    waveSig.StartTime      = codeSig.StartTime;
                    waveSig.EndTime        = codeSig.EndTime;
                    waveSig.SampleInterval = codeSig.SampleInterval;
                    waveSig.Unit           = codeSig.Unit;
                    await myCoreService.SaveAsync(waveSig);
                }
                else
                {
                    throw new Exception(ErrorMessages.NotValidExpressionStringError);
                }
            }
            else
            {
                throw new Exception(ErrorMessages.ExpressionNotFoundError);
            }
            WaveFragment frag = null;

            try
            {
                frag = WaveFragment.Parse(waveSig, dataFragment);
            }
            catch (Exception)
            {
                throw new Exception(ErrorMessages.NotValidSignalFragmentError);
            }

            var startIndex = (long)Math.Ceiling((frag.Start - waveSig.StartTime) / waveSig.SampleInterval);
            var count      = (long)Math.Floor((frag.End - frag.Start) / waveSig.SampleInterval / frag.DecimationFactor) + 1;

            ICursor <double> myCursor = new Cursor <double>(myCoreService, signal, new List <long> {
                startIndex
            }, new List <long> {
                count
            }, new List <long> {
                frag.DecimationFactor
            });

            return(myCursor);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// format is "array"(default) or "complex"
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="signal"></param>
        /// <param name="fragment">fragment: "start=t1&end=t2&decimation=2&count=1000" decimation is optional, if end is no bigger then start then return all</param>
        /// <param name="format">format is "array"(default) or "complex" </param>
        /// <returns></returns>
        public async Task <object> GetDataAsync(Signal signal, string fragment, string format)
        {
            //  var waveSig = signal as FixedIntervalWaveSignal<T>;
            var waveSig = signal as FixedIntervalWaveSignal;

            if (waveSig == null)
            {
                throw new Exception(ErrorMessages.NotValidSignalError);
            }
            WaveFragment frag = null;

            try
            {
                frag = WaveFragment.Parse(waveSig, fragment);
            }
            catch (Exception)
            {
                throw new Exception("Fragment parse error!");
            }

            var startPoint = (long)Math.Ceiling((frag.Start - waveSig.StartTime) / waveSig.SampleInterval);
            var count      = (long)Math.Floor((frag.End - frag.Start) / waveSig.SampleInterval / frag.DecimationFactor) + 1;
            //   Debug.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")+ "  getCursor");
            ICursor <T> cursor = await myStorageEngine.GetCursorAsync <T>(waveSig.Id, new List <long> {
                startPoint
            }, new List <long> {
                count
            }, new List <long> {
                frag.DecimationFactor
            });

            List <T> resultArray = new List <T>();

            //   Debug.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff") + "   getData");
            //防止读时越界 review cursor 目前一次只能读1000个点?
            while (cursor.LeftPoint > 1000)
            {
                resultArray.AddRange(await cursor.Read(1000));
            }
            if (cursor.LeftPoint > 0)
            {
                resultArray.AddRange(await cursor.Read(cursor.LeftPoint));
            }
            //   Debug.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff") + "   readFinish");
            if (format == "complex")
            {
                return(new FixedIntervalWaveComplex <T>
                {
                    Title = waveSig.Path,
                    Start = startPoint * waveSig.SampleInterval + waveSig.StartTime,
                    End = waveSig.StartTime + ((count - 1) * frag.DecimationFactor + startPoint) * waveSig.SampleInterval,
                    Count = count,
                    Data = resultArray,
                    DecimatedSampleInterval = waveSig.SampleInterval * frag.DecimationFactor,
                    OrignalSampleInterval = waveSig.SampleInterval,
                    DecimationFactor = frag.DecimationFactor,
                    StartIndex = startPoint,
                    Unit = waveSig.Unit
                });
            }
            else if (format == "point")
            {
                var points = new List <SignalPoint <T> >();
                //添加中间详细点
                double x = frag.Start;
                foreach (var data in resultArray)
                {
                    points.Add(new SignalPoint <T>(x, data));
                    x += waveSig.SampleInterval * frag.DecimationFactor;
                }
                return(points);
            }
            else
            {
                return(resultArray);
            }
        }