From f499c848c25de2c4adc35b295a60ec77840c7949 Mon Sep 17 00:00:00 2001 From: Liplum Date: Thu, 26 Sep 2024 12:36:45 +0800 Subject: [PATCH] [stats] recording app features --- lib/app.dart | 2 +- lib/backend/bulletin/x.dart | 3 +++ lib/backend/stats/utils/stats.dart | 4 ++-- lib/life/electricity/widget/search.dart | 3 +++ lib/life/expense_records/card.dart | 9 +++++++-- lib/life/lab_door/card.dart | 4 ++++ lib/timetable/p13n/widget/wallpaper.dart | 2 +- 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index a322bb8e0..d0df0788a 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -100,7 +100,7 @@ class _MimirAppState extends ConsumerState { void onRouteChanged() { final info = router.routeInformationProvider.value; - Stats.onRoute(info.uri); + Stats.route(info.uri); } @override diff --git a/lib/backend/bulletin/x.dart b/lib/backend/bulletin/x.dart index 681d856d2..b227c4f65 100644 --- a/lib/backend/bulletin/x.dart +++ b/lib/backend/bulletin/x.dart @@ -1,5 +1,7 @@ import 'package:mimir/backend/bulletin/entity/bulletin.dart'; import 'package:mimir/backend/init.dart'; +import 'package:mimir/backend/stats/utils/stats.dart'; +import 'package:mimir/feature/feature.dart'; class XBulletin { static Future getLatest() async { @@ -13,6 +15,7 @@ class XBulletin { static Future> getList() async { final list = await BackendInit.bulletin.getList(); + Stats.feature(AppFeature.mimirBulletin, "/list"); BackendInit.bulletinStorage.list = list; return list; } diff --git a/lib/backend/stats/utils/stats.dart b/lib/backend/stats/utils/stats.dart index 01c9d1ec4..09794e2bc 100644 --- a/lib/backend/stats/utils/stats.dart +++ b/lib/backend/stats/utils/stats.dart @@ -7,7 +7,7 @@ import '../init.dart'; class Stats { static String? lastRoute; - static void onRoute(Uri uri) { + static void route(Uri uri) { final route = uri.toString(); if (route == lastRoute) { return; @@ -22,7 +22,7 @@ class Stats { debugPrint('[${time.toString()}] On route #$id: "$route"'); } - static void onFeature(String feature, [String? result]) { + static void feature(String feature, [String? result]) { final time = DateTime.now(); final row = StatsFeatureUsage( feature: feature, diff --git a/lib/life/electricity/widget/search.dart b/lib/life/electricity/widget/search.dart index abf984c7a..b4e623bff 100644 --- a/lib/life/electricity/widget/search.dart +++ b/lib/life/electricity/widget/search.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; +import 'package:mimir/backend/stats/utils/stats.dart'; import 'package:mimir/design/adaptive/multiplatform.dart'; import 'package:mimir/design/adaptive/swipe.dart'; import 'package:mimir/design/widget/common.dart'; +import 'package:mimir/feature/feature.dart'; import 'package:mimir/life/electricity/entity/room.dart'; import 'package:mimir/widget/search.dart'; import 'package:rettulf/rettulf.dart'; @@ -15,6 +17,7 @@ Future searchRoom({ required ValueNotifier> $searchHistory, required List roomList, }) async { + Stats.feature(AppFeature.electricityBalance, "/search"); final result = await showSearch( useRootNavigator: true, context: ctx, diff --git a/lib/life/expense_records/card.dart b/lib/life/expense_records/card.dart index 0cdef04af..58f9119e1 100644 --- a/lib/life/expense_records/card.dart +++ b/lib/life/expense_records/card.dart @@ -3,9 +3,11 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; +import 'package:mimir/backend/stats/utils/stats.dart'; import 'package:mimir/credentials/init.dart'; import 'package:mimir/design/widget/app.dart'; import 'package:mimir/design/adaptive/dialog.dart'; +import 'package:mimir/feature/feature.dart'; import 'package:mimir/l10n/extension.dart'; import 'package:mimir/life/event.dart'; import 'package:mimir/settings/settings.dart'; @@ -112,8 +114,11 @@ class _ExpenseRecordsAppCardState extends ConsumerState w OutlinedButton( onPressed: () async { final success = await guardLaunchUrlString(context, _alipaySchoolCardTopUpMiniapp); - if (!context.mounted) return; - if (!success) { + if (success) { + Stats.feature(AppFeature.expenseRecords, "/top-up?launched"); + } else { + Stats.feature(AppFeature.expenseRecords, "/top-up?failed"); + if (!context.mounted) return; context.showTip( title: i18n.launchFailed, desc: i18n.launchFailedDesc, diff --git a/lib/life/lab_door/card.dart b/lib/life/lab_door/card.dart index 601dac89b..d53ea704c 100644 --- a/lib/life/lab_door/card.dart +++ b/lib/life/lab_door/card.dart @@ -3,10 +3,12 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:mimir/backend/stats/utils/stats.dart'; import 'package:mimir/design/adaptive/dialog.dart'; import 'package:mimir/design/adaptive/multiplatform.dart'; import 'package:mimir/design/widget/app.dart'; import 'package:mimir/design/widget/task_builder.dart'; +import 'package:mimir/feature/feature.dart'; import 'package:mimir/init.dart'; import 'package:rettulf/rettulf.dart'; import 'package:mimir/utils/error.dart'; @@ -45,7 +47,9 @@ class _OpenLabDoorAppCardState extends ConsumerState { await Future.delayed(const Duration(milliseconds: 2000)); if (!mounted) return; context.showSnackBar(content: "开门成功".text()); + Stats.feature(AppFeature.sitRobotOpenLabDoor, "/open?success"); } else { + Stats.feature(AppFeature.sitRobotOpenLabDoor, "/open?failed"); if (!mounted) return; context.showSnackBar(content: "开门失败".text()); } diff --git a/lib/timetable/p13n/widget/wallpaper.dart b/lib/timetable/p13n/widget/wallpaper.dart index e23e63516..ea26cb0c5 100644 --- a/lib/timetable/p13n/widget/wallpaper.dart +++ b/lib/timetable/p13n/widget/wallpaper.dart @@ -106,7 +106,7 @@ class _WallpaperImplState extends State<_WallpaperImpl> with SingleTickerProvide }, onShow: () { final now = DateTime.now(); - if (widget.fade && now.difference(lastHiddenTime ?? now).inSeconds > 15) { + if (widget.fade && now.difference(lastHiddenTime ?? now).inSeconds > 60) { final hasCache = PaintingBinding.instance.imageCache.containsKey(FileImage(File(widget.background.path))); if (!hasCache) { $opacity.value = 0;