Stepmania import
This commit is contained in:
parent
2e41125952
commit
c576687122
|
@ -27,6 +27,26 @@ logger = getLogger(__name__)
|
|||
Row = dict[str, Any]
|
||||
Rows = list[Row]
|
||||
|
||||
HOUR = datetime.timedelta(hours=1)
|
||||
MINUTE = datetime.timedelta(minutes=1)
|
||||
SECOND = datetime.timedelta(seconds=1)
|
||||
|
||||
def to_text_duration(duration: datetime.timedelta) -> str:
|
||||
hours = int(duration / HOUR)
|
||||
duration -= hours * HOUR
|
||||
minutes = int(duration / MINUTE)
|
||||
duration -= minutes * MINUTE
|
||||
seconds = int(duration / SECOND)
|
||||
|
||||
l = []
|
||||
if hours > 0:
|
||||
l.append(f'{hours} hours')
|
||||
if minutes > 0:
|
||||
l.append(f'{minutes} minutes')
|
||||
if seconds > 0:
|
||||
l.append(f'{seconds} seconds')
|
||||
return ' '.join(l)
|
||||
|
||||
|
||||
def iterate_samples_from_rows(rows: Rows) -> Iterator[ActivitySample]:
|
||||
assert len(rows) > 0
|
||||
|
@ -109,6 +129,40 @@ def import_step_counts_csv(vault: ObsidianVault, rows: Rows) -> int:
|
|||
|
||||
return num_updated
|
||||
|
||||
def import_stepmania_steps_csv(vault: ObsidianVault, rows: Rows) -> int:
|
||||
num_updated = 0
|
||||
|
||||
rows_per_date = {}
|
||||
for row in rows:
|
||||
date = row['play.start'].date()
|
||||
rows_per_date.setdefault(date, [])
|
||||
rows_per_date[date].append(row)
|
||||
del date, row
|
||||
|
||||
COLUMNS = ['score.w1', 'score.w2', 'score.w3', 'score.w4', 'score.w5']
|
||||
|
||||
def all_steps(row: dict[str,int]):
|
||||
return sum(row[column] for column in COLUMNS)
|
||||
|
||||
steps_per_date = {
|
||||
date: sum(all_steps(row) for row in rows) for date, rows in rows_per_date.items()
|
||||
}
|
||||
|
||||
duration_per_date = {
|
||||
date: sum((row['play.duration'] for row in rows), start=datetime.timedelta()) for date, rows in rows_per_date.items()
|
||||
}
|
||||
print(steps_per_date)
|
||||
print(duration_per_date)
|
||||
|
||||
for date in steps_per_date:
|
||||
was_updated_1 = vault.add_statistic(date, 'Stepmania (Steps)', int(steps_per_date[date]))
|
||||
was_updated_2 = vault.add_statistic(date, 'Stepmania (Duration)', to_text_duration(duration_per_date[date]))
|
||||
if was_updated_1 or was_updated_2:
|
||||
num_updated += 1
|
||||
del date, was_updated_1, was_updated_2
|
||||
|
||||
return num_updated
|
||||
|
||||
|
||||
def escape_for_obsidian_link(link: str) -> str:
|
||||
return link.replace(':', ' ').replace('/', ' ').replace(' ', ' ')
|
||||
|
@ -197,11 +251,13 @@ PATH_WORKOUT = Path('/home/jmaa/Notes/workout.csv')
|
|||
PATH_STEP_COUNTS = Path(
|
||||
'/home/jmaa/personal-archive/misc-data/step_counts_2023-07-26_to_2024-09-21.csv',
|
||||
)
|
||||
PATH_STEPMANIA = Path('output/stepmania.csv')
|
||||
|
||||
|
||||
IMPORTERS = [
|
||||
{'path': PATH_WORKOUT, 'import_rows': import_workout_csv},
|
||||
{'path': PATH_STEP_COUNTS, 'import_rows': import_step_counts_csv},
|
||||
{'path': PATH_STEPMANIA, 'import_rows': import_stepmania_steps_csv},
|
||||
{'path': PATH_PLAYED, 'import_rows': lambda vault, rows: import_activity_sample_csv(vault, rows, map_games_played_content, group_category='game.name',) },
|
||||
{'path': PATH_WATCHED, 'import_rows': lambda vault, rows: import_activity_sample_csv(vault, rows, map_watched_series_content) },
|
||||
]
|
||||
|
|
|
@ -324,7 +324,7 @@ def parse_event_string(
|
|||
start_time = datetime.time.fromisoformat(m.group(1))
|
||||
end_time = datetime.time.fromisoformat(m.group(2)) if m.group(2) else start_time
|
||||
else:
|
||||
logger.info('Could not parse format: %s', event_str)
|
||||
logger.debug('Could not parse format: %s', event_str)
|
||||
return Event(None, None, None, None, event_str)
|
||||
|
||||
start = datetime.datetime.combine(date, start_time, timezone).astimezone(
|
||||
|
|
Loading…
Reference in New Issue
Block a user