Skip to content

Commit 7ef5c47

Browse files
authored
Merge pull request #214 from vmarkovtsev/master
Add labours.py --start-date and --end-date
2 parents b15a7f7 + 4691049 commit 7ef5c47

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

labours.py

+28-4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ def parse_args():
7070
"\"month\", \"year\", \"no\", \"raw\" and pandas offset aliases ("
7171
"http://pandas.pydata.org/pandas-docs/stable/timeseries.html"
7272
"#offset-aliases).")
73+
dateutil_url = "https://dateutil.readthedocs.io/en/stable/parser.html#dateutil.parser.parse"
74+
parser.add_argument("--start-date",
75+
help="Start date of time-based plots. Any format is accepted which is "
76+
"supported by %s" % dateutil_url)
77+
parser.add_argument("--end-date",
78+
help="End date of time-based plots. Any format is accepted which is "
79+
"supported by %s" % dateutil_url)
7380
parser.add_argument("--disable-projector", action="store_true",
7481
help="Do not run Tensorflow Projector on couples.")
7582
parser.add_argument("--max-people", default=20, type=int,
@@ -385,7 +392,15 @@ def read_input(args):
385392
sys.stdout.flush()
386393
if args.input != "-":
387394
if args.input_format == "auto":
388-
args.input_format = args.input.rsplit(".", 1)[1]
395+
try:
396+
args.input_format = args.input.rsplit(".", 1)[1]
397+
except IndexError:
398+
try:
399+
with open(args.input) as f:
400+
f.read(1 << 16)
401+
args.input_format = "yaml"
402+
except UnicodeDecodeError:
403+
args.input_format = "pb"
389404
elif args.input_format == "auto":
390405
args.input_format = "yaml"
391406
reader = READERS[args.input_format]()
@@ -745,6 +760,13 @@ def default_json(x):
745760
return x
746761

747762

763+
def parse_date(text, default):
764+
if not text:
765+
return default
766+
from dateutil.parser import parse
767+
return parse(text)
768+
769+
748770
def plot_burndown(args, target, name, matrix, date_range_sampling, labels, granularity,
749771
sampling, resample):
750772
if args.output and args.output.endswith(".json"):
@@ -776,7 +798,8 @@ def plot_burndown(args, target, name, matrix, date_range_sampling, labels, granu
776798
pyplot.xlabel("Time")
777799
apply_plot_style(pyplot.gcf(), pyplot.gca(), legend, args.background,
778800
args.font_size, args.size)
779-
pyplot.xlim(date_range_sampling[0], date_range_sampling[-1])
801+
pyplot.xlim(parse_date(args.start_date, date_range_sampling[0]),
802+
parse_date(args.end_date, date_range_sampling[-1]))
780803
locator = pyplot.gca().xaxis.get_major_locator()
781804
# set the optimal xticks locator
782805
if "M" not in resample:
@@ -898,7 +921,8 @@ def plot_ownership(args, repo, names, people, date_range, last):
898921
matplotlib, pyplot = import_pyplot(args.backend, args.style)
899922

900923
pyplot.stackplot(date_range, people, labels=names)
901-
pyplot.xlim(date_range[0], last)
924+
pyplot.xlim(parse_date(args.start_date, date_range[0]), parse_date(args.end_date, last))
925+
902926
if args.relative:
903927
for i in range(people.shape[1]):
904928
people[:, i] /= people[:, i].sum()
@@ -1165,7 +1189,7 @@ def show_sentiment_stats(args, name, resample, start_date, data):
11651189
pyplot.xlabel("Time")
11661190
apply_plot_style(pyplot.gcf(), pyplot.gca(), legend, args.background,
11671191
args.font_size, args.size)
1168-
pyplot.xlim(xdates[0], xdates[-1])
1192+
pyplot.xlim(parse_date(args.start_date, xdates[0]), parse_date(args.end_date, xdates[-1]))
11691193
locator = pyplot.gca().xaxis.get_major_locator()
11701194
# set the optimal xticks locator
11711195
if "M" not in resample:

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ munch>=2.0
99
hdbscan==0.8.18
1010
ortools==6.9.5824
1111
fastdtw==0.3.2
12+
python-dateutil==2.8.0

0 commit comments

Comments
 (0)