Add start and stop date options to subunit2sql-graph

This commit adds an optional start and stop date option to the
subunit2sql-graph command. It lets users filter the output graph to
only use the data in the provided range.

Change-Id: I550852c3ba2e8e396c382b82ea56ed175785515c
This commit is contained in:
Matthew Treinish 2015-04-21 17:31:12 -04:00
parent 38fc62d2c2
commit 2ad66e54d0
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
2 changed files with 43 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import sys
from oslo.config import cfg
import pandas as pd
from subunit2sql.analysis import utils
from subunit2sql.db import api
from subunit2sql import shell
@ -32,7 +33,13 @@ SHELL_OPTS = [
'full test_id will be used'),
cfg.StrOpt('output', short='o', required=True,
help='Output path to write image file to. The file extension '
'will determine the file format.')
'will determine the file format.'),
cfg.StrOpt('start-date', short='d',
help='Start date for the graph only data from after this date '
'will be used. Uses ISO8601 format: 1914-06-28'),
cfg.StrOpt('stop-date', short='s',
help='Stop date for the graph only data from before this date '
'will be used. Uses ISO8601 format: 1914-06-28'),
]
@ -53,6 +60,7 @@ def generate_series(test_id):
test = api.get_test_by_id(test_id, session)
session.close()
ts = pd.Series(run_times)
ts = utils.filter_dates(ts)
if not CONF.title:
plot = ts.plot().set_title(test.test_id)
else:

View File

@ -0,0 +1,34 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import datetime
from oslo_config import cfg
CONF = cfg.CONF
def filter_dates(ts):
if CONF.start_date:
start_date = datetime.datetime.strptime(CONF.start_date, '%Y-%m-%d')
if CONF.stop_date:
stop_date = datetime.datetime.strptime(CONF.stop_date, '%Y-%m-%d')
ts = ts.ix[start_date:stop_date]
else:
ts = ts.ix[start_date:]
elif CONF.stop_date:
stop_date = datetime.datetime.strptime(CONF.stop_date, '%Y-%m-%d')
ts = ts.ix[:stop_date]
return ts