1
0

Renamed WorkSample to ActivitySample

This commit is contained in:
Jon Michael Aanes 2024-10-13 15:05:55 +02:00
parent f47daa3256
commit eb3518ba88
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
6 changed files with 26 additions and 26 deletions

View File

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

View File

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

View File

@ -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] = {}

View File

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

View File

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

View File

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