Пример #1
0
        public async Task <ICursor <T> > GetCursorAsync <T>(Guid signalId)
        {
            myCoreService = CoreService.GetInstance();
            var signal = await myCoreService.GetOneByIdAsync(signalId);

            int sampleCount = (int)signal.NumberOfSamples;

            List <IPage <SEPayload> > listIPage = new List <IPage <SEPayload> >();
            List <long> dimPage = new List <long>();

            Byte[]            pagingState      = null;
            Cql               cql              = Cql.New("SELECT * FROM sepayload where parentid=?", signalId);
            IPage <SEPayload> ipagePartialList = (await mapper.FetchPageAsync <SEPayload>(cql.WithOptions(opt => opt.SetPageSize(pagesize).SetPagingState(pagingState))));

            listIPage.Add(ipagePartialList);
            while (ipagePartialList.PagingState != null)
            {
                pagingState      = ipagePartialList.PagingState;
                ipagePartialList = (await mapper.FetchPageAsync <SEPayload>(cql.WithOptions(opt => opt.SetPageSize(pagesize).SetPagingState(pagingState))));
                if (ipagePartialList.Count() > 0)
                {
                    listIPage.Add(ipagePartialList);
                }
            }
            long dimPageCount = listIPage.Count() - dimPage.Sum();

            dimPage.Add(dimPageCount);

            Cursor <T> jdbccursor = new Cursor <T>(listIPage);

            return(jdbccursor);
        }
Пример #2
0
        public async Task <ICursor <T> > GetCursorAsync <T>(Guid signalId, List <long> start, List <long> count, List <long> decimationFactor = null)
        {
            List <IPage <SEPayload> > listIPage = new List <IPage <SEPayload> >();
            long queryStart = start.LastOrDefault();
            long queryEnd;

            if (decimationFactor == null)
            {
                decimationFactor = new List <long>();
                for (int i = 0; i < start.Count; i++)
                {
                    decimationFactor.Add(1);
                }
                queryEnd = queryStart + count.LastOrDefault();
            }
            else
            {
                queryEnd = queryStart + decimationFactor.LastOrDefault() * (count.LastOrDefault() - 1);
            }
            long num    = count.LastOrDefault();
            long factor = decimationFactor[decimationFactor.Count() - 1];
            //from the second lowest rank find each line to read
            long lineCount = 1;

            //how many lines to read
            for (int i = 0; i < count.Count - 1; i++)
            {
                lineCount = lineCount * count[i];
            }
            List <long> lineCursor  = new List <long>(start.Count - 1);
            List <long> lineCounter = new List <long>(start.Count - 1);

            //the line cursor has every but last rank of the start point, point to the start line
            lineCursor.AddRange(start.Where((v, i) => i < start.Count - 1));
            lineCounter.AddRange(count.Where((v, i) => i < count.Count - 1));
            List <long> dimPage = new List <long>();

            for (long line = 0; line < lineCount; line++)
            {
                #region
                Byte[] pagingState = null;
                string dimension   = DimensionsToText(lineCursor);
                Cql    cql         = Cql.New("SELECT * FROM sepayload where parentid=? and dimensions=? and start<=? ", signalId, dimension, queryEnd);
                //     Cql cql = Cql.New("SELECT * FROM sepayload where parentid=? and dimensions=? ", signalId, dimension);
                IPage <SEPayload> ipagePartialList = (await mapper.FetchPageAsync <SEPayload>(cql.WithOptions(opt => opt.SetPageSize(pagesize).SetPagingState(pagingState))));
                listIPage.Add(ipagePartialList);
                while (ipagePartialList.PagingState != null)
                {
                    pagingState      = ipagePartialList.PagingState;
                    ipagePartialList = (await mapper.FetchPageAsync <SEPayload>(cql.WithOptions(opt => opt.SetPageSize(pagesize).SetPagingState(pagingState))));
                    if (ipagePartialList.Count() > 0)
                    {
                        listIPage.Add(ipagePartialList);
                    }
                }
                long dimPageCount = listIPage.Count() - dimPage.Sum();
                dimPage.Add(dimPageCount);

                /***************************************/
                #endregion
                for (var rankIndex = lineCursor.Count - 1; rankIndex >= 0; rankIndex--)
                {
                    //try read next line
                    lineCounter[rankIndex] -= 1;
                    if (lineCounter[rankIndex] == 0)
                    {
                        lineCounter[rankIndex] = count[rankIndex];
                        lineCursor[rankIndex]  = start[rankIndex];
                    }
                    else
                    {
                        //move this rank forward
                        lineCursor[rankIndex] += decimationFactor[rankIndex];
                        break;
                    }
                }
            }
            Cursor <T> jdbccursor = new Cursor <T>(listIPage, start.LastOrDefault(), count, dimPage, decimationFactor.LastOrDefault());
            return(jdbccursor);
        }
