Skip to content

Commit

Permalink
[stats] record routing
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Sep 26, 2024
1 parent 1daf14b commit 0bc4947
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:mimir/agreements/entity/agreements.dart';
import 'package:mimir/agreements/page/privacy_policy.dart';
import 'package:mimir/backend/stats/utils/stats.dart';
import 'package:mimir/credentials/init.dart';
import 'package:mimir/files.dart';
import 'package:mimir/intent/file_type/handle.dart';
Expand Down Expand Up @@ -97,8 +98,7 @@ class _MimirAppState extends ConsumerState<MimirApp> {

void onRouteChanged() {
final info = router.routeInformationProvider.value;
final route = info.uri;
print(info.uri);
Stats.onRoute(info.uri);
}

@override
Expand Down
15 changes: 15 additions & 0 deletions lib/backend/stats/init.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'service/stats.dart';
import 'storage/stats.dart';

class StatsInit {
static late final StatsStorage storage;
static late final StatsService service;

static void init() {
service = StatsService();
}

static void initStorage() {
storage = StatsStorage();
}
}
1 change: 1 addition & 0 deletions lib/backend/stats/service/stats.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class StatsService {}
10 changes: 10 additions & 0 deletions lib/backend/stats/storage/stats.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:objectbox/objectbox.dart';
import 'package:mimir/storage/objectbox/init.dart';

import '../entity/feature.dart';
import '../entity/route.dart';

class StatsStorage {
late final Box<StatsFeatureUsage> feature = ObjectBoxInit.store.box<StatsFeatureUsage>();
late final Box<StatsRoute> route = ObjectBoxInit.store.box<StatsRoute>();
}
35 changes: 35 additions & 0 deletions lib/backend/stats/utils/stats.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/foundation.dart';
import 'package:mimir/backend/stats/entity/route.dart';

import '../entity/feature.dart';
import '../init.dart';

class Stats {
static String? lastRoute;

static void onRoute(Uri uri) {
final route = uri.toString();
if (route == lastRoute) {
return;
}
lastRoute = route;
final time = DateTime.now();
final row = StatsRoute(
route: route.toString(),
time: time,
);
final id = StatsInit.storage.route.put(row);
debugPrint('[${time.toString()}] On route #$id: "$route"');
}

static void onFeature(String feature, [String? result]) {
final time = DateTime.now();
final row = StatsFeatureUsage(
feature: feature,
result: result ?? "",
time: time,
);
final id = StatsInit.storage.feature.put(row);
debugPrint('[${time.toString()}] On feature #$id: "$feature"');
}
}
3 changes: 3 additions & 0 deletions lib/init.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:mimir/backend/init.dart';
import 'package:mimir/backend/network/ua.dart';
import 'package:mimir/backend/stats/init.dart';
import 'package:mimir/credentials/entity/credential.dart';
import 'package:mimir/credentials/entity/login_status.dart';
import 'package:mimir/credentials/entity/user_type.dart';
Expand Down Expand Up @@ -129,6 +130,7 @@ class Init {
YwbInit.init();
Class2ndInit.init();
ElectricityBalanceInit.init();
StatsInit.init();
}
YellowPagesInit.init();
EduEmailInit.init();
Expand All @@ -149,6 +151,7 @@ class Init {
YwbInit.initStorage();
Class2ndInit.initStorage();
ElectricityBalanceInit.initStorage();
StatsInit.initStorage();
}
YellowPagesInit.initStorage();
EduEmailInit.initStorage();
Expand Down
13 changes: 6 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:mimir/storage/objectbox/init.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:mimir/files.dart';
import 'package:mimir/network/proxy.dart';
Expand Down Expand Up @@ -102,13 +103,11 @@ void main() async {
// iOS will clear the cache under [getApplicationCacheDirectory()] when device has no enough storage.
cacheDir: Files.internal.subDir("hive-cache", R.hiveStorageVersionCache),
);
// if (kDebugMode) {
// final objectBoxDir = Files.internal.subDir("obx", R.objectBoxStorageVersion);
// await objectBoxDir.create(recursive: true);
// await ObjectBoxInit.init(
// dir: objectBoxDir,
// );
// }
final objectBoxDir = Files.internal.subDir("obx", R.objectBoxStorageVersion);
await objectBoxDir.create(recursive: true);
await ObjectBoxInit.init(
dir: objectBoxDir,
);
}
HiveInit.initAdapters();
await HiveInit.initBox();
Expand Down
2 changes: 1 addition & 1 deletion lib/r.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class R {
static const scheme = "sitlife";
static const hiveStorageVersionCache = "2.3.0";
static const hiveStorageVersionCore = "2.1.1";
static const objectBoxStorageVersion = "2.6.0";
static const objectBoxStorageVersion = "2.7.0";
static const appId = "life.mysit.SITLife";
static const appName = "SIT Life";
static const icpLicense = "沪ICP备2024077945号-6A";
Expand Down

0 comments on commit 0bc4947

Please sign in to comment.