Skip to content

Instantly share code, notes, and snippets.

@bendichter
Created July 7, 2022 21:02
Show Gist options
  • Save bendichter/43bb5007e91e2e543d87ba3be7877847 to your computer and use it in GitHub Desktop.
Save bendichter/43bb5007e91e2e543d87ba3be7877847 to your computer and use it in GitHub Desktop.
from itertools import chain, repeat
from bisect import bisect_left
from datetime import datetime, timedelta
import numpy as np
import matplotlib.pyplot as plt
data = [
{
"name": "Project1",
"start-stop": [datetime(2021,4,1), datetime(2026, 2, 28)],
"man-months": 4,
},
{
"name": "Project2",
"start-stop": [datetime(2022, 1, 1), datetime(2022,12,31)],
"man-months": 0.5,
},
{
"name": "Project3",
"start-stop": [datetime(2019, 8, 1), datetime(2024, 4, 30)],
"man-months": 0.5,
},
{
"name": "Proejct4",
"start-stop": [datetime(2022, 4, 15), datetime(2023, 4, 14)],
"man-months": 2.,
},
{
"name": "Project5",
"start-stop": [datetime(2021, 1, 1), datetime(2024, 12, 31)],
"man-months": 1,
},
{
"name": "Projecy6",
"start-stop": [datetime(2021, 8, 1), datetime(2023, 7, 31)],
"man-months": 0.5
},
{
"name": "Project7",
"start-stop": [datetime(2022, 1, 10), datetime(2023, 9, 30)],
"man-months": 0.58,
},
]
def plot_stacked_step(x_in, y_in, names, ax=None):
if ax is None:
fig, ax = plt.subplots(figsize=(7,3))
all_x = sorted(set(chain(*x_in)))
all_adj_y = []
for xs, ys in zip(x_in, y_in):
new_y = 0
iy = 0
adj_y = []
for x in all_x:
if x in xs:
new_y = ys[iy] if iy < len(ys) else 0
adj_y.append(new_y)
iy += 1
else:
adj_y.append(new_y)
all_adj_y.append(adj_y)
all_adj_y
stacked = np.cumsum(all_adj_y, axis=0)
for name, i_stacked in list(zip(names, stacked))[::-1]:
ax.fill(
np.repeat(all_x, 2),
np.hstack((0, np.repeat(i_stacked, 2)))[:-1],
label=name,
)
ax.set_xlabel("time")
ax.set_ylabel("man-months commited")
ax.legend(bbox_to_anchor=(1, 1))
ax.axhline(12, ls='--', color='k')
ax.axvline(datetime.now(), ls='--', color=[.5, .5, .5])
ax.set_ylim((0, 12.5))
_ = ax.set_xlim((datetime.now() - timedelta(days=150)))
def plot_jit(data):
plot_stacked_step(
[x["start-stop"] for x in data],
[[x["man-months"]] for x in data],
[x["name"] for x in data],
)
plot_jit(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment