Files
AutoTime-Tracker/lib/models/daily_stats.dart
2025-11-13 15:45:28 +08:00

65 lines
1.4 KiB
Dart

import 'package:flutter/material.dart';
class DailyStats {
final int? id;
final DateTime date;
final int totalTime; // 秒
final int workTime;
final int studyTime;
final int entertainmentTime;
final int socialTime;
final int toolTime;
final int? efficiencyScore;
final int? focusScore;
final int appSwitchCount;
final DateTime createdAt;
final DateTime updatedAt;
DailyStats({
this.id,
required this.date,
required this.totalTime,
this.workTime = 0,
this.studyTime = 0,
this.entertainmentTime = 0,
this.socialTime = 0,
this.toolTime = 0,
this.efficiencyScore,
this.focusScore,
this.appSwitchCount = 0,
required this.createdAt,
required this.updatedAt,
});
Map<String, int> get categoryTime => {
'work': workTime,
'study': studyTime,
'entertainment': entertainmentTime,
'social': socialTime,
'tool': toolTime,
};
// 格式化总时长
String get formattedTotalTime {
final hours = totalTime ~/ 3600;
final minutes = (totalTime % 3600) ~/ 60;
if (hours > 0) {
return '${hours}h ${minutes}m';
}
return '${minutes}m';
}
// 获取效率评分颜色
Color get efficiencyColor {
final score = efficiencyScore ?? 0;
if (score >= 80) {
return const Color(0xFF10B981); // Green
} else if (score >= 50) {
return const Color(0xFFF59E0B); // Orange
} else {
return const Color(0xFFEF4444); // Red
}
}
}