Пример #1
0
        public async Task <FunctionVolumeTimelineEntry[]> GetVolumeAsync(DateTime startTime, DateTime endTime, int numberBuckets)
        {
            var query = InstanceCountEntity.GetQuery(startTime, endTime);

            var iter = await EpochTableIterator.NewAsync(_tableLookup);

            var results = await iter.SafeExecuteQuerySegmentedAsync <InstanceCountEntity>(query, startTime, endTime);

            InstanceCountEntity[] rows = results.Results;

            var startTicks = startTime.Ticks;
            var endTicks   = endTime.Ticks;
            var data       = ProjectionHelper.Work(rows, startTicks, endTicks, numberBuckets);

            int[]  totalCounts      = new int[numberBuckets];
            double bucketWidthTicks = ((double)(endTicks - startTicks)) / numberBuckets;

            foreach (var row in rows)
            {
                int idx = (int)((row.GetTicks() - startTicks) / bucketWidthTicks);
                if (idx >= 0 && idx < numberBuckets)
                {
                    totalCounts[idx] += row.TotalThisPeriod;
                }
            }

            // coerce data
            var chart = new FunctionVolumeTimelineEntry[numberBuckets];

            for (int i = 0; i < numberBuckets; i++)
            {
                var    ticks = data[i].Item1;
                var    time  = new DateTime(ticks);
                double value = data[i].Item2;
                chart[i] = new FunctionVolumeTimelineEntry
                {
                    Time           = time,
                    Volume         = value,
                    InstanceCounts = totalCounts[i]
                };
            }

            return(chart);
        }
Пример #2
0
        public Task <FunctionVolumeTimelineEntry[]> GetVolumeAsync(DateTime startTime, DateTime endTime, int numberBuckets)
        {
            var query = InstanceCountEntity.GetQuery(startTime, endTime);

            IEnumerable <InstanceCountEntity> results = _instanceTable.ExecuteQuery(query);
            var rows = results.ToArray();

            var startTicks = startTime.Ticks;
            var endTicks   = endTime.Ticks;
            var data       = ProjectionHelper.Work(rows, startTicks, endTicks, numberBuckets);

            int[]  totalCounts      = new int[numberBuckets];
            double bucketWidthTicks = ((double)(endTicks - startTicks)) / numberBuckets;

            foreach (var row in rows)
            {
                int idx = (int)((row.GetTicks() - startTicks) / bucketWidthTicks);
                if (idx >= 0 && idx < numberBuckets)
                {
                    totalCounts[idx] += row.TotalThisPeriod;
                }
            }

            // coerce data
            var chart = new FunctionVolumeTimelineEntry[numberBuckets];

            for (int i = 0; i < numberBuckets; i++)
            {
                var    ticks = data[i].Item1;
                var    time  = new DateTime(ticks);
                double value = data[i].Item2;
                chart[i] = new FunctionVolumeTimelineEntry
                {
                    Time           = time,
                    Volume         = value,
                    InstanceCounts = totalCounts[i]
                };
            }

            return(Task.FromResult(chart));
        }