Пример #3
0
        public async Task <ICursor <T> > GetCursorAsync <T>(Guid signalId, List <long> start, List <long> count, List <long> decimationFactor = null)
        {
            myCoreService = CoreService.GetInstance();
            var signal = await myCoreService.GetOneByIdAsync(signalId);

            int sampleCount = (int)signal.NumberOfSamples;
            int indexStart  = (int)start.LastOrDefault();
            int getNumber   = (int)count.LastOrDefault();

            List <IPage <SEPayload> > listIPage = new List <IPage <SEPayload> >();

            if (decimationFactor == null)
            {
                decimationFactor = new List <long>();
                for (int i = 0; i < start.Count; i++)
                {
                    decimationFactor.Add(1);
                }
            }

            int factor = (int)decimationFactor[decimationFactor.Count() - 1];
            //from the second lowest rank find each line to read
            long lineCount = 1;

            //how many lines to read
            for (int i = 0; i < count.Count - 1; i++)
            {
                lineCount = lineCount * count[i];
            }
            List <long> lineCursor  = new List <long>(start.Count - 1);
            List <long> lineCounter = new List <long>(start.Count - 1);

            //the line cursor has every but last rank of the start point, point to the start line
            lineCursor.AddRange(start.Where((v, i) => i < start.Count - 1));
            lineCounter.AddRange(count.Where((v, i) => i < count.Count - 1));
            List <long> dimPage = new List <long>();

            List <long> indexes = new List <long>();

            for (int line = 0; line < lineCount; line++)
            {
                #region
                Byte[] pagingState = null;
                string dimension   = DimensionsToText(lineCursor);
                //计算index
                if (factor < sampleCount)
                {
                    var lastPoint  = (factor * getNumber + indexStart) - factor;
                    var lastIndex  = lastPoint / sampleCount + 1;
                    var firstIndex = indexStart / sampleCount;
                    for (int i = firstIndex; i < lastIndex; i++)
                    {
                        indexes.Add(i);
                    }
                }
                else
                {
                    int coordinate = 0;
                    int variable   = 0;
                    //每个点取一次比较
                    for (int i = 0; i < getNumber; i++)
                    {
                        coordinate = indexStart + i * factor;
                        variable   = coordinate / sampleCount;
                        indexes.Add(variable);
                    }
                }
                //

                Cql cql = Cql.New("SELECT * FROM sepayload where parentid=? and dimensions=? and indexes in ? ", signalId, dimension, indexes);
                IPage <SEPayload> ipagePartialList = (await mapper.FetchPageAsync <SEPayload>(cql.WithOptions(opt => opt.SetPageSize(pagesize).SetPagingState(pagingState))));
                //  Debug.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")+ "   getPAge");
                if (ipagePartialList.Count == 0)
                {
                    throw new Exception(ErrorMessages.DataNotFoundError);
                }
                listIPage.Add(ipagePartialList);
                while (ipagePartialList.PagingState != null)
                {
                    pagingState      = ipagePartialList.PagingState;
                    ipagePartialList = (await mapper.FetchPageAsync <SEPayload>(cql.WithOptions(opt => opt.SetPageSize(pagesize).SetPagingState(pagingState))));
                    if (ipagePartialList.Count() > 0)
                    {
                        listIPage.Add(ipagePartialList);
                    }
                }
                long dimPageCount = listIPage.Count() - dimPage.Sum();
                dimPage.Add(dimPageCount);

                /***************************************/
                #endregion
                for (var rankIndex = lineCursor.Count - 1; rankIndex >= 0; rankIndex--)
                {
                    //try read next line
                    lineCounter[rankIndex] -= 1;
                    if (lineCounter[rankIndex] == 0)
                    {
                        lineCounter[rankIndex] = count[rankIndex];
                        lineCursor[rankIndex]  = start[rankIndex];
                    }
                    else
                    {
                        //move this rank forward
                        lineCursor[rankIndex] += decimationFactor[rankIndex];
                        break;
                    }
                }
            }
            Cursor <T> jdbccursor = new Cursor <T>(listIPage, start.LastOrDefault(), count, dimPage, sampleCount, decimationFactor.LastOrDefault());
            return(jdbccursor);
        }