Renamed WorkSample to ActivitySample
This commit is contained in:
parent
f47daa3256
commit
eb3518ba88
|
@ -35,8 +35,8 @@ from pathlib import Path
|
||||||
from .data import (
|
from .data import (
|
||||||
HIDDEN_LABEL_PREFIX,
|
HIDDEN_LABEL_PREFIX,
|
||||||
HIDDEN_LABEL_TOTAL,
|
HIDDEN_LABEL_TOTAL,
|
||||||
RealizedWorkSample,
|
RealizedActivitySample,
|
||||||
WorkSample,
|
ActivitySample,
|
||||||
)
|
)
|
||||||
from .format import cli, icalendar
|
from .format import cli, icalendar
|
||||||
from .source import csv_file, git_repo
|
from .source import csv_file, git_repo
|
||||||
|
@ -51,16 +51,16 @@ MINUTE = datetime.timedelta(minutes=1)
|
||||||
|
|
||||||
|
|
||||||
def filter_samples(
|
def filter_samples(
|
||||||
samples: list[WorkSample],
|
samples: list[ActivitySample],
|
||||||
sample_filter: set[str],
|
sample_filter: set[str],
|
||||||
) -> list[WorkSample]:
|
) -> list[ActivitySample]:
|
||||||
assert len(sample_filter) > 0
|
assert len(sample_filter) > 0
|
||||||
return [s for s in samples if set(s.labels).intersection(sample_filter)]
|
return [s for s in samples if set(s.labels).intersection(sample_filter)]
|
||||||
|
|
||||||
|
|
||||||
def heuristically_realize_samples(
|
def heuristically_realize_samples(
|
||||||
samples: list[WorkSample],
|
samples: list[ActivitySample],
|
||||||
) -> Iterator[RealizedWorkSample]:
|
) -> Iterator[RealizedActivitySample]:
|
||||||
"""Secret sauce.
|
"""Secret sauce.
|
||||||
|
|
||||||
Guarentees that:
|
Guarentees that:
|
||||||
|
@ -87,7 +87,7 @@ def heuristically_realize_samples(
|
||||||
start_at = max(previous_sample_end, end_at - estimated_duration)
|
start_at = max(previous_sample_end, end_at - estimated_duration)
|
||||||
del 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
|
previous_sample_end = sample.end_at
|
||||||
del sample
|
del sample
|
||||||
|
@ -137,8 +137,8 @@ def parse_arguments():
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def load_samples(args) -> set[WorkSample]:
|
def load_samples(args) -> set[ActivitySample]:
|
||||||
shared_time_stamps_set: set[WorkSample] = set()
|
shared_time_stamps_set: set[ActivitySample] = set()
|
||||||
|
|
||||||
# Git repositories
|
# Git repositories
|
||||||
for repo_path in args.repositories:
|
for repo_path in args.repositories:
|
||||||
|
|
|
@ -7,13 +7,13 @@ HIDDEN_LABEL_TOTAL = HIDDEN_LABEL_PREFIX + 'TOTAL'
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True, order=True)
|
@dataclasses.dataclass(frozen=True, order=True)
|
||||||
class WorkSample:
|
class ActivitySample:
|
||||||
labels: Sequence[str]
|
labels: Sequence[str]
|
||||||
start_at: datetime.datetime | None
|
start_at: datetime.datetime | None
|
||||||
end_at: datetime.datetime | None
|
end_at: datetime.datetime | None
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True, order=True)
|
@dataclasses.dataclass(frozen=True, order=True)
|
||||||
class RealizedWorkSample(WorkSample):
|
class RealizedActivitySample(ActivitySample):
|
||||||
start_at: datetime.datetime
|
start_at: datetime.datetime
|
||||||
end_at: datetime.datetime
|
end_at: datetime.datetime
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
from collections.abc import Iterator
|
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)
|
ZERO_DURATION = datetime.timedelta(seconds=0)
|
||||||
HOUR = datetime.timedelta(hours=1)
|
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(
|
def generate_report(
|
||||||
samples: list[RealizedWorkSample],
|
samples: list[RealizedActivitySample],
|
||||||
) -> Iterator[str]:
|
) -> Iterator[str]:
|
||||||
# Time spent per label
|
# Time spent per label
|
||||||
time_per_label: dict[str, datetime.timedelta] = {}
|
time_per_label: dict[str, datetime.timedelta] = {}
|
||||||
|
|
|
@ -2,14 +2,14 @@ import datetime
|
||||||
|
|
||||||
import icalendar
|
import icalendar
|
||||||
|
|
||||||
from ..data import HIDDEN_LABEL_PREFIX, RealizedWorkSample
|
from ..data import HIDDEN_LABEL_PREFIX, RealizedActivitySample
|
||||||
|
|
||||||
ZERO_DURATION = datetime.timedelta(seconds=0)
|
ZERO_DURATION = datetime.timedelta(seconds=0)
|
||||||
HOUR = datetime.timedelta(hours=1)
|
HOUR = datetime.timedelta(hours=1)
|
||||||
MINUTE = datetime.timedelta(minutes=1)
|
MINUTE = datetime.timedelta(minutes=1)
|
||||||
|
|
||||||
|
|
||||||
def create_title(sample: RealizedWorkSample) -> tuple[str, str]:
|
def create_title(sample: RealizedActivitySample) -> tuple[str, str]:
|
||||||
ls = []
|
ls = []
|
||||||
desc = []
|
desc = []
|
||||||
for label_and_type in sample.labels:
|
for label_and_type in sample.labels:
|
||||||
|
@ -25,7 +25,7 @@ def create_title(sample: RealizedWorkSample) -> tuple[str, str]:
|
||||||
|
|
||||||
|
|
||||||
def generate_calendar(
|
def generate_calendar(
|
||||||
samples: list[RealizedWorkSample],
|
samples: list[RealizedActivitySample],
|
||||||
) -> icalendar.Calendar:
|
) -> icalendar.Calendar:
|
||||||
max_title_parts = 2
|
max_title_parts = 2
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ def generate_calendar(
|
||||||
|
|
||||||
|
|
||||||
def generate_icalendar_file(
|
def generate_icalendar_file(
|
||||||
samples: list[RealizedWorkSample],
|
samples: list[RealizedActivitySample],
|
||||||
file: str,
|
file: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
calendar = generate_calendar(samples)
|
calendar = generate_calendar(samples)
|
||||||
|
|
|
@ -8,9 +8,9 @@ import dataclasses
|
||||||
|
|
||||||
from personal_data.csv_import import load_csv_file, start_end, determine_possible_keys
|
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
|
assert len(rows) > 0
|
||||||
max_title_parts = 2
|
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]
|
labels = [f'{k}:{event_data[k]}' for k in possible_keys.misc]
|
||||||
|
|
||||||
# Create event
|
# Create event
|
||||||
yield WorkSample(
|
yield ActivitySample(
|
||||||
labels=tuple(labels),
|
labels=tuple(labels),
|
||||||
start_at=start_at,
|
start_at=start_at,
|
||||||
end_at=end_at,
|
end_at=end_at,
|
||||||
|
@ -47,7 +47,7 @@ def iterate_samples_from_dicts(rows: list[dict[str,Any]]) -> Iterator[WorkSample
|
||||||
del event_data
|
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)
|
dicts = load_csv_file(file_path)
|
||||||
samples = list(iterate_samples_from_dicts(dicts))
|
samples = list(iterate_samples_from_dicts(dicts))
|
||||||
assert len(samples) > 0, 'Did not found any samples'
|
assert len(samples) > 0, 'Did not found any samples'
|
||||||
|
|
|
@ -5,7 +5,7 @@ from pathlib import Path
|
||||||
|
|
||||||
import git
|
import git
|
||||||
|
|
||||||
from ..data import HIDDEN_LABEL_TOTAL, WorkSample
|
from ..data import HIDDEN_LABEL_TOTAL, ActivitySample
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ def determine_project_name(repo: git.Repo) -> str:
|
||||||
return Path(repo.working_tree_dir).name
|
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)
|
project_name = determine_project_name(repo)
|
||||||
assert project_name is not None
|
assert project_name is not None
|
||||||
|
|
||||||
|
@ -47,13 +47,13 @@ def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]:
|
||||||
tz=datetime.UTC,
|
tz=datetime.UTC,
|
||||||
)
|
)
|
||||||
|
|
||||||
yield WorkSample(
|
yield ActivitySample(
|
||||||
labels=tuple(labels),
|
labels=tuple(labels),
|
||||||
start_at=None,
|
start_at=None,
|
||||||
end_at=authored_date,
|
end_at=authored_date,
|
||||||
)
|
)
|
||||||
if authored_date != committed_date:
|
if authored_date != committed_date:
|
||||||
yield WorkSample(
|
yield ActivitySample(
|
||||||
labels=tuple(labels),
|
labels=tuple(labels),
|
||||||
start_at=None,
|
start_at=None,
|
||||||
end_at=committed_date,
|
end_at=committed_date,
|
||||||
|
@ -61,7 +61,7 @@ def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]:
|
||||||
del labels
|
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:
|
try:
|
||||||
yield from get_samples_from_project(git.Repo(repo_path))
|
yield from get_samples_from_project(git.Repo(repo_path))
|
||||||
except git.exc.InvalidGitRepositoryError:
|
except git.exc.InvalidGitRepositoryError:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user