From 3bc98483555491abf6125d48eac765645522793d Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Tue, 4 Jun 2024 00:46:15 +0200 Subject: [PATCH] README --- README.md | 24 +++++++++++++++++++++++- git_time_tracker/__init__.py | 12 +++++------- requirements.txt | 1 + requirements_test.txt | 1 + test/test_main.py | 4 ++++ 5 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 requirements.txt create mode 100644 requirements_test.txt create mode 100644 test/test_main.py diff --git a/README.md b/README.md index e8065e8..657a1c6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,25 @@ # Git-based Time Tracker -TODO. +Quick and dirty time tracker on git histories. + +Uses the simple heuristics that each commit takes precisely one hour of work. +It will automatically trim commits below one hour if another commit occurred +less than an hour ago. + +Usage: + +``` +python -m git_time_tracker +``` + +# Obligatory + +This tool reports: + +``` +Jmaa/git-time-tracker.git 3 hours +``` + +And the ([Hamster](https://github.com/projecthamster/hamster)) manual time tracker reports: + +![](docs/obligatory-hamster.png) diff --git a/git_time_tracker/__init__.py b/git_time_tracker/__init__.py index bcd6d95..ae83fc2 100644 --- a/git_time_tracker/__init__.py +++ b/git_time_tracker/__init__.py @@ -60,9 +60,8 @@ ZERO_DURATION = datetime.timedelta(seconds = 0) HOUR = datetime.timedelta(hours = 1) def generate_report(samples: list[WorkSample]) -> Iterator[str]: - #SAMPLE_FILTER = {} - SAMPLE_FILTER = {'author:jonjmaa@gmail.com', 'author:jon.michael.aanes@secata.com'} - LABEL_FILTER = {'project'} + SAMPLE_FILTER = {} + LABEL_FILTER = {} # Time spent per label time_per_label: dict[str, datetime.timedelta] = {} @@ -95,18 +94,18 @@ def generate_report(samples: list[WorkSample]) -> Iterator[str]: label_type, label = label_and_type.split(':', 1) - if label_type not in LABEL_FILTER: + if len(LABEL_FILTER) > 0 and label_type not in LABEL_FILTER: continue label_type = '' # TODO - yield f' {label_type:8} {label:40} {total_time / HOUR:-4.0f} hours\n' + yield f' {label_type:8} {label:40} {total_time / HOUR:-4.2f} hours\n' del label, total_time yield '-' * 66 yield '\n' - yield ' {label_type:8} {label:40} {hours:-4.0f} hours\n'.format(label_type='', label='TOTAL', hours = time_per_label[HIDDEN_LABEL_TOTAL] / HOUR) + yield ' {label_type:8} {label:40} {hours:-4.0f} hours\n'.format(label_type='', label='TOTAL', hours = time_per_label.get(HIDDEN_LABEL_TOTAL, ZERO_DURATION) / HOUR) def main(): logging.basicConfig() @@ -127,4 +126,3 @@ def main(): for t in generate_report(shared_time_stamps): sys.stdout.write(t) - diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..64b1ada --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +GitPython diff --git a/requirements_test.txt b/requirements_test.txt new file mode 100644 index 0000000..e079f8a --- /dev/null +++ b/requirements_test.txt @@ -0,0 +1 @@ +pytest diff --git a/test/test_main.py b/test/test_main.py new file mode 100644 index 0000000..4f5020c --- /dev/null +++ b/test/test_main.py @@ -0,0 +1,4 @@ +import git_time_tracker + +def test_report_empty(): + assert list(git_time_tracker.generate_report([]))