palm_correction.dart 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import 'dart:convert';
  2. /// A harvester's ground-truth correction for a [PalmRecord]'s AI inference.
  3. /// Additive/append-only: a new correction is a new row, never an edit to
  4. /// the AI's original record or to a prior correction.
  5. class PalmCorrection {
  6. final int? id;
  7. final int originalRecordId;
  8. final String correctedClass;
  9. final List<Map<String, dynamic>> correctedDetections;
  10. final DateTime timestamp;
  11. PalmCorrection({
  12. this.id,
  13. required this.originalRecordId,
  14. required this.correctedClass,
  15. required this.correctedDetections,
  16. required this.timestamp,
  17. });
  18. Map<String, dynamic> toMap() {
  19. return {
  20. 'id': id,
  21. 'original_record_id': originalRecordId,
  22. 'corrected_class': correctedClass,
  23. 'corrected_detections': json.encode(correctedDetections),
  24. 'timestamp': timestamp.toIso8601String(),
  25. };
  26. }
  27. factory PalmCorrection.fromMap(Map<String, dynamic> map) {
  28. return PalmCorrection(
  29. id: map['id'],
  30. originalRecordId: map['original_record_id'],
  31. correctedClass: map['corrected_class'],
  32. correctedDetections: map['corrected_detections'] != null
  33. ? List<Map<String, dynamic>>.from(json.decode(map['corrected_detections']))
  34. : [],
  35. timestamp: DateTime.parse(map['timestamp']),
  36. );
  37. }
  38. String toJson() => json.encode(toMap());
  39. factory PalmCorrection.fromJson(String source) => PalmCorrection.fromMap(json.decode(source));
  40. }