feat: Refactor activity data handling and improve CSV import logic
- Updated `ACTIVITY_PRODUCTION_ARCHITECTURE_AND_PHASES.md` to clarify the derivation of `ACTIVITY_MODULE_REGISTRY_FIELD_KEYS` from `csv_parser.module_registry`. - Enhanced `activity_data_canon.py` to eliminate hardcoded key lists, ensuring all registry fields are derived dynamically. - Refactored the `_import_activity` function to remove redundant parameters and streamline the import process. - Improved the `insert_activity_csv_minimal` function to handle metrics exclusively through `update_activity_columns`, preventing hardcoded values. - Updated frontend components to manage editable activity log fields more effectively, ensuring proper handling of metrics during CSV imports. - Added unit tests to validate the new logic and ensure consistency in activity session metrics handling.
This commit is contained in:
1 parent
cd29c7d433
commit
5cda485458
9 files changed
+191
-135
No files matched your search
@@ -96,6 +96,16 @@ const ACTIVITY_LOG_PAYLOAD_KEYS = new Set([
|
||||
'training_subcategory',
|
||||
])
|
||||
|
||||
/** activity_log-Spalten, die im EntryForm editiert werden (nicht aus metricDraft überschreiben). */
|
||||
const ACTIVITY_ENTRY_FORM_COLUMNS = new Set([
|
||||
'duration_min',
|
||||
'kcal_active',
|
||||
'hr_avg',
|
||||
'hr_max',
|
||||
'rpe',
|
||||
'notes',
|
||||
])
|
||||
|
||||
function empty() {
|
||||
return {
|
||||
date: dayjs().format('YYYY-MM-DD'),
|
||||
@@ -113,6 +123,9 @@ function empty() {
|
||||
function buildMetricsPayload(schema, draft) {
|
||||
const out = []
|
||||
for (const s of schema) {
|
||||
if (s.source_field && ACTIVITY_LOG_PAYLOAD_KEYS.has(String(s.source_field))) {
|
||||
continue
|
||||
}
|
||||
const raw = draft[s.key]
|
||||
if (s.data_type === 'boolean') {
|
||||
if (raw === '' || raw === null || raw === undefined) {
|
||||
@@ -148,14 +161,23 @@ function SessionMetricsFields({ schema, values, setValues, metrics }) {
|
||||
const schemaList = Array.isArray(schema) ? schema : []
|
||||
const metricRows = Array.isArray(metrics) ? metrics : []
|
||||
const schemaKeys = new Set(schemaList.map((s) => s.key))
|
||||
const orphanMetrics = metricRows.filter((row) => row && row.key && !schemaKeys.has(row.key))
|
||||
const isHeadColumnMetric = (s) =>
|
||||
s && s.source_field && ACTIVITY_LOG_PAYLOAD_KEYS.has(String(s.source_field))
|
||||
const schemaForProfileOnly = schemaList.filter((s) => !isHeadColumnMetric(s))
|
||||
const orphanMetrics = metricRows.filter(
|
||||
(row) =>
|
||||
row &&
|
||||
row.key &&
|
||||
!schemaKeys.has(row.key) &&
|
||||
!ACTIVITY_LOG_PAYLOAD_KEYS.has(row.key)
|
||||
)
|
||||
|
||||
if (schemaList.length === 0 && orphanMetrics.length === 0) return null
|
||||
if (schemaForProfileOnly.length === 0 && orphanMetrics.length === 0) return null
|
||||
const set = (k, v) => setValues((prev) => ({ ...prev, [k]: v }))
|
||||
return (
|
||||
<div style={{ marginTop: 12, paddingTop: 12, borderTop: '1px solid var(--border)' }}>
|
||||
<div style={{ fontSize: 13, fontWeight: 600, marginBottom: 8 }}>Weitere Kennwerte (Profil)</div>
|
||||
{schemaList.map((s) => (
|
||||
{schemaForProfileOnly.map((s) => (
|
||||
<div key={s.key} className="form-row">
|
||||
<label className="form-label">
|
||||
{s.name_de}
|
||||
@@ -588,8 +610,9 @@ export default function ActivityPage() {
|
||||
for (const s of sessionDetail?.schema || []) {
|
||||
const col = s.source_field
|
||||
if (!col || !ACTIVITY_LOG_PAYLOAD_KEYS.has(col)) continue
|
||||
if (!(s.key in metricDraft)) continue
|
||||
const raw = metricDraft[s.key]
|
||||
const useFormColumn = ACTIVITY_ENTRY_FORM_COLUMNS.has(col)
|
||||
if (!useFormColumn && !(s.key in metricDraft)) continue
|
||||
const raw = useFormColumn ? editing[col] : metricDraft[s.key]
|
||||
const rawStr = raw === null || raw === undefined ? '' : String(raw).trim()
|
||||
if (rawStr === '') {
|
||||
payload[col] = null
|
||||
|
||||
Reference in new issue
Block a user