1
0

Sample filter cmdline argument implemented
All checks were successful
Test Python / Test (push) Successful in 20s

This commit is contained in:
Jon Michael Aanes 2024-06-08 15:17:04 +02:00
parent c1b95997d9
commit 6c9f6b157d
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -12,12 +12,6 @@ import git
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('repositories', action='extend', nargs='+', type=Path)
return parser.parse_args()
@dataclasses.dataclass(frozen=True, order=True) @dataclasses.dataclass(frozen=True, order=True)
class WorkSample: class WorkSample:
registered_at: datetime.datetime registered_at: datetime.datetime
@ -95,10 +89,9 @@ def fmt_year_ranges(years: list[int]) -> str:
def fmt_line(label_type: str, label: str, total_time: datetime.timedelta) -> str: def fmt_line(label_type: str, label: str, total_time: datetime.timedelta) -> str:
hours = int(total_time / HOUR) hours = int(total_time / HOUR)
minutes = int((total_time - hours*HOUR)/MINUTE) minutes = int((total_time - hours*HOUR)/MINUTE)
return f' {label_type:8} {label:40} {hours:-4d}h {minutes:-2d}m' return f' {label_type:10} {label:40} {hours:-4d}h {minutes:-2d}m'
def generate_report(samples: list[WorkSample]) -> Iterator[str]: def generate_report(samples: list[WorkSample], sample_filter = frozenset()) -> Iterator[str]:
SAMPLE_FILTER = {}
LABEL_FILTER = {} LABEL_FILTER = {}
# Time spent per label # Time spent per label
@ -109,9 +102,9 @@ def generate_report(samples: list[WorkSample]) -> Iterator[str]:
est_time: datetime.timedelta = DEFAULT_EST_TIME est_time: datetime.timedelta = DEFAULT_EST_TIME
est_time = min(sample.registered_at - prev_time, est_time) est_time = min(sample.registered_at - prev_time, est_time)
if len(SAMPLE_FILTER) == 0: if len(sample_filter) == 0:
pass pass
elif not set(sample.labels).intersection(SAMPLE_FILTER): elif not set(sample.labels).intersection(sample_filter):
continue continue
for label in sample.labels: for label in sample.labels:
@ -137,8 +130,6 @@ def generate_report(samples: list[WorkSample]) -> Iterator[str]:
if len(LABEL_FILTER) > 0 and label_type not in LABEL_FILTER: if len(LABEL_FILTER) > 0 and label_type not in LABEL_FILTER:
continue continue
label_type = '' # TODO
yield fmt_line(label_type, label, total_time) yield fmt_line(label_type, label, total_time)
yield ' (' yield ' ('
yield fmt_year_ranges(years_per_label.get(label_and_type,[])) yield fmt_year_ranges(years_per_label.get(label_and_type,[]))
@ -152,6 +143,14 @@ def generate_report(samples: list[WorkSample]) -> Iterator[str]:
yield fmt_line('', 'TOTAL', time_per_label.get(HIDDEN_LABEL_TOTAL, ZERO_DURATION)) yield fmt_line('', 'TOTAL', time_per_label.get(HIDDEN_LABEL_TOTAL, ZERO_DURATION))
yield '\n' yield '\n'
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('repositories', action='extend', nargs='+', type=Path)
parser.add_argument('--filter', action='extend', nargs='+', type=str, dest='sample_filter', default=[])
return parser.parse_args()
def main(): def main():
logging.basicConfig() logging.basicConfig()
@ -169,5 +168,5 @@ def main():
shared_time_stamps = sorted(shared_time_stamps) shared_time_stamps = sorted(shared_time_stamps)
for t in generate_report(shared_time_stamps): for t in generate_report(shared_time_stamps, sample_filter=args.sample_filter):
sys.stdout.write(t) sys.stdout.write(t)