1
0
This commit is contained in:
Jon Michael Aanes 2024-06-04 00:46:15 +02:00
parent 2db419c780
commit 3bc9848355
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
5 changed files with 34 additions and 8 deletions

View File

@ -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)

View File

@ -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)

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
GitPython

1
requirements_test.txt Normal file
View File

@ -0,0 +1 @@
pytest

4
test/test_main.py Normal file
View File

@ -0,0 +1,4 @@
import git_time_tracker
def test_report_empty():
assert list(git_time_tracker.generate_report([]))