Fix dailycount command

This commit fixes the dailycount subunit2sql-graph command. This was one
of the earlier graph commands added and has since bitrotted a bit to the
point where it doesn't work anymore. This commit fixes all those issues
and bumps the minimum versions for pandas and matplotlib because of the
updated usage.

Story: 2001034
Task: 4590
Change-Id: Iaea5e2f6036d39b6aa57685d484cd02f323a4d39
This commit is contained in:
Matthew Treinish 2017-05-23 11:44:51 -04:00
parent 71d7811a3e
commit de195d5b75
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
2 changed files with 36 additions and 14 deletions

View File

@ -47,5 +47,5 @@ universal = 1
[extras]
graph =
pandas>=0.11
matplotlib>=1.4
pandas>=0.20.1
matplotlib>=2.0.2

View File

@ -12,12 +12,14 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
import matplotlib
import matplotlib.dates as dates
import matplotlib.pyplot as plt
from oslo_config import cfg
import pandas as pd
from subunit2sql.analysis import utils
from subunit2sql.db import api
CONF = cfg.CONF
@ -30,24 +32,44 @@ def set_cli_opts(parser):
def generate_series():
if CONF.start_date:
start_date = datetime.datetime.strptime(CONF.start_date, '%Y-%m-%d')
else:
start_date = None
if CONF.stop_date:
stop_date = datetime.datetime.strptime(CONF.stop_date, '%Y-%m-%d')
else:
stop_date = None
session = api.get_session()
test_starts = api.get_test_run_series(session)
test_starts = api.get_test_run_series(start_date=start_date,
stop_date=stop_date,
session=session)
session.close()
ts = pd.Series(test_starts).resample('D', how='sum')
daily_count = utils.filter_dates(ts)
mean = pd.rolling_mean(daily_count, 10)
rolling_std = pd.rolling_std(daily_count, 10)
ts = pd.Series(test_starts)
daily_count = ts.resample('D').sum()
mean = daily_count.rolling(window=10, center=False).mean()
rolling_std = daily_count.rolling(window=10, center=False).std()
plt.figure()
title = CONF.title or 'Number of tests run'
title = CONF.title or 'Number of Tests run Daily'
plt.title(title)
plt.ylabel('Number of tests')
plt.plot(daily_count.index, daily_count, 'k', label='Daily Test Count')
plt.plot(mean.index, mean, 'b', label='Avg. Daily Test Count')
fig, ax = plt.subplots(1)
fig.autofmt_xdate()
plt.title(title)
plt.ylabel('Number of tests')
xfmt = dates.DateFormatter("%b %d %Y")
ax.xaxis_date()
ax.xaxis.set_major_formatter(xfmt)
plt.plot(daily_count.index[10:], daily_count[10:], 'k',
label='Daily Test Count')
plt.plot(mean.index[10:], mean[10:], 'b', label='Avg. Daily Test Count')
upper_std_dev = mean + 2 * rolling_std
lower_std_dev = mean - 2 * rolling_std
# Set negative numbers to 0
lower_std_dev[lower_std_dev < 0] = 0
plt.fill_between(rolling_std.index, lower_std_dev, upper_std_dev,
color='b', alpha=0.2, label='std dev')
plt.fill_between(rolling_std.index[10:], lower_std_dev[10:],
upper_std_dev[10:],
color='b', alpha=0.2, label='Std Dev')
plt.legend()
plt.savefig(CONF.output)
plt.savefig(CONF.output, dpi=900)