WT 1.1.18+4 A/B Test sales page
This commit is contained in:
@@ -3,17 +3,14 @@ import 'dart:collection';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/model/customer_property.dart';
|
||||
import 'package:aitrainer_app/model/product_test.dart';
|
||||
import 'package:aitrainer_app/model/property.dart';
|
||||
import 'package:aitrainer_app/model/purchase.dart';
|
||||
import 'package:aitrainer_app/model/sport.dart';
|
||||
import 'package:aitrainer_app/repository/property_repository.dart';
|
||||
import 'package:aitrainer_app/service/customer_service.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/service/product_test_service.dart';
|
||||
import 'package:aitrainer_app/service/purchase_service.dart';
|
||||
import 'package:aitrainer_app/util/enums.dart';
|
||||
import 'package:aitrainer_app/util/not_found_exception.dart';
|
||||
|
||||
class GenderItem {
|
||||
GenderItem(this.dbValue, this.name);
|
||||
@@ -354,25 +351,6 @@ class CustomerRepository with Logging {
|
||||
await PurchaseApi().savePurchase(purchase);
|
||||
}
|
||||
|
||||
Future<List<ProductTest>> getProductTests() async {
|
||||
List<ProductTest> tests = [];
|
||||
try {
|
||||
int customerId = Cache().userLoggedIn!.customerId!;
|
||||
tests = await ProductTestApi().getProductTestByCustomer(customerId);
|
||||
} on NotFoundException catch (_) {
|
||||
log("Product Tests not found");
|
||||
Cache().productTests = tests;
|
||||
} on Exception catch (ex) {
|
||||
log(ex.toString());
|
||||
Cache().productTests = tests;
|
||||
}
|
||||
return tests;
|
||||
}
|
||||
|
||||
Future<void> addProductTest(ProductTest productTest) async {
|
||||
await ProductTestApi().saveProductTest(productTest);
|
||||
}
|
||||
|
||||
void setMediaDimensions(double width, double height) {
|
||||
this.mediaHeight = height;
|
||||
this.mediaWidth = width;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/description.dart';
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DescriptionRepository {
|
||||
List<Description>? descriptions;
|
||||
@@ -12,9 +15,12 @@ class DescriptionRepository {
|
||||
String descriptionText = "";
|
||||
if (descriptions != null) {
|
||||
this.descriptions!.forEach((element) {
|
||||
print("Desc ${element.name} - $name");
|
||||
if (element.name == name) {
|
||||
descriptionText = element.descriptionTranslation != null ? element.descriptionTranslation! : element.description;
|
||||
if (AppLanguage().appLocal == Locale('en')) {
|
||||
descriptionText = element.description;
|
||||
} else {
|
||||
descriptionText = element.descriptionTranslation != null ? element.descriptionTranslation! : element.description;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/repository/description_repository.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:firebase_remote_config/firebase_remote_config.dart';
|
||||
|
||||
class SplitTestRepository with Logging {
|
||||
final RemoteConfig? _remoteConfig = Cache().remoteConfig;
|
||||
final DescriptionRepository descriptionRepository = DescriptionRepository();
|
||||
|
||||
String getSplitTestValue(String remoteConfigKey) {
|
||||
String testValue = "";
|
||||
|
||||
if (_remoteConfig != null) {
|
||||
_remoteConfig!.fetchAndActivate();
|
||||
Map configs = _remoteConfig!.getAll();
|
||||
RemoteConfigValue? value = configs[remoteConfigKey];
|
||||
if (value != null) {
|
||||
log("A/B Test RemoteConfig $remoteConfigKey value: ${value.asString()}");
|
||||
final String remoteConfigValue = value.asString();
|
||||
testValue = this.getSplitTestValueByRemoteConfig(remoteConfigKey, remoteConfigValue);
|
||||
} else {
|
||||
log("RemoteConfig value $remoteConfigKey is null!!");
|
||||
}
|
||||
} else {
|
||||
log(" !! remoteConfig isnull");
|
||||
}
|
||||
|
||||
return testValue;
|
||||
}
|
||||
|
||||
String getSource(String remoteConfigKey) {
|
||||
String source = "";
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
String getSplitTestValueByRemoteConfig(String key, String value) {
|
||||
String testValue = "";
|
||||
if (Cache().getSplitTests().isEmpty) {
|
||||
log("Splittests empty");
|
||||
return testValue;
|
||||
}
|
||||
|
||||
Cache().getSplitTests().forEach((element) {
|
||||
if (element.remoteConfigKey == key && element.remoteConfigValue == value && element.active) {
|
||||
testValue = element.testValue;
|
||||
log("A/B Test testValue: $testValue");
|
||||
|
||||
if (element.source != null && element.source!.isNotEmpty) {
|
||||
final List<String> sourceElements = element.source!.split(".");
|
||||
if (sourceElements.length > 1) {
|
||||
final String modelName = sourceElements[0];
|
||||
if (modelName == "description") {
|
||||
testValue = descriptionRepository.getDescriptionByName(element.testValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return testValue;
|
||||
}
|
||||
}
|
||||
@@ -65,8 +65,11 @@ class TrainingPlanRepository {
|
||||
}
|
||||
|
||||
// 3 calculate weights
|
||||
int index = 0;
|
||||
trainingPlan.details!.forEach((elem) {
|
||||
CustomerTrainingPlanDetails detail = CustomerTrainingPlanDetails();
|
||||
detail.customerTrainingPlanDetailsId = ++index;
|
||||
detail.trainingPlanDetailsId = elem.trainingPlanDetailId;
|
||||
detail.exerciseTypeId = elem.exerciseTypeId;
|
||||
detail.repeats = elem.repeats;
|
||||
detail.set = elem.set;
|
||||
@@ -111,6 +114,7 @@ class TrainingPlanRepository {
|
||||
double weight = -1;
|
||||
if (Cache().getExercises() == null) {
|
||||
detail.weight = weight;
|
||||
detail.isTest = true;
|
||||
return detail;
|
||||
}
|
||||
|
||||
@@ -124,6 +128,7 @@ class TrainingPlanRepository {
|
||||
|
||||
if (lastExercise1RM == null || lastExercise1RM!.unitQuantity == null) {
|
||||
detail.weight = weight;
|
||||
detail.isTest = true;
|
||||
return detail;
|
||||
}
|
||||
|
||||
@@ -138,4 +143,34 @@ class TrainingPlanRepository {
|
||||
detail.weight = weight;
|
||||
return detail;
|
||||
}
|
||||
|
||||
CustomerTrainingPlanDetails recalculateDetail(int trainingPlanId, CustomerTrainingPlanDetails detail) {
|
||||
CustomerTrainingPlanDetails recalculatedDetail = detail;
|
||||
|
||||
// 1. get original repeats
|
||||
|
||||
// 1a get original plan
|
||||
TrainingPlan? plan = getTrainingPlanById(trainingPlanId);
|
||||
if (plan == null) {
|
||||
return recalculatedDetail;
|
||||
}
|
||||
|
||||
// 1.b get the original detail's repeat
|
||||
int originalRepeats = detail.repeats!;
|
||||
plan.details!.forEach((element) {
|
||||
if (element.trainingPlanDetailId == detail.trainingPlanDetailsId) {
|
||||
print("element $element");
|
||||
originalRepeats = element.repeats;
|
||||
}
|
||||
});
|
||||
|
||||
// 2 get recalculated repeats
|
||||
|
||||
recalculatedDetail.weight =
|
||||
Common.calculateWeigthByChangedQuantity(detail.weight!, detail.repeats!.toDouble(), originalRepeats.toDouble());
|
||||
print("recalculated repeats for $originalRepeats: ${recalculatedDetail.weight}");
|
||||
recalculatedDetail.repeats = originalRepeats;
|
||||
|
||||
return recalculatedDetail;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user