[ObsidianImport]: Import wanikani achievements
This commit is contained in:
parent
6ef5cfff2d
commit
e5b29f5a01
|
@ -187,13 +187,15 @@ class EventContent:
|
||||||
comment: str
|
comment: str
|
||||||
|
|
||||||
|
|
||||||
def import_activity_sample_csv(
|
def import_activity_samples(
|
||||||
vault: ObsidianVault,
|
vault: ObsidianVault,
|
||||||
rows: Rows,
|
raw_samples: list[ActivitySample],
|
||||||
content_mapper,
|
content_mapper,
|
||||||
group_category: str | None = None,
|
group_category: str | None = None,
|
||||||
|
default_estimated_duration: datetime.timedelta | None = None,
|
||||||
) -> int:
|
) -> int:
|
||||||
samples = heuristically_realize_samples(list(iterate_samples_from_rows(rows)))
|
samples = heuristically_realize_samples(raw_samples,
|
||||||
|
default_estimated_duration=default_estimated_duration)
|
||||||
|
|
||||||
if group_category is not None:
|
if group_category is not None:
|
||||||
samples = merge_adjacent_samples(list(samples), group_category)
|
samples = merge_adjacent_samples(list(samples), group_category)
|
||||||
|
@ -208,7 +210,6 @@ def import_activity_sample_csv(
|
||||||
samples_per_date.setdefault(date, [])
|
samples_per_date.setdefault(date, [])
|
||||||
samples_per_date[date].append(sample)
|
samples_per_date[date].append(sample)
|
||||||
del date, sample
|
del date, sample
|
||||||
del rows
|
|
||||||
|
|
||||||
def map_to_event(sample: RealizedActivitySample) -> Event:
|
def map_to_event(sample: RealizedActivitySample) -> Event:
|
||||||
content = content_mapper(sample)
|
content = content_mapper(sample)
|
||||||
|
@ -232,6 +233,15 @@ def import_activity_sample_csv(
|
||||||
|
|
||||||
return num_updated
|
return num_updated
|
||||||
|
|
||||||
|
def import_activity_sample_csv(
|
||||||
|
vault: ObsidianVault,
|
||||||
|
rows: Rows,
|
||||||
|
content_mapper,
|
||||||
|
group_category: str | None = None,
|
||||||
|
) -> int:
|
||||||
|
raw_samples = list(iterate_samples_from_rows(rows))
|
||||||
|
return import_activity_samples(vault, raw_samples, content_mapper, group_category)
|
||||||
|
|
||||||
|
|
||||||
def map_watched_series_content(sample: RealizedActivitySample) -> EventContent:
|
def map_watched_series_content(sample: RealizedActivitySample) -> EventContent:
|
||||||
subject = sample.single_label_with_category('series.name')
|
subject = sample.single_label_with_category('series.name')
|
||||||
|
@ -257,8 +267,31 @@ def map_games_played_content(sample: RealizedActivitySample) -> EventContent:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def import_wanikani_events(vault: ObsidianVault, rows: Rows):
|
||||||
|
keys = ['unlocked_at', 'started_at', 'passed_at', 'burned_at']
|
||||||
|
raw_samples = []
|
||||||
|
for row in rows:
|
||||||
|
for k in keys:
|
||||||
|
if k in row:
|
||||||
|
raw_samples.append(ActivitySample([Label('application.name', 'WaniKani')], None, row[k]))
|
||||||
|
del k
|
||||||
|
del row
|
||||||
|
|
||||||
|
def mapper(sample: RealizedActivitySample) -> EventContent:
|
||||||
|
subject = sample.single_label_with_category('application.name')
|
||||||
|
return EventContent(
|
||||||
|
verb='Practiced',
|
||||||
|
subject=subject,
|
||||||
|
comment='',
|
||||||
|
)
|
||||||
|
|
||||||
|
return import_activity_samples(vault, raw_samples, mapper,
|
||||||
|
group_category='application.name',
|
||||||
|
default_estimated_duration=datetime.timedelta(minutes=5))
|
||||||
|
|
||||||
PATH_WATCHED = Path('output/show_episodes_watched.csv')
|
PATH_WATCHED = Path('output/show_episodes_watched.csv')
|
||||||
PATH_PLAYED = Path('output/games_played.csv')
|
PATH_PLAYED = Path('output/games_played.csv')
|
||||||
|
PATH_WANIKANI = Path('output/wanikani_lessons.csv')
|
||||||
PATH_WORKOUT = Path('/home/jmaa/Notes/workout.csv')
|
PATH_WORKOUT = Path('/home/jmaa/Notes/workout.csv')
|
||||||
PATH_STEP_COUNTS = Path(
|
PATH_STEP_COUNTS = Path(
|
||||||
'/home/jmaa/Notes/Rawbackupdata/Steps/exportStepCount_2025-03-15_22-58-20',
|
'/home/jmaa/Notes/Rawbackupdata/Steps/exportStepCount_2025-03-15_22-58-20',
|
||||||
|
@ -267,6 +300,7 @@ PATH_STEPMANIA = Path('output/stepmania.csv')
|
||||||
|
|
||||||
|
|
||||||
IMPORTERS = [
|
IMPORTERS = [
|
||||||
|
{'path': PATH_WANIKANI, 'standard_variant': True, 'import_rows': import_wanikani_events},
|
||||||
{'path': PATH_WORKOUT, 'standard_variant': True, 'import_rows': import_workout_csv},
|
{'path': PATH_WORKOUT, 'standard_variant': True, 'import_rows': import_workout_csv},
|
||||||
{'path': PATH_STEP_COUNTS, 'import_rows': import_step_counts_csv},
|
{'path': PATH_STEP_COUNTS, 'import_rows': import_step_counts_csv},
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,6 +47,7 @@ class RealizedActivitySample(ActivitySample):
|
||||||
|
|
||||||
def heuristically_realize_samples(
|
def heuristically_realize_samples(
|
||||||
samples: list[ActivitySample],
|
samples: list[ActivitySample],
|
||||||
|
default_estimated_duration: datetime.timedelta = DEFAULT_ESTIMATED_DURATION,
|
||||||
) -> Iterator[RealizedActivitySample]:
|
) -> Iterator[RealizedActivitySample]:
|
||||||
"""Secret sauce.
|
"""Secret sauce.
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ def heuristically_realize_samples(
|
||||||
|
|
||||||
start_at = sample.start_at
|
start_at = sample.start_at
|
||||||
if start_at is None:
|
if start_at is None:
|
||||||
estimated_duration: datetime.timedelta = DEFAULT_ESTIMATED_DURATION
|
estimated_duration: datetime.timedelta = default_estimated_duration
|
||||||
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user