1
0

Duration support
Some checks failed
Test Python / Test (push) Failing after 24s

This commit is contained in:
Jon Michael Aanes 2024-09-08 20:29:45 +02:00
parent cdbfd6623c
commit 11888b4208
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -1,5 +1,6 @@
import argparse
from collections.abc import Iterator
from decimal import Decimal
import datetime
import urllib.parse
from pathlib import Path
@ -17,6 +18,9 @@ def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]:
possible_time_keys = [
k for k, v in event_data.items() if isinstance(v, datetime.date)
]
possible_duration_keys = [
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_image_keys = [
k for k, v in event_data.items() if isinstance(v, urllib.parse.ParseResult)
@ -38,6 +42,15 @@ def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]:
if date is None:
continue
if len(possible_duration_keys) > 0:
start_at = date
seconds = event_data[possible_duration_keys[0]]
end_at = date + datetime.timedelta(seconds = float(seconds))
del seconds
else:
start_at = None
end_at = date
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:])
@ -46,8 +59,8 @@ def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]:
# Create event
yield WorkSample(
labels=tuple(labels),
start_at=None,
end_at=date,
start_at=start_at,
end_at=end_at,
)
del event_data