palm_record.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import 'dart:convert';
  2. class PalmRecord {
  3. final int? id;
  4. final String imagePath;
  5. final String ripenessClass;
  6. final double confidence;
  7. final DateTime timestamp;
  8. final double x1;
  9. final double y1;
  10. final double x2;
  11. final double y2;
  12. final List<Map<String, dynamic>> detections;
  13. final String? batchId;
  14. final int? inferenceMs;
  15. PalmRecord({
  16. this.id,
  17. required this.imagePath,
  18. required this.ripenessClass,
  19. required this.confidence,
  20. required this.timestamp,
  21. required this.x1,
  22. required this.y1,
  23. required this.x2,
  24. required this.y2,
  25. this.detections = const [],
  26. this.batchId,
  27. this.inferenceMs,
  28. });
  29. Map<String, dynamic> toMap() {
  30. return {
  31. 'id': id,
  32. 'image_path': imagePath,
  33. 'ripeness_class': ripenessClass,
  34. 'confidence': confidence,
  35. 'timestamp': timestamp.toIso8601String(),
  36. 'x1': x1,
  37. 'y1': y1,
  38. 'x2': x2,
  39. 'y2': y2,
  40. 'detections': json.encode(detections),
  41. 'batch_id': batchId,
  42. 'inference_ms': inferenceMs,
  43. };
  44. }
  45. factory PalmRecord.fromMap(Map<String, dynamic> map) {
  46. return PalmRecord(
  47. id: map['id'],
  48. imagePath: map['image_path'],
  49. ripenessClass: map['ripeness_class'],
  50. confidence: map['confidence'],
  51. timestamp: DateTime.parse(map['timestamp']),
  52. x1: map['x1'],
  53. y1: map['y1'],
  54. x2: map['x2'],
  55. y2: map['y2'],
  56. detections: map['detections'] != null
  57. ? List<Map<String, dynamic>>.from(json.decode(map['detections']))
  58. : [],
  59. batchId: map['batch_id'],
  60. inferenceMs: map['inference_ms'],
  61. );
  62. }
  63. String toJson() => json.encode(toMap());
  64. factory PalmRecord.fromJson(String source) => PalmRecord.fromMap(json.decode(source));
  65. }