1
0

Report works!

This commit is contained in:
Jon Michael Aanes 2024-06-04 00:02:49 +02:00
parent 002caa1874
commit 2ca01d21b3
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -18,18 +18,32 @@ class WorkSample:
labels: Sequence[str] labels: Sequence[str]
def determine_default(repo: git.Repo):
try:
repo.commit('main')
return 'main'
except:
return 'master'
HIDDEN_LABEL_PREFIX = '__'
HIDDEN_LABEL_TOTAL = HIDDEN_LABEL_PREFIX + 'TOTAL'
def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]: def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]:
labels = [] labels = [HIDDEN_LABEL_TOTAL]
labels.append('project:'+repo.remotes.origin.url) labels.append(repo.remotes.origin.url.removeprefix('git@gitfub.space:'))
# TODO: Branch on main or master or default # TODO: Branch on main or master or default
for commit in repo.iter_commits('main'):
repo.commit()
for commit in repo.iter_commits(determine_default(repo)):
yield WorkSample(datetime.datetime.fromtimestamp(commit.authored_date, tz=datetime.UTC), tuple(labels)) yield WorkSample(datetime.datetime.fromtimestamp(commit.authored_date, tz=datetime.UTC), tuple(labels))
yield WorkSample(datetime.datetime.fromtimestamp(commit.committed_date, tz=datetime.UTC), tuple(labels)) yield WorkSample(datetime.datetime.fromtimestamp(commit.committed_date, tz=datetime.UTC), tuple(labels))
DEFAULT_EST_TIME=datetime.timedelta(hours=1) DEFAULT_EST_TIME=datetime.timedelta(hours=1)
ZERO_DURATION = datetime.timedelta(seconds = 0) ZERO_DURATION = datetime.timedelta(seconds = 0)
HOUR = datetime.timedelta(hours = 1)
def generate_report(samples: list[WorkSample]) -> Iterator[str]: def generate_report(samples: list[WorkSample]) -> Iterator[str]:
@ -48,20 +62,22 @@ def generate_report(samples: list[WorkSample]) -> Iterator[str]:
del sample, est_time del sample, est_time
time_and_label = [(duration, label) for label,duration in time_per_label.items()] time_and_label = [(duration, label) for label,duration in time_per_label.items()]
time_and_label.sort() time_and_label.sort(reverse=True)
# #
yield 'Time report:\n' yield '-' * 56
for (total_time, label) in time_and_label:
yield ' '
yield label
yield ' '
yield str(total_time)
yield '\n' yield '\n'
for (total_time, label) in time_and_label:
if label.startswith(HIDDEN_LABEL_PREFIX):
continue
yield f' {label:40} {total_time / HOUR:-4.0f} hours\n'
del label, total_time del label, total_time
yield '-' * 56
yield '\n' yield '\n'
yield ' {label:40} {hours:-4.0f} hours\n'.format(label='TOTAL', hours = time_per_label[HIDDEN_LABEL_TOTAL] / HOUR)
def main(): def main():
args = parse_arguments() args = parse_arguments()