From cb3320e176bf03bc38fc6c34b622cee0bfbbd75c Mon Sep 17 00:00:00 2001 From: Asher Pembroke Date: Tue, 6 Apr 2021 00:20:10 -0500 Subject: [PATCH] added division of labor for multiple repo names --- MultiRepo.md | 1 + hourly/cli/main.py | 36 +++++++++++++++++++++++++++++++----- hourly/hourly.py | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/MultiRepo.md b/MultiRepo.md index 34639d3..ce0a4ce 100644 --- a/MultiRepo.md +++ b/MultiRepo.md @@ -1,3 +1,4 @@ +* added division of labor for multiple repo names ### 2021-04-05 22:00:06.101441: clock-in diff --git a/hourly/cli/main.py b/hourly/cli/main.py index b255642..f9d9f58 100644 --- a/hourly/cli/main.py +++ b/hourly/cli/main.py @@ -7,7 +7,7 @@ from hourly import invoice import plotly.graph_objs as go import plotly.offline as po -from omegaconf import OmegaConf, DictConfig +from omegaconf import OmegaConf, DictConfig, ListConfig import hydra from os import path import os @@ -195,6 +195,22 @@ def get_avg_time(cfg, labor, total_hours): return avg_time, tmin, tmax +def divide_labor(labor): + """divides labor among multiple repo names""" + rows = [] + for _, row in labor.iterrows(): + if isinstance(row.repo, tuple): + # divide evenly among the tags + tag_count = len(row.repo) + row_tag = row + for repo_name in row.repo: + row_tag.repo = repo_name + row_tag.TimeDelta = row.TimeDelta/tag_count + row_tag.Hours = row.Hours/tag_count + rows.append(pd.DataFrame(row_tag).T) + else: + rows.append(pd.DataFrame(row).T) + return pd.concat(rows) def run_report(cfg): if cfg.verbosity > 1: @@ -283,7 +299,12 @@ def run_report(cfg): - clocks = clocks.assign(repo = repo_conf.name) + # clocks = clocks.assign(repo = repo_conf.name) + # allow repo name to be a list + if isinstance(repo_conf.name, ListConfig): + clocks = clocks.assign(repo = [tuple(repo_conf.name)]*len(clocks)) + else: + clocks = clocks.assign(repo=repo_conf.name) clocks.sort_index(inplace=True) clocks = clocks.loc[start_date:].loc[:end_date] @@ -334,6 +355,8 @@ def run_report(cfg): print('unique branches', labor.branch.unique()) + labor = divide_labor(labor) + for labor_id, labor_ in labor.groupby(report_grouping): hours_worked = get_hours_worked(labor_) dt = labor_.TimeDelta.sum() @@ -362,12 +385,17 @@ def run_report(cfg): if cfg.vis.normalize: norm = cfg.vis.normalize/avg_time # norm > 1 if avg_time < normalization + if cfg.verbosity: + print('normalization factor: {}'.format(norm)) else: norm = 1 for labor_id, labor_ in labor.groupby(report_grouping): if type(labor_id) == tuple: - plot_label = "
".join(labor_id) + try: + plot_label = "
".join(labor_id) + except: + raise NameError('something wrong with {}'.format(labor_id)) else: plot_label = labor_id @@ -379,8 +407,6 @@ def run_report(cfg): plot_traces.append(labor_trace) - - plot_title = "total hours commited: {0:.2f}".format(total_hours*norm) plot_traces = [plot_traces[i] for i in np.argsort(hours)[::-1]] fig = go.Figure(plot_traces) diff --git a/hourly/hourly.py b/hourly/hourly.py index b9f1358..042ffe6 100644 --- a/hourly/hourly.py +++ b/hourly/hourly.py @@ -216,7 +216,7 @@ def plot_labor(labor, freq, name = None, norm = 1): tdelta_trace = go.Scatter( x = pd.Series(tdelta.index), - y = [norm*td.total_seconds()/3600 for td in tdelta], + y = [norm*td.total_seconds()/3600. for td in tdelta], mode='lines', stackgroup = 'one', text = [str(td) for td in tdelta],