Skip to content

Commit 91ca4fe

Browse files
authored
Merge pull request #280 from vmarkovtsev/master
Support variable tick sizes in burndown plots
2 parents 154f0a0 + 1be215c commit 91ca4fe

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

python/labours/labours.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def get_header(self):
169169

170170
def get_burndown_parameters(self):
171171
header = self.data["Burndown"]
172-
return header["sampling"], header["granularity"]
172+
return header["sampling"], header["granularity"], header["tick_size"]
173173

174174
def get_project_burndown(self):
175175
return self.data["hercules"]["repository"], \
@@ -300,7 +300,7 @@ def get_header(self):
300300

301301
def get_burndown_parameters(self):
302302
burndown = self.contents["Burndown"]
303-
return burndown.sampling, burndown.granularity
303+
return burndown.sampling, burndown.granularity, burndown.tick_size / 1000000000
304304

305305
def get_project_burndown(self):
306306
return self._parse_burndown_matrix(self.contents["Burndown"].project)
@@ -605,19 +605,23 @@ def import_pandas():
605605
return pandas
606606

607607

608+
def floor_datetime(dt, duration):
609+
return datetime.fromtimestamp(dt.timestamp() - dt.timestamp() % duration)
610+
611+
608612
def load_burndown(header, name, matrix, resample, report_survival=True):
609613
pandas = import_pandas()
610614

611-
start, last, sampling, granularity = header
615+
start, last, sampling, granularity, tick = header
612616
assert sampling > 0
613617
assert granularity > 0
614-
start = datetime.fromtimestamp(start)
618+
start = floor_datetime(datetime.fromtimestamp(start), tick)
615619
last = datetime.fromtimestamp(last)
616620
if report_survival:
617621
kmf = fit_kaplan_meier(matrix)
618622
if kmf is not None:
619623
print_survival_function(kmf, sampling)
620-
finish = start + timedelta(days=matrix.shape[1] * sampling)
624+
finish = start + timedelta(seconds=matrix.shape[1] * sampling * tick)
621625
if resample not in ("no", "raw"):
622626
print("resampling to %s, please wait..." % resample)
623627
# Interpolate the day x day matrix.
@@ -670,31 +674,32 @@ def load_burndown(header, name, matrix, resample, report_survival=True):
670674
labels = [dt.date() for dt in date_granularity_sampling]
671675
else:
672676
labels = [
673-
"%s - %s" % ((start + timedelta(days=i * granularity)).date(),
677+
"%s - %s" % ((start + timedelta(seconds=i * granularity * tick)).date(),
674678
(
675-
start + timedelta(days=(i + 1) * granularity)).date())
679+
start + timedelta(seconds=(i + 1) * granularity * tick)).date())
676680
for i in range(matrix.shape[0])]
677681
if len(labels) > 18:
678682
warnings.warn("Too many labels - consider resampling.")
679683
resample = "M" # fake resampling type is checked while plotting
680684
date_range_sampling = pandas.date_range(
681-
start + timedelta(days=sampling), periods=matrix.shape[1],
685+
start + timedelta(seconds=sampling * tick), periods=matrix.shape[1],
682686
freq="%dD" % sampling)
683687
return name, matrix, date_range_sampling, labels, granularity, sampling, resample
684688

685689

686690
def load_ownership(header, sequence, contents, max_people):
687691
pandas = import_pandas()
688692

689-
start, last, sampling, _ = header
693+
start, last, sampling, _, tick = header
690694
start = datetime.fromtimestamp(start)
695+
start = floor_datetime(start, tick)
691696
last = datetime.fromtimestamp(last)
692697
people = []
693698
for name in sequence:
694699
people.append(contents[name].sum(axis=1))
695700
people = numpy.array(people)
696701
date_range_sampling = pandas.date_range(
697-
start + timedelta(days=sampling), periods=people[0].shape[0],
702+
start + timedelta(seconds=sampling * tick), periods=people[0].shape[0],
698703
freq="%dD" % sampling)
699704

700705
if people.shape[0] > max_people:

python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
description="Python companion for github.com/src-d/hercules to visualize the results.",
1616
long_description=long_description,
1717
long_description_content_type="text/markdown",
18-
version="10.0.4",
18+
version="10.1.0",
1919
license="Apache-2.0",
2020
author="source{d}",
2121
author_email="[email protected]",

0 commit comments

Comments
 (0)