|
|
|
@ -2,6 +2,7 @@ import 'dart:convert'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:get_storage/get_storage.dart'; |
|
|
|
import '../models/translation_usage_stats.dart'; |
|
|
|
import '../models/meeting_usage_stats.dart'; |
|
|
|
import '../../core/utils/logger.dart'; |
|
|
|
import 'network/api.dart'; |
|
|
|
import '../models/goods.dart'; |
|
|
|
@ -12,6 +13,7 @@ import '../models/user_Info.dart'; |
|
|
|
class UsageStatsService extends GetxService { |
|
|
|
static const String _storageKey = 'usage_stats'; |
|
|
|
static const String _dailyStatsKey = 'daily_translation_stats'; |
|
|
|
static const String _meetingDailyKey = 'daily_meeting_asr_stats'; |
|
|
|
|
|
|
|
final GetStorage _storage = GetStorage(); |
|
|
|
|
|
|
|
@ -67,6 +69,69 @@ class UsageStatsService extends GetxService { |
|
|
|
return 'anonymous'; |
|
|
|
} |
|
|
|
|
|
|
|
MeetingAsrDailyStats _loadMeetingDaily(String dateKey) { |
|
|
|
final data = _storage.read('${_meetingDailyKey}_$dateKey'); |
|
|
|
if (data != null) { |
|
|
|
return MeetingAsrDailyStats.fromJson(Map<String, dynamic>.from(data)); |
|
|
|
} |
|
|
|
return MeetingAsrDailyStats( |
|
|
|
date: dateKey, userId: getCurrentUserId(), items: []); |
|
|
|
} |
|
|
|
|
|
|
|
void _saveMeetingDaily(MeetingAsrDailyStats stats) { |
|
|
|
_storage.write('${_meetingDailyKey}_${stats.date}', stats.toJson()); |
|
|
|
} |
|
|
|
|
|
|
|
String _formatDate(DateTime d) { |
|
|
|
final y = d.year; |
|
|
|
final m = d.month.toString().padLeft(2, '0'); |
|
|
|
final day = d.day.toString().padLeft(2, '0'); |
|
|
|
return '$y-$m-$day'; |
|
|
|
} |
|
|
|
|
|
|
|
void addMeetingAsrRecord(MeetingAsrRecord record) { |
|
|
|
final dateKey = _formatDate( |
|
|
|
DateTime.fromMillisecondsSinceEpoch(record.submitTimestamp)); |
|
|
|
final daily = _loadMeetingDaily(dateKey); |
|
|
|
final idx = daily.items.indexWhere((e) => e.id == record.id); |
|
|
|
if (idx >= 0) { |
|
|
|
daily.items[idx] = record; |
|
|
|
} else { |
|
|
|
daily.items.add(record); |
|
|
|
} |
|
|
|
_saveMeetingDaily(daily); |
|
|
|
} |
|
|
|
|
|
|
|
void completeMeetingAsrRecord({ |
|
|
|
required String id, |
|
|
|
required int transcriptBytes, |
|
|
|
required int completeTimestamp, |
|
|
|
}) { |
|
|
|
final now = DateTime.now(); |
|
|
|
for (int i = 0; i < 3; i++) { |
|
|
|
final dateKey = _formatDate(now.subtract(Duration(days: i))); |
|
|
|
final daily = _loadMeetingDaily(dateKey); |
|
|
|
final idx = daily.items.indexWhere((e) => e.id == id); |
|
|
|
if (idx >= 0) { |
|
|
|
final old = daily.items[idx]; |
|
|
|
daily.items[idx] = MeetingAsrRecord( |
|
|
|
id: old.id, |
|
|
|
meetingId: old.meetingId, |
|
|
|
taskId: old.taskId, |
|
|
|
audioSeconds: old.audioSeconds, |
|
|
|
fileSizeBytes: old.fileSizeBytes, |
|
|
|
language: old.language, |
|
|
|
submitTimestamp: old.submitTimestamp, |
|
|
|
status: asrStatusCompleted, |
|
|
|
transcriptBytes: transcriptBytes, |
|
|
|
completeTimestamp: completeTimestamp, |
|
|
|
); |
|
|
|
_saveMeetingDaily(daily); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// 记录翻译API调用 |
|
|
|
void recordTranslationApiCall({ |
|
|
|
required String sourceText, |
|
|
|
|