diff --git a/git_time_tracker/__init__.py b/git_time_tracker/__init__.py index 6c11b13..b3532f6 100644 --- a/git_time_tracker/__init__.py +++ b/git_time_tracker/__init__.py @@ -35,8 +35,8 @@ from pathlib import Path from .data import ( HIDDEN_LABEL_PREFIX, HIDDEN_LABEL_TOTAL, - RealizedWorkSample, - WorkSample, + RealizedActivitySample, + ActivitySample, ) from .format import cli, icalendar from .source import csv_file, git_repo @@ -51,16 +51,16 @@ MINUTE = datetime.timedelta(minutes=1) def filter_samples( - samples: list[WorkSample], + samples: list[ActivitySample], sample_filter: set[str], -) -> list[WorkSample]: +) -> list[ActivitySample]: assert len(sample_filter) > 0 return [s for s in samples if set(s.labels).intersection(sample_filter)] def heuristically_realize_samples( - samples: list[WorkSample], -) -> Iterator[RealizedWorkSample]: + samples: list[ActivitySample], +) -> Iterator[RealizedActivitySample]: """Secret sauce. Guarentees that: @@ -87,7 +87,7 @@ def heuristically_realize_samples( start_at = max(previous_sample_end, end_at - estimated_duration) del estimated_duration - yield RealizedWorkSample(labels=sample.labels, end_at=end_at, start_at=start_at) + yield RealizedActivitySample(labels=sample.labels, end_at=end_at, start_at=start_at) previous_sample_end = sample.end_at del sample @@ -137,8 +137,8 @@ def parse_arguments(): return parser.parse_args() -def load_samples(args) -> set[WorkSample]: - shared_time_stamps_set: set[WorkSample] = set() +def load_samples(args) -> set[ActivitySample]: + shared_time_stamps_set: set[ActivitySample] = set() # Git repositories for repo_path in args.repositories: diff --git a/git_time_tracker/data.py b/git_time_tracker/data.py index 1b0860a..2a152aa 100644 --- a/git_time_tracker/data.py +++ b/git_time_tracker/data.py @@ -7,13 +7,13 @@ HIDDEN_LABEL_TOTAL = HIDDEN_LABEL_PREFIX + 'TOTAL' @dataclasses.dataclass(frozen=True, order=True) -class WorkSample: +class ActivitySample: labels: Sequence[str] start_at: datetime.datetime | None end_at: datetime.datetime | None @dataclasses.dataclass(frozen=True, order=True) -class RealizedWorkSample(WorkSample): +class RealizedActivitySample(ActivitySample): start_at: datetime.datetime end_at: datetime.datetime diff --git a/git_time_tracker/format/cli.py b/git_time_tracker/format/cli.py index bab846f..d715a9d 100644 --- a/git_time_tracker/format/cli.py +++ b/git_time_tracker/format/cli.py @@ -1,7 +1,7 @@ import datetime from collections.abc import Iterator -from ..data import HIDDEN_LABEL_PREFIX, HIDDEN_LABEL_TOTAL, RealizedWorkSample +from ..data import HIDDEN_LABEL_PREFIX, HIDDEN_LABEL_TOTAL, RealizedActivitySample ZERO_DURATION = datetime.timedelta(seconds=0) HOUR = datetime.timedelta(hours=1) @@ -36,7 +36,7 @@ def fmt_line(label_type: str, label: str, total_time: datetime.timedelta) -> str def generate_report( - samples: list[RealizedWorkSample], + samples: list[RealizedActivitySample], ) -> Iterator[str]: # Time spent per label time_per_label: dict[str, datetime.timedelta] = {} diff --git a/git_time_tracker/format/icalendar.py b/git_time_tracker/format/icalendar.py index d3232b5..5c4725a 100644 --- a/git_time_tracker/format/icalendar.py +++ b/git_time_tracker/format/icalendar.py @@ -2,14 +2,14 @@ import datetime import icalendar -from ..data import HIDDEN_LABEL_PREFIX, RealizedWorkSample +from ..data import HIDDEN_LABEL_PREFIX, RealizedActivitySample ZERO_DURATION = datetime.timedelta(seconds=0) HOUR = datetime.timedelta(hours=1) MINUTE = datetime.timedelta(minutes=1) -def create_title(sample: RealizedWorkSample) -> tuple[str, str]: +def create_title(sample: RealizedActivitySample) -> tuple[str, str]: ls = [] desc = [] for label_and_type in sample.labels: @@ -25,7 +25,7 @@ def create_title(sample: RealizedWorkSample) -> tuple[str, str]: def generate_calendar( - samples: list[RealizedWorkSample], + samples: list[RealizedActivitySample], ) -> icalendar.Calendar: max_title_parts = 2 @@ -58,7 +58,7 @@ def generate_calendar( def generate_icalendar_file( - samples: list[RealizedWorkSample], + samples: list[RealizedActivitySample], file: str, ) -> None: calendar = generate_calendar(samples) diff --git a/git_time_tracker/source/csv_file.py b/git_time_tracker/source/csv_file.py index 0130dc2..627cffd 100644 --- a/git_time_tracker/source/csv_file.py +++ b/git_time_tracker/source/csv_file.py @@ -8,9 +8,9 @@ import dataclasses from personal_data.csv_import import load_csv_file, start_end, determine_possible_keys -from ..data import WorkSample +from ..data import ActivitySample -def iterate_samples_from_dicts(rows: list[dict[str,Any]]) -> Iterator[WorkSample]: +def iterate_samples_from_dicts(rows: list[dict[str,Any]]) -> Iterator[ActivitySample]: assert len(rows) > 0 max_title_parts = 2 @@ -38,7 +38,7 @@ def iterate_samples_from_dicts(rows: list[dict[str,Any]]) -> Iterator[WorkSample labels = [f'{k}:{event_data[k]}' for k in possible_keys.misc] # Create event - yield WorkSample( + yield ActivitySample( labels=tuple(labels), start_at=start_at, end_at=end_at, @@ -47,7 +47,7 @@ def iterate_samples_from_dicts(rows: list[dict[str,Any]]) -> Iterator[WorkSample del event_data -def iterate_samples_from_csv_file(file_path: Path) -> Iterator[WorkSample]: +def iterate_samples_from_csv_file(file_path: Path) -> Iterator[ActivitySample]: dicts = load_csv_file(file_path) samples = list(iterate_samples_from_dicts(dicts)) assert len(samples) > 0, 'Did not found any samples' diff --git a/git_time_tracker/source/git_repo.py b/git_time_tracker/source/git_repo.py index 67839aa..a85b589 100644 --- a/git_time_tracker/source/git_repo.py +++ b/git_time_tracker/source/git_repo.py @@ -5,7 +5,7 @@ from pathlib import Path import git -from ..data import HIDDEN_LABEL_TOTAL, WorkSample +from ..data import HIDDEN_LABEL_TOTAL, ActivitySample logger = logging.getLogger(__name__) @@ -25,7 +25,7 @@ def determine_project_name(repo: git.Repo) -> str: return Path(repo.working_tree_dir).name -def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]: +def get_samples_from_project(repo: git.Repo) -> Iterator[ActivitySample]: project_name = determine_project_name(repo) assert project_name is not None @@ -47,13 +47,13 @@ def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]: tz=datetime.UTC, ) - yield WorkSample( + yield ActivitySample( labels=tuple(labels), start_at=None, end_at=authored_date, ) if authored_date != committed_date: - yield WorkSample( + yield ActivitySample( labels=tuple(labels), start_at=None, end_at=committed_date, @@ -61,7 +61,7 @@ def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]: del labels -def iterate_samples_from_git_repository(repo_path: Path) -> Iterator[WorkSample]: +def iterate_samples_from_git_repository(repo_path: Path) -> Iterator[ActivitySample]: try: yield from get_samples_from_project(git.Repo(repo_path)) except git.exc.InvalidGitRepositoryError: