1
0
This commit is contained in:
Jon Michael Aanes 2024-09-21 00:32:19 +02:00
parent 66ba20d629
commit 06dd687a98
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
4 changed files with 26 additions and 16 deletions

View File

@ -39,7 +39,7 @@ from .data import (
WorkSample, WorkSample,
) )
from .format import cli, icalendar from .format import cli, icalendar
from .source import git_repo, csv_file from .source import csv_file, git_repo
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -51,7 +51,8 @@ MINUTE = datetime.timedelta(minutes=1)
def filter_samples( def filter_samples(
samples: list[WorkSample], sample_filter: set[str], samples: list[WorkSample],
sample_filter: set[str],
) -> list[WorkSample]: ) -> 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)]
@ -122,6 +123,7 @@ def parse_arguments():
) )
return parser.parse_args() return parser.parse_args()
def load_samples(args): def load_samples(args):
shared_time_stamps_set: set[WorkSample] = set() shared_time_stamps_set: set[WorkSample] = set()
@ -141,9 +143,9 @@ def load_samples(args):
) )
del csv_path del csv_path
return shared_time_stamps_set return shared_time_stamps_set
def main(): def main():
logging.basicConfig() logging.basicConfig()
@ -173,5 +175,6 @@ def main():
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

@ -9,7 +9,7 @@ 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: RealizedWorkSample) -> tuple[str, str]:
ls = [] ls = []
desc = [] desc = []
for label_and_type in sample.labels: for label_and_type in sample.labels:
@ -47,7 +47,8 @@ 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)

View File

@ -1,25 +1,26 @@
import argparse
from collections.abc import Iterator
from decimal import Decimal
import datetime import datetime
import urllib.parse import urllib.parse
from collections.abc import Iterator
from decimal import Decimal
from pathlib import Path from pathlib import Path
from personal_data.util import load_csv_file from personal_data.util import load_csv_file
from ..data import WorkSample from ..data import WorkSample
def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]: def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]:
max_title_parts = 2 max_title_parts = 2
for event_data in rows: for event_data in rows:
# Select data # Select data
possible_time_keys = [ possible_time_keys = [
k for k, v in event_data.items() if isinstance(v, datetime.date) k for k, v in event_data.items() if isinstance(v, datetime.date)
] ]
possible_duration_keys = [ possible_duration_keys = [
k for k, v in event_data.items() if isinstance(v, Decimal) and 'duration_seconds' in k k
for k, v in event_data.items()
if isinstance(v, Decimal) and 'duration_seconds' in k
] ]
possible_name_keys = [k for k, v in event_data.items() if isinstance(v, str)] possible_name_keys = [k for k, v in event_data.items() if isinstance(v, str)]
possible_image_keys = [ possible_image_keys = [
@ -31,7 +32,7 @@ def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]:
if k in possible_misc_keys: if k in possible_misc_keys:
possible_misc_keys.remove(k) possible_misc_keys.remove(k)
del k del k
for k in possible_time_keys : for k in possible_time_keys:
if k in possible_misc_keys: if k in possible_misc_keys:
possible_misc_keys.remove(k) possible_misc_keys.remove(k)
del k del k
@ -45,14 +46,16 @@ def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]:
if len(possible_duration_keys) > 0: if len(possible_duration_keys) > 0:
start_at = date start_at = date
seconds = event_data[possible_duration_keys[0]] seconds = event_data[possible_duration_keys[0]]
end_at = date + datetime.timedelta(seconds = float(seconds)) end_at = date + datetime.timedelta(seconds=float(seconds))
del seconds del seconds
else: else:
start_at = None start_at = None
end_at = date end_at = date
title = ': '.join(event_data[k] for k in possible_name_keys[:max_title_parts]) title = ': '.join(event_data[k] for k in possible_name_keys[:max_title_parts])
description = '\n\n'.join(event_data[k] for k in possible_name_keys[max_title_parts:]) description = '\n\n'.join(
event_data[k] for k in possible_name_keys[max_title_parts:]
)
labels = [f'{k}:{event_data[k]}' for k in possible_misc_keys] labels = [f'{k}:{event_data[k]}' for k in possible_misc_keys]
@ -65,6 +68,7 @@ def iterate_samples_from_dicts(rows: list[dict]) -> 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[WorkSample]:
dicts = load_csv_file(file_path) dicts = load_csv_file(file_path)
yield from iterate_samples_from_dicts(dicts) yield from iterate_samples_from_dicts(dicts)

View File

@ -39,10 +39,12 @@ def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]:
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( committed_date = datetime.datetime.fromtimestamp(
commit.committed_date, tz=datetime.UTC, commit.committed_date,
tz=datetime.UTC,
) )
yield WorkSample( yield WorkSample(