Firstly, I'd add a method to the PageHit class (or as an extension method) to calculate the rounded response time
public class PageHit
{
public DateTime RequestTime { get; set; }
public int PageResponseTime { get; set; }
public DateTime GetRequestTimeToNearest30Mins()
{
return RoundUp(RequestTime, TimeSpan.FromMinutes(30));
}
}
Then you can do something like the following
public void GetAverageRequestTimeByPeriod()
{
// Firstly project out both the PageHit and the rounded request time
var averages = _pageHits.Select(t => new { RoundedTime = t.GetRequestTimeToNearest30Mins(), PageHit = t})
// Then Group them all by the rounded time, forming the blocks you mention
.GroupBy(t => t.RoundedTime)
// Project out the block time and the average of each page hit response time in the block
.Select(g => new { RequestTimeBlock = g.Key, AverageResponseTime = g.Average(t => t.PageHit.PageResponseTime)})
.ToArray();
}
Obviously you'd want to do something with the resulting averages, but I'll leave that part to you