Esempio 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
            }));
        }
Esempio n. 2
0
        /// <summary>
        /// parse the fragment string,
        /// "start=t1&end=t2&decimation=2" decimation is optional
        /// </summary>
        /// <param name="fragment"></param>
        /// <returns></returns>
        public static WaveFragment Parse(FixedIntervalWaveSignal waveSig, string fragment)
        {
            //"start=t1&end=t2&decimation=2&count=1000" decimation is optional
            if (fragment.StartsWith("#"))
            {
                fragment = fragment.Substring(1);
            }
            var sections = fragment.Split(new char[] { '&' });
            var result   = new WaveFragment {
                DecimationFactor = 1, Start = waveSig.StartTime, End = waveSig.EndTime + waveSig.SampleInterval, Count = 0
            };

            foreach (var sec in sections)
            {
                if (sec.Contains("start"))
                {
                    result.Start = double.Parse(sec.Substring(6));
                }
                if (sec.Contains("end"))
                {
                    result.End = double.Parse(sec.Substring(4)) + waveSig.SampleInterval;
                }
                if (sec.Contains("decimation"))
                {
                    result.DecimationFactor = long.Parse(sec.Substring(11));
                }
                if (sec.Contains("count"))
                {
                    result.Count = long.Parse(sec.Substring(6)) > 0 ? long.Parse(sec.Substring(6)) : 0;
                }
            }
            //end smaller then start then read all
            if (result.Start >= result.End)
            {
                result.Start = waveSig.StartTime;
                result.End   = waveSig.EndTime;
            }
            if (result.Start < waveSig.StartTime)
            {
                result.Start = waveSig.StartTime;
            }
            if (result.End > waveSig.EndTime)
            {
                result.End = waveSig.EndTime;
            }
            //calc the decimationfactor is count valid
            if (result.Count > 0)
            {
                //todo can be optimized a little
                result.DecimationFactor = (long)Math.Floor(((result.End - result.Start) / waveSig.SampleInterval + 1) / result.Count);
            }
            if (result.DecimationFactor < 1)
            {
                result.DecimationFactor = 1;
            }
            return(result);
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
            }
        }