feat(csv-import): Enhance Apple sleep CSV import functionality
- Integrated date parsing improvements using dateutil for better handling of various date formats in sleep data. - Added total sleep hours to the nights dictionary for comprehensive sleep analysis. - Updated the import logic to handle cases where sleep duration is zero, providing appropriate warnings. - Enhanced the CSV import interface to detect Apple sleep CSV format and provide user feedback on template selection. - Improved the admin CSV template editor to accommodate new sleep import requirements and clarify usage instructions.
This commit is contained in:
1 parent
26ab11eb7b
commit
41cc0ed2a8
6 files changed
+223
-54
No files matched your search
@@ -84,13 +84,14 @@ export default function AdminCsvTemplateEditorPage() {
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
const modMeta = useMemo(() => modules.find((m) => m.id === module), [modules, module])
|
||||
const aggregateSleepImport = modMeta?.import_mode === 'apple_sleep_aggregate'
|
||||
const targetOptions = useMemo(() => {
|
||||
if (!modMeta?.fields) return []
|
||||
if (!modMeta?.fields || aggregateSleepImport) return []
|
||||
return Object.entries(modMeta.fields).map(([key, meta]) => ({
|
||||
value: key,
|
||||
label: `${key}${meta.required ? ' *' : ''}`,
|
||||
}))
|
||||
}, [modMeta])
|
||||
}, [modMeta, aggregateSleepImport])
|
||||
|
||||
const requiredTargets = useMemo(() => {
|
||||
if (!modMeta?.fields) return []
|
||||
@@ -302,7 +303,27 @@ export default function AdminCsvTemplateEditorPage() {
|
||||
</select>
|
||||
{!isNew && (
|
||||
<p style={{ fontSize: 13, color: 'var(--text3)', marginTop: 8 }}>
|
||||
Modul bestehender Vorlagen kann nicht geändert werden.
|
||||
Modul bestehender Vorlagen kann nicht geändert werden. System-Vorlagen können hier bearbeitet und
|
||||
gespeichert werden (Signatur, Trennzeichen, Zuordnungen).
|
||||
</p>
|
||||
)}
|
||||
{aggregateSleepImport && (
|
||||
<p
|
||||
style={{
|
||||
fontSize: 13,
|
||||
color: 'var(--text2)',
|
||||
marginTop: 12,
|
||||
lineHeight: 1.55,
|
||||
padding: 12,
|
||||
background: 'var(--surface2)',
|
||||
borderRadius: 12,
|
||||
}}
|
||||
>
|
||||
<strong>Schlaf (Apple-Aggregat):</strong> Die Zeilen werden nicht über Spalten-Ziele importiert,
|
||||
sondern vom Apple-Schlaf-Parser ausgewertet (Schlafanalyse oder Segment-Export). Alle CSV-Spalten
|
||||
bleiben auf „ignorieren“. Wichtig sind die{' '}
|
||||
<strong>gespeicherte Spalten-Signatur</strong> und das passende Datei-Format — damit die Datei
|
||||
in der Nutzer-Auswahl erkannt wird.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
@@ -430,12 +451,39 @@ export default function AdminCsvTemplateEditorPage() {
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<label className="form-label" style={{ marginTop: 16, display: 'block' }}>
|
||||
Spalten-Signatur (Vorlagen-Matching — eine Original-Überschrift pro Zeile, manuell anpassbar)
|
||||
</label>
|
||||
<textarea
|
||||
className="form-input"
|
||||
style={{
|
||||
width: '100%',
|
||||
minHeight: 100,
|
||||
marginTop: 8,
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 12,
|
||||
textAlign: 'left',
|
||||
}}
|
||||
value={columnSignature.join('\n')}
|
||||
onChange={(e) =>
|
||||
setColumnSignature(
|
||||
e.target.value
|
||||
.split('\n')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean),
|
||||
)
|
||||
}
|
||||
placeholder={'Date/Time\nStart\nEnd\nTotal Sleep (hr)\n…'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="card" style={{ padding: 16, marginBottom: 16 }}>
|
||||
<div className="form-label">3. Spalten → Zielfelder (* = Pflicht)</div>
|
||||
{!columns.length ? (
|
||||
<p style={{ fontSize: 14, color: 'var(--text2)', marginTop: 8 }}>Nach CSV-Analyse erscheinen die Zeilen hier.</p>
|
||||
<p style={{ fontSize: 14, color: 'var(--text2)', marginTop: 8 }}>
|
||||
Nach CSV-Analyse erscheinen die Zeilen hier. Bei Schlaf-Vorlagen ohne Analyse: Signatur oben pflegen,
|
||||
speichern, oder Beispiel-CSV analysieren.
|
||||
</p>
|
||||
) : (
|
||||
<div style={{ marginTop: 12, display: 'flex', flexDirection: 'column', gap: 10 }}>
|
||||
{columns.map((col) => (
|
||||
@@ -455,6 +503,7 @@ export default function AdminCsvTemplateEditorPage() {
|
||||
className="form-input"
|
||||
value={fieldMappings[col] || '-'}
|
||||
onChange={(e) => updateMapping(col, e.target.value)}
|
||||
disabled={aggregateSleepImport}
|
||||
style={{
|
||||
width: '100%',
|
||||
minHeight: 46,
|
||||
|
||||
Reference in new issue
Block a user