|
|
@ -21,10 +21,12 @@ import com.todoroo.andlib.service.Autowired;
|
|
|
|
import com.todoroo.andlib.service.DependencyInjectionService;
|
|
|
|
import com.todoroo.andlib.service.DependencyInjectionService;
|
|
|
|
import com.todoroo.andlib.sql.Order;
|
|
|
|
import com.todoroo.andlib.sql.Order;
|
|
|
|
import com.todoroo.andlib.sql.Query;
|
|
|
|
import com.todoroo.andlib.sql.Query;
|
|
|
|
|
|
|
|
import com.todoroo.andlib.utility.Preferences;
|
|
|
|
import com.todoroo.astrid.dao.ABTestEventDao;
|
|
|
|
import com.todoroo.astrid.dao.ABTestEventDao;
|
|
|
|
import com.todoroo.astrid.data.ABTestEvent;
|
|
|
|
import com.todoroo.astrid.data.ABTestEvent;
|
|
|
|
import com.todoroo.astrid.service.StartupService;
|
|
|
|
import com.todoroo.astrid.service.StartupService;
|
|
|
|
import com.todoroo.astrid.service.StatisticsService;
|
|
|
|
import com.todoroo.astrid.service.StatisticsService;
|
|
|
|
|
|
|
|
import com.todoroo.astrid.service.TaskService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Service to manage the reporting of launch events for AB testing.
|
|
|
|
* Service to manage the reporting of launch events for AB testing.
|
|
|
@ -44,6 +46,11 @@ public final class ABTestEventReportingService {
|
|
|
|
private static final String KEY_DAYS = "days";
|
|
|
|
private static final String KEY_DAYS = "days";
|
|
|
|
private static final String KEY_DATE = "date";
|
|
|
|
private static final String KEY_DATE = "date";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String KEY_INITIAL = "initial";
|
|
|
|
|
|
|
|
private static final String KEY_ACTIVATION = "activation";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String PREF_REPORTED_ACTIVATION = "p_reported_activation";
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ABTestEventDao abTestEventDao;
|
|
|
|
private ABTestEventDao abTestEventDao;
|
|
|
|
|
|
|
|
|
|
|
@ -53,6 +60,9 @@ public final class ABTestEventReportingService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ABTests abTests;
|
|
|
|
private ABTests abTests;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private TaskService taskService;
|
|
|
|
|
|
|
|
|
|
|
|
public ABTestEventReportingService() {
|
|
|
|
public ABTestEventReportingService() {
|
|
|
|
DependencyInjectionService.getInstance().inject(this);
|
|
|
|
DependencyInjectionService.getInstance().inject(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -69,6 +79,7 @@ public final class ABTestEventReportingService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
abTestEventDao.createRelativeDateEvents();
|
|
|
|
abTestEventDao.createRelativeDateEvents();
|
|
|
|
pushAllUnreportedABTestEvents();
|
|
|
|
pushAllUnreportedABTestEvents();
|
|
|
|
|
|
|
|
reportUserActivation();
|
|
|
|
} catch (SQLiteException e) {
|
|
|
|
} catch (SQLiteException e) {
|
|
|
|
StartupService.handleSQLiteError(context, e);
|
|
|
|
StartupService.handleSQLiteError(context, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -86,7 +97,7 @@ public final class ABTestEventReportingService {
|
|
|
|
if (unreported.getCount() > 0) {
|
|
|
|
if (unreported.getCount() > 0) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
JSONArray payload = jsonArrayFromABTestEvents(unreported);
|
|
|
|
JSONArray payload = jsonArrayFromABTestEvents(unreported);
|
|
|
|
abTestInvoker.post(payload);
|
|
|
|
abTestInvoker.post(ABTestInvoker.AB_RETENTION_METHOD, payload);
|
|
|
|
ABTestEvent model = new ABTestEvent();
|
|
|
|
ABTestEvent model = new ABTestEvent();
|
|
|
|
for (unreported.moveToFirst(); !unreported.isAfterLast(); unreported.moveToNext()) {
|
|
|
|
for (unreported.moveToFirst(); !unreported.isAfterLast(); unreported.moveToNext()) {
|
|
|
|
model.readFromCursor(unreported);
|
|
|
|
model.readFromCursor(unreported);
|
|
|
@ -104,6 +115,29 @@ public final class ABTestEventReportingService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void reportUserActivation() {
|
|
|
|
|
|
|
|
synchronized (ABTestEventReportingService.class) {
|
|
|
|
|
|
|
|
if (StatisticsService.dontCollectStatistics())
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Preferences.getBoolean(PREF_REPORTED_ACTIVATION, false) || !taskService.getUserActivationStatus())
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final TodorooCursor<ABTestEvent> variants = abTestEventDao.query(Query.select(ABTestEvent.PROPERTIES)
|
|
|
|
|
|
|
|
.groupBy(ABTestEvent.TEST_NAME));
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
JSONArray payload = jsonArrayForActivationAnalytics(variants);
|
|
|
|
|
|
|
|
abTestInvoker.post(ABTestInvoker.AB_ACTIVATION_METHOD, payload);
|
|
|
|
|
|
|
|
Preferences.setBoolean(PREF_REPORTED_ACTIVATION, true);
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
|
|
|
handleException(e);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
handleException(e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
variants.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public JSONArray getTestsWithVariantsArray() {
|
|
|
|
public JSONArray getTestsWithVariantsArray() {
|
|
|
|
JSONArray array = new JSONArray();
|
|
|
|
JSONArray array = new JSONArray();
|
|
|
|
Set<String> tests = abTests.getAllTestKeys();
|
|
|
|
Set<String> tests = abTests.getAllTestKeys();
|
|
|
@ -159,4 +193,21 @@ public final class ABTestEventReportingService {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static JSONArray jsonArrayForActivationAnalytics(TodorooCursor<ABTestEvent> events) throws JSONException {
|
|
|
|
|
|
|
|
JSONArray result = new JSONArray();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ABTestEvent model = new ABTestEvent();
|
|
|
|
|
|
|
|
for (events.moveToFirst(); !events.isAfterLast(); events.moveToNext()) {
|
|
|
|
|
|
|
|
JSONObject event = new JSONObject();
|
|
|
|
|
|
|
|
event.put(KEY_TEST, model.getValue(ABTestEvent.TEST_NAME));
|
|
|
|
|
|
|
|
event.put(KEY_VARIANT, model.getValue(ABTestEvent.TEST_VARIANT));
|
|
|
|
|
|
|
|
if (model.getValue(ABTestEvent.ACTIVATED_USER) > 0)
|
|
|
|
|
|
|
|
event.put(KEY_INITIAL, true);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
event.put(KEY_ACTIVATION, true);
|
|
|
|
|
|
|
|
result.put(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|