Add multi-sport tracking with configurable recovery bonuses

This commit is contained in:
2026-04-11 20:12:21 +02:00
parent 3e5cdfb717
commit 2cfd59871c
16 changed files with 926 additions and 35 deletions
+26 -1
View File
@@ -62,6 +62,21 @@ final class EntryRepository
private function parse(string $content, string $fallbackDate): ?array
{
$sportTypes = [];
$sportTypesRaw = (string) ($this->extract('/^- Sportarten:\s*(.*)$/mu', $content) ?? '');
if ($sportTypesRaw !== '') {
preg_match_all('/\[([^\]]+)\]/u', $sportTypesRaw, $matches);
$sportTypes = normalize_sport_type_selection($matches[1] ?? []);
}
if ($sportTypes === []) {
$sportType = (string) ($this->extract('/^- Sportart:\s*(.*)$/mu', $content) ?? '');
if (preg_match('/\[(.+)\]\s*$/u', $sportType, $matches)) {
$sportType = trim((string) ($matches[1] ?? ''));
}
$sportTypes = normalize_sport_type_selection($sportType);
}
$entry = [
'date' => $this->extract('/^Datum:\s*(\d{4}-\d{2}-\d{2})$/m', $content) ?? $fallbackDate,
'mood' => (int) ($this->extract('/^- Stimmung:\s*(.+)$/m', $content) ?? 5),
@@ -70,6 +85,8 @@ final class EntryRepository
'sleep_hours' => (float) ($this->extract('/^- Schlafdauer:\s*(.+)$/m', $content) ?? 0),
'sleep_feeling' => (int) ($this->extract('/^- Schlaf(?:gefühl|gefuehl):\s*(.+)$/mu', $content) ?? 3),
'sport_minutes' => (int) ($this->extract('/^- Sport:\s*(.+)$/m', $content) ?? 0),
'sport_type' => $sportTypes[0] ?? '',
'sport_types' => $sportTypes,
'walk_minutes' => (int) ($this->extract('/^- Spaziergang:\s*(.+)$/m', $content) ?? 0),
'note' => $this->extractNote($content),
];
@@ -101,8 +118,14 @@ final class EntryRepository
private function toMarkdown(string $username, string $date, array $entry, array $evaluation): string
{
$sportTypes = $evaluation['sport_types'] ?? [];
$sportTypeValues = array_map(
static fn (array $type): string => (string) $type['label'] . ' [' . (string) $type['id'] . ']',
array_filter($sportTypes, 'is_array')
);
$lines = [
'<!-- mood-tracker:v1 -->',
'<!-- mood-tracker:v2 -->',
'# Stimmungstracker',
'Datum: ' . $date,
'Benutzer: ' . normalize_username($username),
@@ -114,6 +137,7 @@ final class EntryRepository
'- Schlafdauer: ' . $entry['sleep_hours'],
'- Schlafgefühl: ' . $entry['sleep_feeling'],
'- Sport: ' . $entry['sport_minutes'],
'- Sportarten: ' . implode(', ', $sportTypeValues),
'- Spaziergang: ' . $entry['walk_minutes'],
'',
'## Bewertung',
@@ -127,6 +151,7 @@ final class EntryRepository
'- Schlafdauer: ' . format_points((float) $evaluation['components']['sleep_hours']),
'- Schlafgefühl: ' . format_points((float) $evaluation['components']['sleep_feeling']),
'- Sport: ' . format_points((float) $evaluation['components']['sport_minutes']),
'- Sportbonus: ' . format_points((float) ($evaluation['components']['sport_bonus'] ?? 0)),
'- Spaziergang: ' . format_points((float) $evaluation['components']['walk_minutes']),
'- Notiz: ' . format_points((float) $evaluation['components']['note']),
'',