first commit
This commit is contained in:
114
lib/services/mock_data_service.dart
Normal file
114
lib/services/mock_data_service.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import '../models/daily_stats.dart';
|
||||
import '../models/app_usage.dart';
|
||||
|
||||
/// 测试数据服务 - 用于 Web 平台或开发测试
|
||||
class MockDataService {
|
||||
/// 生成今日测试统计数据
|
||||
static DailyStats generateTodayStats() {
|
||||
return DailyStats(
|
||||
date: DateTime.now(),
|
||||
totalTime: 23040, // 6小时24分钟
|
||||
workTime: 14400, // 4小时
|
||||
studyTime: 3600, // 1小时
|
||||
entertainmentTime: 3600, // 1小时
|
||||
socialTime: 1800, // 30分钟
|
||||
toolTime: 0,
|
||||
efficiencyScore: 72,
|
||||
focusScore: 65,
|
||||
appSwitchCount: 45,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
}
|
||||
|
||||
/// 生成本周测试统计数据
|
||||
static List<DailyStats> generateWeekStats() {
|
||||
final now = DateTime.now();
|
||||
final startOfWeek = now.subtract(Duration(days: now.weekday - 1));
|
||||
|
||||
return List.generate(7, (index) {
|
||||
final date = startOfWeek.add(Duration(days: index));
|
||||
final baseTime = 20000 + (index * 500); // 每天略有不同
|
||||
|
||||
return DailyStats(
|
||||
date: date,
|
||||
totalTime: baseTime,
|
||||
workTime: (baseTime * 0.6).round(), // 60% 工作时间
|
||||
studyTime: (baseTime * 0.15).round(), // 15% 学习时间
|
||||
entertainmentTime: (baseTime * 0.15).round(), // 15% 娱乐时间
|
||||
socialTime: (baseTime * 0.08).round(), // 8% 社交时间
|
||||
toolTime: (baseTime * 0.02).round(), // 2% 工具时间
|
||||
efficiencyScore: 65 + (index * 2), // 效率评分递增
|
||||
focusScore: 60 + (index * 3),
|
||||
appSwitchCount: 40 + (index * 2),
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// 生成今日 Top 应用测试数据
|
||||
static List<AppUsage> generateTopApps() {
|
||||
final now = DateTime.now();
|
||||
|
||||
return [
|
||||
AppUsage(
|
||||
packageName: 'com.google.chrome',
|
||||
appName: 'Chrome',
|
||||
startTime: now.subtract(const Duration(hours: 2, minutes: 15)),
|
||||
endTime: now,
|
||||
duration: 8100, // 2小时15分钟
|
||||
category: 'work',
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
),
|
||||
AppUsage(
|
||||
packageName: 'com.microsoft.vscode',
|
||||
appName: 'VS Code',
|
||||
startTime: now.subtract(const Duration(hours: 1, minutes: 30)),
|
||||
endTime: now,
|
||||
duration: 5400, // 1小时30分钟
|
||||
category: 'work',
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
),
|
||||
AppUsage(
|
||||
packageName: 'com.slack',
|
||||
appName: 'Slack',
|
||||
startTime: now.subtract(const Duration(hours: 1)),
|
||||
endTime: now,
|
||||
duration: 3600, // 1小时
|
||||
category: 'work',
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
),
|
||||
AppUsage(
|
||||
packageName: 'com.notion',
|
||||
appName: 'Notion',
|
||||
startTime: now.subtract(const Duration(minutes: 45)),
|
||||
endTime: now,
|
||||
duration: 2700, // 45分钟
|
||||
category: 'work',
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
),
|
||||
AppUsage(
|
||||
packageName: 'com.apple.mail',
|
||||
appName: 'Mail',
|
||||
startTime: now.subtract(const Duration(minutes: 30)),
|
||||
endTime: now,
|
||||
duration: 1800, // 30分钟
|
||||
category: 'work',
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/// 检查是否应该使用测试数据
|
||||
static bool shouldUseMockData() {
|
||||
return kIsWeb;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user