This commit is contained in:
parent
cdbfd6623c
commit
11888b4208
|
@ -1,5 +1,6 @@
|
||||||
import argparse
|
import argparse
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
|
from decimal import Decimal
|
||||||
import datetime
|
import datetime
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -17,6 +18,9 @@ def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]:
|
||||||
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 = [
|
||||||
|
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 = [
|
||||||
k for k, v in event_data.items() if isinstance(v, urllib.parse.ParseResult)
|
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:
|
if date is None:
|
||||||
continue
|
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])
|
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:])
|
||||||
|
|
||||||
|
@ -46,8 +59,8 @@ def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]:
|
||||||
# Create event
|
# Create event
|
||||||
yield WorkSample(
|
yield WorkSample(
|
||||||
labels=tuple(labels),
|
labels=tuple(labels),
|
||||||
start_at=None,
|
start_at=start_at,
|
||||||
end_at=date,
|
end_at=end_at,
|
||||||
)
|
)
|
||||||
|
|
||||||
del event_data
|
del event_data
|
||||||
|
|
Reference in New Issue
Block a user