diff --git a/obsidian_import/__init__.py b/obsidian_import/__init__.py index 6ee0e0c..cb3a39f 100644 --- a/obsidian_import/__init__.py +++ b/obsidian_import/__init__.py @@ -187,13 +187,15 @@ class EventContent: comment: str -def import_activity_sample_csv( +def import_activity_samples( vault: ObsidianVault, - rows: Rows, + raw_samples: list[ActivitySample], content_mapper, group_category: str | None = None, + default_estimated_duration: datetime.timedelta | None = None, ) -> 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: 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[date].append(sample) del date, sample - del rows def map_to_event(sample: RealizedActivitySample) -> Event: content = content_mapper(sample) @@ -232,6 +233,15 @@ def import_activity_sample_csv( 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: 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_PLAYED = Path('output/games_played.csv') +PATH_WANIKANI = Path('output/wanikani_lessons.csv') PATH_WORKOUT = Path('/home/jmaa/Notes/workout.csv') PATH_STEP_COUNTS = Path( '/home/jmaa/Notes/Rawbackupdata/Steps/exportStepCount_2025-03-15_22-58-20', @@ -267,6 +300,7 @@ PATH_STEPMANIA = Path('output/stepmania.csv') 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_STEP_COUNTS, 'import_rows': import_step_counts_csv}, { diff --git a/personal_data/activity.py b/personal_data/activity.py index ba6d305..aed2a29 100644 --- a/personal_data/activity.py +++ b/personal_data/activity.py @@ -47,6 +47,7 @@ class RealizedActivitySample(ActivitySample): def heuristically_realize_samples( samples: list[ActivitySample], + default_estimated_duration: datetime.timedelta = DEFAULT_ESTIMATED_DURATION, ) -> Iterator[RealizedActivitySample]: """Secret sauce. @@ -72,7 +73,7 @@ def heuristically_realize_samples( start_at = sample.start_at 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) del estimated_duration