1
0

Compare commits

..

No commits in common. "9656b884e0c7f6af4dc56df8aab27ceb9ed77f96" and "7ab46bc48edc905d35c17c3960733e931d87123f" have entirely different histories.

5 changed files with 26 additions and 37 deletions

View File

@ -32,12 +32,7 @@ import sys
from collections.abc import Iterator from collections.abc import Iterator
from pathlib import Path from pathlib import Path
from .data import ( from .data import HIDDEN_LABEL_PREFIX, HIDDEN_LABEL_TOTAL, WorkSample, RealizedWorkSample
HIDDEN_LABEL_PREFIX,
HIDDEN_LABEL_TOTAL,
RealizedWorkSample,
WorkSample,
)
from .format import cli, icalendar from .format import cli, icalendar
from .source import git_repo from .source import git_repo
@ -50,16 +45,11 @@ HOUR = datetime.timedelta(hours=1)
MINUTE = datetime.timedelta(minutes=1) MINUTE = datetime.timedelta(minutes=1)
def filter_samples( def filter_samples(samples: list[WorkSample], sample_filter: set[str]) -> list[WorkSample]:
samples: list[WorkSample], sample_filter: set[str],
) -> list[WorkSample]:
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(samples: list[WorkSample]) -> Iterator[RealizedWorkSample]:
def heuristically_realize_samples(
samples: list[WorkSample],
) -> Iterator[RealizedWorkSample]:
"""Secret sauce. """Secret sauce.
Guarentees that: Guarentees that:
@ -85,7 +75,6 @@ def heuristically_realize_samples(
previous_sample_end = sample.end_at previous_sample_end = sample.end_at
del sample del sample
def parse_arguments(): def parse_arguments():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
@ -126,7 +115,7 @@ def main():
git_repo.iterate_samples_from_git_repository(repo_path), git_repo.iterate_samples_from_git_repository(repo_path),
) )
shared_time_stamps = sorted(shared_time_stamps_set, key=lambda s: s.end_at) shared_time_stamps = sorted(shared_time_stamps_set, key = lambda s: s.end_at)
del shared_time_stamps_set del shared_time_stamps_set
sample_filter = args.sample_filter sample_filter = args.sample_filter
@ -142,6 +131,4 @@ def main():
for t in cli.generate_report(shared_time_stamps): for t in cli.generate_report(shared_time_stamps):
sys.stdout.write(t) sys.stdout.write(t)
elif args.format_mode == 'icalendar': elif args.format_mode == 'icalendar':
icalendar.generate_icalendar_file( icalendar.generate_icalendar_file(shared_time_stamps, file='./output/samples.ics')
shared_time_stamps, file='./output/samples.ics',
)

View File

@ -1 +1 @@
__version__ = '0.1.16' __version__ = '0.1.15'

View File

@ -12,7 +12,6 @@ class WorkSample:
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 RealizedWorkSample(WorkSample):
start_at: datetime.datetime start_at: datetime.datetime

View File

@ -1,8 +1,15 @@
import datetime import datetime
from collections.abc import Iterator
import argparse
import datetime
import urllib.parse
import icalendar import icalendar
from ..data import HIDDEN_LABEL_PREFIX, RealizedWorkSample from personal_data.util import load_csv_file
from ..data import HIDDEN_LABEL_PREFIX, HIDDEN_LABEL_TOTAL, RealizedWorkSample
ZERO_DURATION = datetime.timedelta(seconds=0) ZERO_DURATION = datetime.timedelta(seconds=0)
HOUR = datetime.timedelta(hours=1) HOUR = datetime.timedelta(hours=1)
@ -22,7 +29,7 @@ def create_title(sample: RealizedWorkSample) -> str:
def generate_calendar( def generate_calendar(
samples: list[RealizedWorkSample], samples: list[RealizedWorkSample],
) -> icalendar.Calendar: ) -> icalendar.Calendar:
max_title_parts = 2 max_title_parts = 2
cal = icalendar.Calendar() cal = icalendar.Calendar()
@ -30,6 +37,7 @@ def generate_calendar(
cal.add('version', '2.0') cal.add('version', '2.0')
for sample in samples: for sample in samples:
title = create_title(sample) title = create_title(sample)
description = '' description = ''
@ -44,9 +52,7 @@ def generate_calendar(
for label_and_type in sample.labels: for label_and_type in sample.labels:
if label_and_type.startswith('author:'): if label_and_type.startswith('author:'):
event.add( event.add('organizer', 'mailto:'+label_and_type.removeprefix('author:'))
'organizer', 'mailto:' + label_and_type.removeprefix('author:'),
)
cal.add_component(event) cal.add_component(event)
del event del event
@ -58,6 +64,7 @@ def generate_icalendar_file(
samples: list[RealizedWorkSample], samples: list[RealizedWorkSample],
file: str, file: str,
) -> None: ) -> None:
calendar = generate_calendar(samples) calendar = generate_calendar(samples)
with open(file, 'wb') as f: with open(file, 'wb') as f:

View File

@ -38,23 +38,19 @@ def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]:
labels.append('project:' + project_name) labels.append('project:' + project_name)
labels.append('author:' + commit.author.email) labels.append('author:' + commit.author.email)
authored_date = datetime.datetime.fromtimestamp( authored_date = datetime.datetime.fromtimestamp(commit.authored_date, tz=datetime.UTC)
commit.authored_date, tz=datetime.UTC, committed_date = datetime.datetime.fromtimestamp(commit.committed_date, tz=datetime.UTC)
)
committed_date = datetime.datetime.fromtimestamp(
commit.committed_date, tz=datetime.UTC,
)
yield WorkSample( yield WorkSample(
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 WorkSample(
labels=tuple(labels), labels = tuple(labels),
start_at=None, start_at = None,
end_at=committed_date, end_at = committed_date,
) )
del labels del labels