120 lines
3.1 KiB
Dart
120 lines
3.1 KiB
Dart
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
|
|
class FireDetectionModel {
|
|
final String id;
|
|
final String userId;
|
|
final DateTime timestamp;
|
|
final String location;
|
|
final double confidence;
|
|
final String imageUrl;
|
|
final String status;
|
|
final String severity;
|
|
final String description;
|
|
final bool resolved;
|
|
final DateTime createdAt;
|
|
|
|
FireDetectionModel({
|
|
required this.id,
|
|
required this.userId,
|
|
required this.timestamp,
|
|
required this.location,
|
|
required this.confidence,
|
|
required this.imageUrl,
|
|
required this.status,
|
|
required this.severity,
|
|
required this.description,
|
|
required this.resolved,
|
|
required this.createdAt,
|
|
});
|
|
|
|
factory FireDetectionModel.fromFirestore(DocumentSnapshot doc) {
|
|
Map<String, dynamic> data = doc.data() as Map<String, dynamic>;
|
|
return FireDetectionModel(
|
|
id: doc.id,
|
|
userId: data['userId'] ?? '',
|
|
timestamp: data['timestamp']?.toDate() ?? DateTime.now(),
|
|
location: data['location'] ?? '',
|
|
confidence: (data['confidence'] ?? 0.0).toDouble(),
|
|
imageUrl: data['imageUrl'] ?? '',
|
|
status: data['status'] ?? 'detected',
|
|
severity: data['severity'] ?? 'medium',
|
|
description: data['description'] ?? '',
|
|
resolved: data['resolved'] ?? false,
|
|
createdAt: data['createdAt']?.toDate() ?? DateTime.now(),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toFirestore() {
|
|
return {
|
|
'userId': userId,
|
|
'timestamp': Timestamp.fromDate(timestamp),
|
|
'location': location,
|
|
'confidence': confidence,
|
|
'imageUrl': imageUrl,
|
|
'status': status,
|
|
'severity': severity,
|
|
'description': description,
|
|
'resolved': resolved,
|
|
'createdAt': Timestamp.fromDate(createdAt),
|
|
};
|
|
}
|
|
|
|
FireDetectionModel copyWith({
|
|
String? id,
|
|
String? userId,
|
|
DateTime? timestamp,
|
|
String? location,
|
|
double? confidence,
|
|
String? imageUrl,
|
|
String? status,
|
|
String? severity,
|
|
String? description,
|
|
bool? resolved,
|
|
DateTime? createdAt,
|
|
}) {
|
|
return FireDetectionModel(
|
|
id: id ?? this.id,
|
|
userId: userId ?? this.userId,
|
|
timestamp: timestamp ?? this.timestamp,
|
|
location: location ?? this.location,
|
|
confidence: confidence ?? this.confidence,
|
|
imageUrl: imageUrl ?? this.imageUrl,
|
|
status: status ?? this.status,
|
|
severity: severity ?? this.severity,
|
|
description: description ?? this.description,
|
|
resolved: resolved ?? this.resolved,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
);
|
|
}
|
|
|
|
String get severityText {
|
|
switch (severity) {
|
|
case 'low':
|
|
return 'Rendah';
|
|
case 'medium':
|
|
return 'Sedang';
|
|
case 'high':
|
|
return 'Tinggi';
|
|
case 'critical':
|
|
return 'Kritis';
|
|
default:
|
|
return 'Tidak diketahui';
|
|
}
|
|
}
|
|
|
|
String get statusText {
|
|
switch (status) {
|
|
case 'detected':
|
|
return 'Terdeteksi';
|
|
case 'confirmed':
|
|
return 'Dikonfirmasi';
|
|
case 'false_alarm':
|
|
return 'Alarm Palsu';
|
|
case 'resolved':
|
|
return 'Diselesaikan';
|
|
default:
|
|
return 'Tidak diketahui';
|
|
}
|
|
}
|
|
}
|