Commit 8e1bd9f6 authored by Vincent Pelletier's avatar Vincent Pelletier

Use more appropriate date locators & formatters.

parent ddb41afa
......@@ -51,9 +51,14 @@ except ImportError:
else:
matplotlib.use('Agg')
import matplotlib.pyplot as pyplot
from matplotlib.dates import DateFormatter, DayLocator
day_formatter = DateFormatter('%Y-%m-%d')
all_days = DayLocator()
from matplotlib.dates import (
DateFormatter,
DayLocator,
HourLocator,
AutoDateLocator,
AutoDateFormatter,
)
MONTH_VALUE_DICT = dict((y, x) for (x, y) in enumerate(('Jan', 'Feb', 'Mar',
'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), 1))
......@@ -455,17 +460,28 @@ def main():
daily_data = data.getApdexData()
date_list = [datetime.strptime(x[0], '%Y/%m/%d' + {'hour': ' %H'}.get(
args.period, '')) for x in daily_data]
date_range = date_list[-1] - date_list[0]
if date_range < timedelta(2):
date_formatter = DateFormatter('%Y-%m-%dT%H')
date_locator = HourLocator(
interval=int((date_range / 4).total_seconds() / 3600))
elif date_range < timedelta(6):
date_formatter = DateFormatter('%Y-%m-%d')
date_locator = DayLocator()
else:
date_locator = AutoDateLocator()
date_formatter = AutoDateFormatter(date_locator)
apdex_plot = pyplot.subplot(2, 1, 1)
apdex_plot.xaxis.set_major_locator(all_days)
apdex_plot.xaxis.set_major_formatter(day_formatter)
apdex_plot.xaxis.set_major_locator(date_locator)
apdex_plot.xaxis.set_major_formatter(date_formatter)
pyplot.title('Apdex')
pyplot.ylabel('%')
pyplot.plot(date_list, [x[1] for x in daily_data], '-')
pyplot.plot(date_list, [x[1] for x in daily_data], '.')
# response_time_plot = pyplot.subplot(3, 1, 2)
# response_time_plot.xaxis.set_major_locator(all_days)
# response_time_plot.xaxis.set_major_formatter(day_formatter)
# response_time_plot.xaxis.set_major_locator(date_locator)
# response_time_plot.xaxis.set_major_formatter(date_formatter)
# pyplot.title('Response time')
# pyplot.ylabel('time (s)')
# pyplot.plot(date_list, [x[2] for x in daily_data], '-', label='Average')
......@@ -473,8 +489,8 @@ def main():
# pyplot.legend()
hit_plot = pyplot.subplot(2, 1, 2)
hit_plot.xaxis.set_major_locator(all_days)
hit_plot.xaxis.set_major_formatter(day_formatter)
hit_plot.xaxis.set_major_locator(date_locator)
hit_plot.xaxis.set_major_formatter(date_formatter)
pyplot.title('Hits')
pyplot.plot(date_list, [x[4] for x in daily_data], '-')
pyplot.plot(date_list, [x[4] for x in daily_data], '.')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment