private BarGraph GraphHourlyPages( PageInfoCollection pages, PageResolution res, string title, string fname )
{
int[] totals = new int[24];
int[] counts = new int[24];
DateTime[] dates = new DateTime[24];
DateTime max = DateTime.Now;
DateTime min = max - TimeSpan.FromDays( 7.0 );
bool sentStamp = ( res == PageResolution.None );
for ( int i = 0; i < pages.Count; ++i )
{
if ( res != PageResolution.None && pages[i].Resolution != res )
continue;
DateTime ts = ( sentStamp ? pages[i].TimeSent : pages[i].TimeResolved );
if ( ts >= min && ts < max )
{
DateTime date = ts.Date;
TimeSpan time = ts.TimeOfDay;
int hour = time.Hours;
totals[hour]++;
if ( dates[hour] != date )
{
counts[hour]++;
dates[hour] = date;
}
}
}
BarGraph barGraph = new BarGraph( title, fname, 10, "Time", "Pages", BarGraphRenderMode.Lines );
barGraph.FontSize = 6;
for ( int i = 7; i <= totals.Length+7; ++i )
{
int val;
if ( counts[i%totals.Length] == 0 )
val = 0;
else
val = (totals[i%totals.Length] + (counts[i%totals.Length] / 2)) / counts[i%totals.Length];
int realHours = i%totals.Length;
int hours;
if ( realHours == 0 )
hours = 12;
else if ( realHours > 12 )
hours = realHours - 12;
else
hours = realHours;
barGraph.Items.Add( hours + (realHours >= 12 ? " PM" : " AM"), val );
}
return barGraph;
}