hondavert-dev/lib/core/models/datalog_session.dart
2026-10-13 00:34:11 +00:00

63 lines
1.7 KiB
Dart

/// Metadata for a single recorded ECU datalog session.
class DatalogSession {
final int? id;
final String ecuType;
final DateTime startTime;
final DateTime? endTime;
final int frameCount;
const DatalogSession({
this.id,
required this.ecuType,
required this.startTime,
this.endTime,
this.frameCount = 0,
});
Duration get duration {
final end = endTime ?? DateTime.now();
return end.difference(startTime);
}
String get durationLabel {
final d = duration;
final m = d.inMinutes.remainder(60).toString().padLeft(2, '0');
final s = d.inSeconds.remainder(60).toString().padLeft(2, '0');
return '$m:$s';
}
DatalogSession copyWith({
int? id,
String? ecuType,
DateTime? startTime,
DateTime? endTime,
int? frameCount,
}) =>
DatalogSession(
id: id ?? this.id,
ecuType: ecuType ?? this.ecuType,
startTime: startTime ?? this.startTime,
endTime: endTime ?? this.endTime,
frameCount: frameCount ?? this.frameCount,
);
Map<String, dynamic> toMap() => {
'id': id,
'ecu_type': ecuType,
'start_time': startTime.millisecondsSinceEpoch,
'end_time': endTime?.millisecondsSinceEpoch,
'frame_count': frameCount,
};
factory DatalogSession.fromMap(Map<String, dynamic> m) => DatalogSession(
id: m['id'] as int?,
ecuType: m['ecu_type'] as String,
startTime:
DateTime.fromMillisecondsSinceEpoch(m['start_time'] as int),
endTime: m['end_time'] == null
? null
: DateTime.fromMillisecondsSinceEpoch(m['end_time'] as int),
frameCount: m['frame_count'] as int? ?? 0,
);
}