feat(inventory): photo-first drafts + on-device OCR (digitization R2+R4)
Lower the bulk-digitization cliff with two more routes on top of the already-landed CSV import and "save and add another": - Photo-first drafts (capture now, catalogue later): burst-capture photos (camera or multi-gallery) into unnamed draft varieties, shown in a "to catalogue" tray, hidden from the main list until named. Adds Variety.isDraft (schema), addDraftVariety/watchDrafts/nameDraft, the triage sheet and the inventory banner. - On-device OCR label suggestion (Tesseract, offline, no Google): a "Suggest name from photo" button in the naming dialog behind a LabelTextExtractor interface (Tesseract on Android/iOS, no-op elsewhere). Reads the largest print via hOCR bounding boxes, drops boilerplate/low-confidence noise, preprocesses (grayscale, contrast, upscale) and sweeps rotations (0-315 deg) so tilted packets still read. Bundles tessdata_fast eng+spa; validated on-device against real packets. The photo is written to a temp file deleted immediately in a finally block (the plugin needs a path) - a bounded, documented exception to no-plaintext-at-rest. This commit also carries the co-developed schema evolution v5 to v8 that shares these files (organic flag, species viability years, crop calendar, lot provenance/abundance/preservation format, condition checks) plus their exports/migrations and i18n. Tests: CSV/draft/OCR unit + widget + migration green in isolation. Note: the full widget suite currently hangs (>10 min) - under investigation.
This commit is contained in:
parent
12a2ee2d64
commit
6809dc6143
89 changed files with 17141 additions and 228 deletions
100
apps/app_seeds/test/services/ocr/ocr_language_test.dart
Normal file
100
apps/app_seeds/test/services/ocr/ocr_language_test.dart
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/services/ocr/ocr_language.dart';
|
||||
|
||||
void main() {
|
||||
group('parseAvailableOcrLanguages', () {
|
||||
test('strips the .traineddata suffix', () {
|
||||
final available = parseAvailableOcrLanguages(
|
||||
'{"files": ["eng.traineddata", "spa.traineddata"]}',
|
||||
);
|
||||
expect(available, {'eng', 'spa'});
|
||||
});
|
||||
|
||||
test('empty / missing files yields empty set', () {
|
||||
expect(parseAvailableOcrLanguages('{}'), isEmpty);
|
||||
expect(parseAvailableOcrLanguages('{"files": []}'), isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
group('tesseractCodeForLocale', () {
|
||||
test('maps ISO 639-1 to Tesseract codes', () {
|
||||
expect(tesseractCodeForLocale('es'), 'spa');
|
||||
expect(tesseractCodeForLocale('en'), 'eng');
|
||||
expect(tesseractCodeForLocale('ar'), 'ara');
|
||||
expect(tesseractCodeForLocale('zh'), 'chi_sim');
|
||||
});
|
||||
|
||||
test('accepts full locale tags and is case-insensitive', () {
|
||||
expect(tesseractCodeForLocale('es_ES'), 'spa');
|
||||
expect(tesseractCodeForLocale('zh-Hans-CN'), 'chi_sim');
|
||||
expect(tesseractCodeForLocale('DE'), 'deu');
|
||||
});
|
||||
|
||||
test('unmapped locale returns null', () {
|
||||
expect(tesseractCodeForLocale('xx'), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('resolveOcrLanguages', () {
|
||||
const bundled = {'eng', 'spa'};
|
||||
|
||||
test('preferred locale comes first, baseline appended', () {
|
||||
expect(
|
||||
resolveOcrLanguages(preferredLocales: ['es'], available: bundled),
|
||||
'spa+eng',
|
||||
);
|
||||
});
|
||||
|
||||
test('English preferred is not duplicated by the baseline', () {
|
||||
expect(
|
||||
resolveOcrLanguages(preferredLocales: ['en'], available: bundled),
|
||||
'eng',
|
||||
);
|
||||
});
|
||||
|
||||
test('order follows preference, de-duplicated', () {
|
||||
expect(
|
||||
resolveOcrLanguages(
|
||||
preferredLocales: ['es', 'en', 'es'],
|
||||
available: bundled,
|
||||
),
|
||||
'spa+eng',
|
||||
);
|
||||
});
|
||||
|
||||
test('unbundled locale falls back to the Latin baseline', () {
|
||||
// German pack is not bundled here — degrade to eng, never fail.
|
||||
expect(
|
||||
resolveOcrLanguages(preferredLocales: ['de'], available: bundled),
|
||||
'eng',
|
||||
);
|
||||
});
|
||||
|
||||
test('a future RTL/CJK pack lights up automatically once bundled', () {
|
||||
expect(
|
||||
resolveOcrLanguages(
|
||||
preferredLocales: ['ar'],
|
||||
available: {'eng', 'spa', 'ara'},
|
||||
),
|
||||
'ara+eng',
|
||||
);
|
||||
});
|
||||
|
||||
test('no baseline available: falls back to every bundled pack, sorted', () {
|
||||
expect(
|
||||
resolveOcrLanguages(
|
||||
preferredLocales: ['fr'],
|
||||
available: {'spa', 'deu'},
|
||||
),
|
||||
'deu+spa',
|
||||
);
|
||||
});
|
||||
|
||||
test('empty available yields empty string', () {
|
||||
expect(
|
||||
resolveOcrLanguages(preferredLocales: ['es'], available: const {}),
|
||||
'',
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue