upload
This commit is contained in:
@@ -570,6 +570,8 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const OCR_AUTO_SAVE_CONFIDENCE_THRESHOLD = 0.95;
|
||||||
|
|
||||||
function getOcrStatusMessage(preview) {
|
function getOcrStatusMessage(preview) {
|
||||||
const flags = Array.isArray(preview && preview.flags) ? preview.flags : [];
|
const flags = Array.isArray(preview && preview.flags) ? preview.flags : [];
|
||||||
const missingProviders = flags
|
const missingProviders = flags
|
||||||
@@ -1734,8 +1736,37 @@
|
|||||||
};
|
};
|
||||||
}, [currentSettings.crypto_currency, measurements, payload?.bootstrap_meta?.overview_window_days]);
|
}, [currentSettings.crypto_currency, measurements, payload?.bootstrap_meta?.overview_window_days]);
|
||||||
|
|
||||||
async function submitMeasurement(fromPreview) {
|
async function saveMeasurement(raw, successMessage) {
|
||||||
const preview = normalizeOcrPreview(ocrPreview);
|
setSaving(true);
|
||||||
|
setError('');
|
||||||
|
setMessage('');
|
||||||
|
try {
|
||||||
|
await request(`${apiBase}/projects/${encodeURIComponent(projectKey)}/measurements`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(raw),
|
||||||
|
});
|
||||||
|
invalidateProjectBootstrapCache(projectKey);
|
||||||
|
setMessage(successMessage);
|
||||||
|
setMeasurementForm({
|
||||||
|
measured_at: '',
|
||||||
|
coins_total: '',
|
||||||
|
price_per_coin: '',
|
||||||
|
price_currency: '',
|
||||||
|
note: '',
|
||||||
|
source: 'manual',
|
||||||
|
});
|
||||||
|
setOcrPreview(null);
|
||||||
|
await reloadBootstrapAfterMutation(successMessage);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err.message);
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitMeasurement(fromPreview, previewOverride) {
|
||||||
|
const preview = normalizeOcrPreview(previewOverride || ocrPreview);
|
||||||
const raw = fromPreview ? {
|
const raw = fromPreview ? {
|
||||||
...preview.suggested,
|
...preview.suggested,
|
||||||
coin_currency: currentMiningCurrency,
|
coin_currency: currentMiningCurrency,
|
||||||
@@ -1748,44 +1779,10 @@
|
|||||||
coin_currency: currentMiningCurrency,
|
coin_currency: currentMiningCurrency,
|
||||||
};
|
};
|
||||||
|
|
||||||
setSaving(true);
|
return saveMeasurement(raw, fromPreview ? 'OCR-Vorschlag bestaetigt und gespeichert.' : 'Messpunkt gespeichert.');
|
||||||
setError('');
|
|
||||||
setMessage('');
|
|
||||||
try {
|
|
||||||
await request(`${apiBase}/projects/${encodeURIComponent(projectKey)}/measurements`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify(raw),
|
|
||||||
});
|
|
||||||
invalidateProjectBootstrapCache(projectKey);
|
|
||||||
setMessage(fromPreview ? 'OCR-Vorschlag bestaetigt und gespeichert.' : 'Messpunkt gespeichert.');
|
|
||||||
setMeasurementForm({
|
|
||||||
measured_at: '',
|
|
||||||
coins_total: '',
|
|
||||||
price_per_coin: '',
|
|
||||||
price_currency: '',
|
|
||||||
note: '',
|
|
||||||
source: 'manual',
|
|
||||||
});
|
|
||||||
setOcrPreview(null);
|
|
||||||
await reloadBootstrapAfterMutation(fromPreview ? 'OCR-Vorschlag bestaetigt und gespeichert.' : 'Messpunkt gespeichert.');
|
|
||||||
} catch (err) {
|
|
||||||
setError(err.message);
|
|
||||||
} finally {
|
|
||||||
setSaving(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitWalletSnapshotFromPreview() {
|
async function saveWalletSnapshot(raw, successMessage) {
|
||||||
const preview = normalizeOcrPreview(ocrPreview);
|
|
||||||
const raw = {
|
|
||||||
...preview.suggested_wallet,
|
|
||||||
image_path: preview.image_path,
|
|
||||||
ocr_raw_text: preview.raw_text,
|
|
||||||
ocr_confidence: preview.confidence,
|
|
||||||
ocr_flags: preview.flags,
|
|
||||||
};
|
|
||||||
|
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setError('');
|
setError('');
|
||||||
setMessage('');
|
setMessage('');
|
||||||
@@ -1795,9 +1792,9 @@
|
|||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify(raw),
|
body: JSON.stringify(raw),
|
||||||
});
|
});
|
||||||
setMessage('Wallet-Snapshot gespeichert.');
|
setMessage(successMessage);
|
||||||
setOcrPreview(null);
|
setOcrPreview(null);
|
||||||
await reloadBootstrapAfterMutation('Wallet-Snapshot gespeichert.');
|
await reloadBootstrapAfterMutation(successMessage);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err.message);
|
setError(err.message);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -1805,6 +1802,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function submitWalletSnapshotFromPreview(previewOverride) {
|
||||||
|
const preview = normalizeOcrPreview(previewOverride || ocrPreview);
|
||||||
|
const raw = {
|
||||||
|
...preview.suggested_wallet,
|
||||||
|
image_path: preview.image_path,
|
||||||
|
ocr_raw_text: preview.raw_text,
|
||||||
|
ocr_confidence: preview.confidence,
|
||||||
|
ocr_flags: preview.flags,
|
||||||
|
};
|
||||||
|
|
||||||
|
return saveWalletSnapshot(raw, 'Wallet-Snapshot gespeichert.');
|
||||||
|
}
|
||||||
|
|
||||||
async function deleteMeasurement(id) {
|
async function deleteMeasurement(id) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return;
|
return;
|
||||||
@@ -1892,7 +1902,23 @@
|
|||||||
body,
|
body,
|
||||||
timeoutMs: 45000,
|
timeoutMs: 45000,
|
||||||
});
|
});
|
||||||
setOcrPreview(normalizeOcrPreview(data));
|
const preview = normalizeOcrPreview(data);
|
||||||
|
const isWalletPreview = preview.kind === 'wallet';
|
||||||
|
const hasMiningSuggestion = preview.suggested.coins_total !== '' && preview.suggested.coins_total !== null;
|
||||||
|
const hasWalletSuggestion = preview.suggested_wallet.wallet_balance !== '' && preview.suggested_wallet.wallet_balance !== null;
|
||||||
|
const hasUsableOcrSuggestion = isWalletPreview ? hasWalletSuggestion : hasMiningSuggestion;
|
||||||
|
|
||||||
|
setOcrPreview(preview);
|
||||||
|
|
||||||
|
if (hasUsableOcrSuggestion && preview.confidence >= OCR_AUTO_SAVE_CONFIDENCE_THRESHOLD) {
|
||||||
|
if (isWalletPreview) {
|
||||||
|
await submitWalletSnapshotFromPreview(preview);
|
||||||
|
} else {
|
||||||
|
await submitMeasurement(true, preview);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setMessage('OCR-Ergebnis geladen. Bei Bedarf direkt speichern.');
|
setMessage('OCR-Ergebnis geladen. Bei Bedarf direkt speichern.');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err.message);
|
setError(err.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user