def generate_series(): session = api.get_session() test_starts = api.get_test_run_series(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) plt.figure() title = CONF.title or 'Number of tests run' 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') 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.legend() plt.savefig(CONF.output)
def test_get_test_run_series_with_meta(self): timestamp_a = datetime.datetime.utcnow() timestamp_b = timestamp_a + datetime.timedelta(minutes=2) run_a = api.create_run(passes=5, run_at=timestamp_a) api.create_run(fails=2, run_at=timestamp_b) api.add_run_metadata({'not_a_key': 'not_a_value'}, run_a.id) result = api.get_test_run_series(key='not_a_key', value='not_a_value') self.assertEqual(1, len(result.keys())) self.assertIn(timestamp_a.replace(microsecond=0), [x.replace(microsecond=0) for x in list(result.keys())]) self.assertNotIn( timestamp_b.replace(microsecond=0), [x.replace(microsecond=0) for x in list(result.keys())]) self.assertEqual(5, result[list(result.keys())[0]])
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(start_date=start_date, stop_date=stop_date, session=session, key=CONF.command.dcmd_key, value=CONF.command.dcmd_value) session.close() ts = pd.Series(test_starts) daily_count = ts.resample('D').sum().fillna(value=0) 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 Daily' plt.title(title) plt.ylabel('Number of tests') 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[10:], lower_std_dev[10:], upper_std_dev[10:], color='b', alpha=0.2, label='Std Dev') plt.legend() plt.savefig(CONF.output, dpi=900)
def test_get_test_run_series_with_meta(self): timestamp_a = datetime.datetime.utcnow() timestamp_b = timestamp_a + datetime.timedelta(minutes=2) run_a = api.create_run(passes=5, run_at=timestamp_a) api.create_run(fails=2, run_at=timestamp_b) api.add_run_metadata({'not_a_key': 'not_a_value'}, run_a.id) result = api.get_test_run_series(key='not_a_key', value='not_a_value') self.assertEqual(1, len(result.keys())) self.assertIn(timestamp_a.replace(microsecond=0), [x.replace(microsecond=0) for x in list(result.keys())]) self.assertNotIn(timestamp_b.replace(microsecond=0), [x.replace(microsecond=0) for x in list( result.keys())]) self.assertEqual(5, result[list(result.keys())[0]])
def test_get_test_run_series(self): timestamp_a = datetime.datetime.utcnow() timestamp_b = timestamp_a + datetime.timedelta(minutes=2) api.create_run(passes=5, run_at=timestamp_a) api.create_run(fails=2, run_at=timestamp_b) result = api.get_test_run_series(key=None, value=None) self.assertEqual(2, len(result.keys())) self.assertIn(timestamp_a.replace(microsecond=0), [x.replace(microsecond=0) for x in list(result.keys())]) self.assertIn(timestamp_b.replace(microsecond=0), [x.replace(microsecond=0) for x in list(result.keys())]) for timestamp in result: if timestamp.replace(microsecond=0) == timestamp_a.replace( microsecond=0): self.assertEqual(5, result[timestamp]) else: self.assertEqual(2, result[timestamp])
def test_get_test_run_series(self): timestamp_a = datetime.datetime.utcnow() timestamp_b = timestamp_a + datetime.timedelta(minutes=2) api.create_run(passes=5, run_at=timestamp_a) api.create_run(fails=2, run_at=timestamp_b) result = api.get_test_run_series(key=None, value=None) self.assertEqual(2, len(result.keys())) self.assertIn(timestamp_a.replace(microsecond=0), [x.replace(microsecond=0) for x in list(result.keys())]) self.assertIn(timestamp_b.replace(microsecond=0), [x.replace(microsecond=0) for x in list(result.keys())]) for timestamp in result: if timestamp.replace( microsecond=0) == timestamp_a.replace(microsecond=0): self.assertEqual(5, result[timestamp]) else: self.assertEqual(2, result[timestamp])
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(start_date=start_date, stop_date=stop_date, session=session, key=CONF.command.dcmd_key, value=CONF.command.dcmd_value) session.close() ts = pd.Series(test_starts) daily_count = ts.resample('D').sum().fillna(value=0) 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 Daily' plt.title(title) plt.ylabel('Number of tests') 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[10:], lower_std_dev[10:], upper_std_dev[10:], color='b', alpha=0.2, label='Std Dev') plt.legend() plt.savefig(CONF.output, dpi=CONF.dpi)