Skip to content

Commit

Permalink
feat: metric database (#2066)
Browse files Browse the repository at this point in the history
* fix: mixpanel add membership and source to user profile

* Remove Mixpanel

* remove unused constanst

* Update

* support update tv device id

* Update

* Update

* Update

* Ignore and sentry for metric

* Update API path

* Update deviceID

* fix lint

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
ppupha and github-actions[bot] authored Sep 13, 2024
1 parent 74d33db commit bebd311
Show file tree
Hide file tree
Showing 38 changed files with 163 additions and 1,067 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Podfile.lock
.pub-cache/
.pub/
/build/
ios/build/
node_modules/

# Web related
lib/generated_plugin_registrant.dart
Expand Down
6 changes: 2 additions & 4 deletions lib/common/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import 'package:autonomy_flutter/service/iap_service.dart';
import 'package:autonomy_flutter/service/keychain_service.dart';
import 'package:autonomy_flutter/service/merchandise_service.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/service/mix_panel_client_service.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/service/network_issue_manager.dart';
import 'package:autonomy_flutter/service/network_service.dart';
Expand Down Expand Up @@ -174,6 +173,7 @@ Future<void> setup() async {
authenticatedDio.interceptors.add(AutonomyAuthInterceptor());
authenticatedDio.interceptors.add(LoggingInterceptor());
authenticatedDio.interceptors.add(ConnectingExceptionInterceptor());
authenticatedDio.interceptors.add(MetricsInterceptor());
(authenticatedDio.transformer as SyncTransformer).jsonDecodeCallback =
parseJson;
authenticatedDio.addSentry();
Expand All @@ -188,8 +188,6 @@ Future<void> setup() async {
injector.registerLazySingleton(() => http.Client());
injector
.registerLazySingleton<MetricClientService>(() => MetricClientService());
injector.registerLazySingleton<MixPanelClientService>(
() => MixPanelClientService(injector(), injector(), injector()));
injector.registerLazySingleton<CacheManager>(() => AUImageCacheManage());
injector.registerLazySingleton<AccountService>(() => AccountServiceImpl(
cloudDB,
Expand Down Expand Up @@ -419,5 +417,5 @@ Future<void> setup() async {
() => AnnouncementServiceImpl(injector(), injector(), injector()));

injector.registerLazySingleton<UpgradesBloc>(
() => UpgradesBloc(injector(), injector()));
() => UpgradesBloc(injector(), injector(), injector()));
}
6 changes: 5 additions & 1 deletion lib/gateway/iap_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'dart:io';

import 'package:autonomy_flutter/model/announcement/announcement.dart';
import 'package:autonomy_flutter/model/announcement/announcement_request.dart';
import 'package:autonomy_flutter/model/backup_versions.dart';
import 'package:autonomy_flutter/model/jwt.dart';
import 'package:autonomy_flutter/model/ok_response.dart';
import 'package:dio/dio.dart';
Expand Down Expand Up @@ -65,4 +64,9 @@ abstract class IAPApi {
Future<OkResponse> redeemGiftCode(
@Path('id') String id,
);

@PATCH('/apis/metric-devices/{id}')
Future<void> updateMetrics(
@Path('id') String deviceId,
);
}
24 changes: 24 additions & 0 deletions lib/gateway/iap_api.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions lib/model/jwt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ enum MembershipType {
}
}

String get mixpanelName {
switch (this) {
case MembershipType.free:
return 'Free';
case MembershipType.premium:
return 'Premium';
}
}

static MembershipType fromString(String name) {
switch (name) {
case 'premium':
Expand Down Expand Up @@ -117,7 +126,18 @@ enum MembershipSource {
}
}

static MembershipSource fromString(String name) {
String get mixpanelName {
switch (this) {
case MembershipSource.purchase:
return 'Purchase';
case MembershipSource.giftCode:
return 'Gift Code';
case MembershipSource.preset:
return 'Preset';
}
}

static MembershipSource? fromString(String name) {
switch (name) {
case 'purchase':
return MembershipSource.purchase;
Expand All @@ -126,15 +146,15 @@ enum MembershipSource {
case 'preset':
return MembershipSource.preset;
default:
return MembershipSource.purchase;
return null;
}
}
}

class SubscriptionStatus {
final MembershipType membership;
final bool isTrial;
final MembershipSource source;
final MembershipSource? source;
final DateTime? expireDate;

SubscriptionStatus(
Expand Down
6 changes: 5 additions & 1 deletion lib/screen/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,11 @@ class AppRouter {
settings: settings,
builder: (context) => MultiBlocProvider(providers: [
BlocProvider(
create: (_) => UpgradesBloc(injector(), injector()),
create: (_) => UpgradesBloc(
injector(),
injector(),
injector(),
),
),
], child: const SubscriptionPage()));

Expand Down
8 changes: 1 addition & 7 deletions lib/screen/detail/artwork_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,7 @@ class _ArtworkDetailPageState extends State<ArtworkDetailPage>
currentAsset?.medium == 'other' ||
currentAsset?.medium == null;
return BlocConsumer<ArtworkDetailBloc, ArtworkDetailState>(
listenWhen: (previous, current) {
if (previous.assetToken != current.assetToken &&
current.assetToken != null) {
unawaited(current.assetToken?.sendViewArtworkEvent());
}
return true;
}, listener: (context, state) {
listener: (context, state) {
final identitiesList = state.provenances.map((e) => e.owner).toList();
if (state.assetToken?.artistName != null &&
state.assetToken!.artistName!.length > 20) {
Expand Down
13 changes: 1 addition & 12 deletions lib/screen/exhibition_details/exhibition_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import 'package:autonomy_flutter/model/pair.dart';
import 'package:autonomy_flutter/screen/detail/preview/canvas_device_bloc.dart';
import 'package:autonomy_flutter/screen/exhibition_details/exhibition_detail_bloc.dart';
import 'package:autonomy_flutter/screen/exhibition_details/exhibition_detail_state.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/exhibition_ext.dart';
import 'package:autonomy_flutter/util/log.dart';
import 'package:autonomy_flutter/util/series_ext.dart';
Expand Down Expand Up @@ -41,7 +39,6 @@ class _ExhibitionDetailPageState extends State<ExhibitionDetailPage>
with AfterLayoutMixin {
late final ExhibitionDetailBloc _exBloc;

final _metricClientService = injector<MetricClientService>();
final _canvasDeviceBloc = injector<CanvasDeviceBloc>();

late final PageController _controller;
Expand Down Expand Up @@ -280,15 +277,7 @@ class _ExhibitionDetailPageState extends State<ExhibitionDetailPage>
}

@override
FutureOr<void> afterFirstLayout(BuildContext context) {
_metricClientService.addEvent(
MixpanelEvent.viewExhibition,
data: {
MixpanelProp.exhibitionId:
widget.payload.exhibitions[widget.payload.index].id,
},
);
}
FutureOr<void> afterFirstLayout(BuildContext context) {}
}

class ExhibitionDetailPayload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import 'package:autonomy_flutter/model/ff_artwork.dart';
import 'package:autonomy_flutter/screen/app_router.dart';
import 'package:autonomy_flutter/screen/detail/preview/canvas_device_bloc.dart';
import 'package:autonomy_flutter/screen/detail/preview/keyboard_control_page.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/exhibition_ext.dart';
import 'package:autonomy_flutter/util/john_gerrard_helper.dart';
import 'package:autonomy_flutter/util/series_ext.dart';
Expand Down Expand Up @@ -51,7 +49,6 @@ class _FeralFileArtworkPreviewPageState
with
AfterLayoutMixin<FeralFileArtworkPreviewPage>,
SingleTickerProviderStateMixin {
final _metricClient = injector.get<MetricClientService>();
final _canvasDeviceBloc = injector.get<CanvasDeviceBloc>();
late bool isCrystallineWork;

Expand All @@ -70,13 +67,6 @@ class _FeralFileArtworkPreviewPageState
ScrollController? _scrollController;
late AnimationController _animationController;

void _sendViewArtworkEvent(Artwork artwork) {
final data = {
MixpanelProp.tokenId: artwork.metricTokenId,
};
_metricClient.addEvent(MixpanelEvent.viewArtwork, data: data);
}

@override
void initState() {
isCrystallineWork = widget.payload.artwork.series?.exhibitionID ==
Expand All @@ -95,7 +85,6 @@ class _FeralFileArtworkPreviewPageState
@override
void afterFirstLayout(BuildContext context) {
_appBarBottomDy ??= MediaQuery.of(context).padding.top + kToolbarHeight;
_sendViewArtworkEvent(widget.payload.artwork);
_detector = ShakeDetector.autoStart(
onPhoneShake: () async {
await _exitFullScreen();
Expand Down
47 changes: 28 additions & 19 deletions lib/screen/feralfile_home/featured_work_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,28 +282,37 @@ class FeaturedWorkViewState extends State<FeaturedWorkView> {
..add(token.artistName ?? '');
}
bloc.add(GetIdentityEvent(addresses));
await Future.wait(tokens.map((token) async {
final uri = Uri.tryParse(token.thumbnailURL ?? '');
if (uri != null) {
final response = await http.get(uri);
await Future.wait(
tokens.map(
(token) async {
try {
final uri = Uri.tryParse(token.thumbnailURL ?? '');
if (uri != null) {
final response = await http.get(uri);

if (response.statusCode == 200) {
final bytes = response.bodyBytes;
if (response.statusCode == 200) {
final bytes = response.bodyBytes;

// Decode the image
final image = await decodeImageFromList(bytes);
// Decode the image
final image = await decodeImageFromList(bytes);

// Get width and height
final width = image.width;
final height = image.height;
_imageSize.addEntries([
MapEntry(token.thumbnailURL ?? '', Size(width * 1.0, height * 1.0))
]);
} else {
log.info('Failed to load image at ${token.thumbnailURL}');
}
}
}));
// Get width and height
final width = image.width;
final height = image.height;
_imageSize.addEntries([
MapEntry(
token.thumbnailURL ?? '', Size(width * 1.0, height * 1.0))
]);
} else {
log.info('Failed to load image at ${token.thumbnailURL}');
}
}
} catch (e) {
log.info('Failed to load image at ${token.thumbnailURL}');
}
},
),
);
return tokens;
}

Expand Down
1 change: 0 additions & 1 deletion lib/screen/home/collection_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ class CollectionHomePageState extends State<CollectionHomePage>
}

void _handleBackground() {
unawaited(_metricClient.sendAndClearMetrics());
unawaited(FileLogger.shrinkLogFileIfNeeded());
}

Expand Down
Loading

0 comments on commit bebd311

Please sign in to comment.