From 4691049d2c7ab980e4bb09cd0fd01c71d92d8579 Mon Sep 17 00:00:00 2001 From: Vadim Markovtsev Date: Mon, 25 Feb 2019 15:31:40 +0100 Subject: [PATCH] Add labours.py --start-date and --end-date Signed-off-by: Vadim Markovtsev --- labours.py | 32 ++++++++++++++++++++++++++++---- requirements.txt | 1 + 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/labours.py b/labours.py index 51b903cc..f8d8236f 100755 --- a/labours.py +++ b/labours.py @@ -70,6 +70,13 @@ def parse_args(): "\"month\", \"year\", \"no\", \"raw\" and pandas offset aliases (" "http://pandas.pydata.org/pandas-docs/stable/timeseries.html" "#offset-aliases).") + dateutil_url = "https://dateutil.readthedocs.io/en/stable/parser.html#dateutil.parser.parse" + parser.add_argument("--start-date", + help="Start date of time-based plots. Any format is accepted which is " + "supported by %s" % dateutil_url) + parser.add_argument("--end-date", + help="End date of time-based plots. Any format is accepted which is " + "supported by %s" % dateutil_url) parser.add_argument("--disable-projector", action="store_true", help="Do not run Tensorflow Projector on couples.") parser.add_argument("--max-people", default=20, type=int, @@ -385,7 +392,15 @@ def read_input(args): sys.stdout.flush() if args.input != "-": if args.input_format == "auto": - args.input_format = args.input.rsplit(".", 1)[1] + try: + args.input_format = args.input.rsplit(".", 1)[1] + except IndexError: + try: + with open(args.input) as f: + f.read(1 << 16) + args.input_format = "yaml" + except UnicodeDecodeError: + args.input_format = "pb" elif args.input_format == "auto": args.input_format = "yaml" reader = READERS[args.input_format]() @@ -745,6 +760,13 @@ def default_json(x): return x +def parse_date(text, default): + if not text: + return default + from dateutil.parser import parse + return parse(text) + + def plot_burndown(args, target, name, matrix, date_range_sampling, labels, granularity, sampling, resample): if args.output and args.output.endswith(".json"): @@ -776,7 +798,8 @@ def plot_burndown(args, target, name, matrix, date_range_sampling, labels, granu pyplot.xlabel("Time") apply_plot_style(pyplot.gcf(), pyplot.gca(), legend, args.background, args.font_size, args.size) - pyplot.xlim(date_range_sampling[0], date_range_sampling[-1]) + pyplot.xlim(parse_date(args.start_date, date_range_sampling[0]), + parse_date(args.end_date, date_range_sampling[-1])) locator = pyplot.gca().xaxis.get_major_locator() # set the optimal xticks locator if "M" not in resample: @@ -898,7 +921,8 @@ def plot_ownership(args, repo, names, people, date_range, last): matplotlib, pyplot = import_pyplot(args.backend, args.style) pyplot.stackplot(date_range, people, labels=names) - pyplot.xlim(date_range[0], last) + pyplot.xlim(parse_date(args.start_date, date_range[0]), parse_date(args.end_date, last)) + if args.relative: for i in range(people.shape[1]): people[:, i] /= people[:, i].sum() @@ -1165,7 +1189,7 @@ def show_sentiment_stats(args, name, resample, start_date, data): pyplot.xlabel("Time") apply_plot_style(pyplot.gcf(), pyplot.gca(), legend, args.background, args.font_size, args.size) - pyplot.xlim(xdates[0], xdates[-1]) + pyplot.xlim(parse_date(args.start_date, xdates[0]), parse_date(args.end_date, xdates[-1])) locator = pyplot.gca().xaxis.get_major_locator() # set the optimal xticks locator if "M" not in resample: diff --git a/requirements.txt b/requirements.txt index e6320af7..5a130d47 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ munch>=2.0 hdbscan==0.8.18 ortools==6.9.5824 fastdtw==0.3.2 +python-dateutil==2.8.0