public async Task <IHttpActionResult> GetVolume(
            DateTime startTime,
            DateTime endTime,
            int numberBuckets)
        {
            var data = await _reader.GetVolumeAsync(startTime, endTime, numberBuckets);

            // Return as parallel arrays since that's more efficient than an array of structs.
            var result = new
            {
                Times          = Array.ConvertAll(data, x => x.Time),
                Counts         = Array.ConvertAll(data, x => x.Volume),
                InstanceCounts = Array.ConvertAll(data, x => x.InstanceCounts)
            };

            return(Ok(result));
        }
        public async Task FunctionInstance()
        {
            var table = GetNewLoggingTable();

            try
            {
                ILogReader reader = LogFactory.NewReader(table);
                TimeSpan   poll   = TimeSpan.FromMilliseconds(50);
                TimeSpan   poll5  = TimeSpan.FromMilliseconds(poll.TotalMilliseconds * 5);

                var logger1 = new CloudTableInstanceCountLogger("c1", table, 100)
                {
                    PollingInterval = poll
                };

                Guid g1 = Guid.NewGuid();

                DateTime startTime = DateTime.UtcNow;
                logger1.Increment(g1);
                await Task.Delay(poll5); // should get at least 1 poll entry in

                logger1.Decrement(g1);
                await Task.WhenAll(logger1.StopAsync());

                DateTime endTime = DateTime.UtcNow;

                // Now read.
                // We may get an arbitrary number of raw poll entries since the
                // low poll latency combined with network delay can be unpredictable.
                var values = await reader.GetVolumeAsync(startTime, endTime, 1);

                double totalVolume = (from value in values select value.Volume).Sum();
                Assert.True(totalVolume > 0);

                double totalInstance = (from value in values select value.InstanceCounts).Sum();
                Assert.Equal(1, totalInstance);
            }
            finally
            {
                table.DeleteIfExists();
            }
        }