Push unreported test data on startup

pull/14/head
Sam Bosley 14 years ago
parent 7f57679469
commit 1b2d5c2585

@ -26,7 +26,8 @@ import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.gtasks.GtasksTaskListUpdater; import com.todoroo.astrid.gtasks.GtasksTaskListUpdater;
import com.todoroo.astrid.gtasks.sync.GtasksSyncService; import com.todoroo.astrid.gtasks.sync.GtasksSyncService;
import com.todoroo.astrid.service.abtesting.ABChooser; import com.todoroo.astrid.service.abtesting.ABChooser;
import com.todoroo.astrid.service.abtesting.ABTestReporter; import com.todoroo.astrid.service.abtesting.ABTestEventReportingService;
import com.todoroo.astrid.service.abtesting.ABTestInvoker;
import com.todoroo.astrid.service.abtesting.ABTests; import com.todoroo.astrid.service.abtesting.ABTests;
import com.todoroo.astrid.service.abtesting.FeatureFlipper; import com.todoroo.astrid.service.abtesting.FeatureFlipper;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
@ -103,7 +104,8 @@ public class AstridDependencyInjector extends AbstractDependencyInjector {
injectables.put("abChooser", ABChooser.class); injectables.put("abChooser", ABChooser.class);
injectables.put("abTests", new ABTests()); injectables.put("abTests", new ABTests());
injectables.put("abTestEventDao", new ABTestEventDao()); injectables.put("abTestEventDao", new ABTestEventDao());
injectables.put("abTestReporter", ABTestReporter.class); injectables.put("abTestEventReportingService", ABTestEventReportingService.class);
injectables.put("abTestInvoker", ABTestInvoker.class);
injectables.put("featureFlipper", FeatureFlipper.class); injectables.put("featureFlipper", FeatureFlipper.class);
// com.todoroo.astrid.tags // com.todoroo.astrid.tags

@ -42,6 +42,7 @@ import com.todoroo.astrid.opencrx.OpencrxCoreUtils;
import com.todoroo.astrid.producteev.ProducteevUtilities; import com.todoroo.astrid.producteev.ProducteevUtilities;
import com.todoroo.astrid.reminders.ReminderStartupReceiver; import com.todoroo.astrid.reminders.ReminderStartupReceiver;
import com.todoroo.astrid.service.abtesting.ABChooser; import com.todoroo.astrid.service.abtesting.ABChooser;
import com.todoroo.astrid.service.abtesting.ABTestEventReportingService;
import com.todoroo.astrid.service.abtesting.FeatureFlipper; import com.todoroo.astrid.service.abtesting.FeatureFlipper;
import com.todoroo.astrid.utility.AstridPreferences; import com.todoroo.astrid.utility.AstridPreferences;
import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Constants;
@ -88,6 +89,8 @@ public class StartupService {
@Autowired ABChooser abChooser; @Autowired ABChooser abChooser;
@Autowired ABTestEventReportingService abTestEventReportingService;
/** /**
* bit to prevent multiple initializations * bit to prevent multiple initializations
*/ */
@ -212,7 +215,7 @@ public class StartupService {
} }
}).start(); }).start();
abChooser.makeChoicesForAllTests(latestSetVersion == 0, taskService.getUserActivationStatus()); initializeABTesting(latestSetVersion == 0);
AstridPreferences.setPreferenceDefaults(); AstridPreferences.setPreferenceDefaults();
trackABTestingData(); trackABTestingData();
@ -224,6 +227,12 @@ public class StartupService {
hasStartedUp = true; hasStartedUp = true;
} }
private void initializeABTesting(boolean newUser) {
abTestEventReportingService.initialize();
abTestEventReportingService.pushAllUnreportedABTestEvents();
abChooser.makeChoicesForAllTests(newUser, taskService.getUserActivationStatus());
}
private void trackABTestingData() { private void trackABTestingData() {
long firstLaunchTime = Preferences.getLong(AstridPreferences.P_FIRST_LAUNCH, 0); long firstLaunchTime = Preferences.getLong(AstridPreferences.P_FIRST_LAUNCH, 0);
long now = DateUtilities.now(); long now = DateUtilities.now();

@ -30,7 +30,7 @@ public final class ABTestEventReportingService {
private ABTestEventDao abTestEventDao; private ABTestEventDao abTestEventDao;
@Autowired @Autowired
private ABTestReporter abTestReporter; private ABTestInvoker abTestInvoker;
public ABTestEventReportingService() { public ABTestEventReportingService() {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
@ -53,7 +53,7 @@ public final class ABTestEventReportingService {
public void run() { public void run() {
try { try {
JSONArray payload = new JSONArray().put(jsonFromABTestEvent(model)); JSONArray payload = new JSONArray().put(jsonFromABTestEvent(model));
abTestReporter.post(payload); abTestInvoker.post(payload);
model.setValue(ABTestEvent.REPORTED, 1); model.setValue(ABTestEvent.REPORTED, 1);
abTestEventDao.saveExisting(model); abTestEventDao.saveExisting(model);
} catch (JSONException e) { } catch (JSONException e) {
@ -66,31 +66,34 @@ public final class ABTestEventReportingService {
} }
public void pushAllUnreportedABTestEvents() { public void pushAllUnreportedABTestEvents() {
TodorooCursor<ABTestEvent> unreported = abTestEventDao.query(Query.select(ABTestEvent.PROPERTIES) final TodorooCursor<ABTestEvent> unreported = abTestEventDao.query(Query.select(ABTestEvent.PROPERTIES)
.where(ABTestEvent.REPORTED.eq(0))); .where(ABTestEvent.REPORTED.eq(0)));
try { if (unreported.getCount() > 0) {
if (unreported.getCount() > 0) { new Thread(new Runnable() {
JSONArray payload = jsonArrayFromABTestEvents(unreported); @Override
abTestReporter.post(payload); public void run() {
for (unreported.moveToFirst(); !unreported.isAfterLast(); unreported.moveToNext()) { try {
ABTestEvent model = new ABTestEvent(unreported); JSONArray payload = jsonArrayFromABTestEvents(unreported);
model.setValue(ABTestEvent.REPORTED, 1); abTestInvoker.post(payload);
abTestEventDao.saveExisting(model); for (unreported.moveToFirst(); !unreported.isAfterLast(); unreported.moveToNext()) {
ABTestEvent model = new ABTestEvent(unreported);
model.setValue(ABTestEvent.REPORTED, 1);
abTestEventDao.saveExisting(model);
}
} catch (JSONException e) {
handleException(e);
} catch (IOException e) {
handleException(e);
} finally {
unreported.close();
}
} }
} }).start();
} catch (JSONException e) {
handleException(e);
} catch (IOException e) {
handleException(e);
} finally {
unreported.close();
} }
} }
private void handleException(Exception e) { private void handleException(Exception e) {
Log.e("analytics", "analytics-error", e); Log.e("analytics", "analytics-error", e);
// TODO: Schedule retry
} }
private static JSONObject jsonFromABTestEvent(ABTestEvent model) throws JSONException { private static JSONObject jsonFromABTestEvent(ABTestEvent model) throws JSONException {

@ -20,7 +20,7 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.RestClient; import com.todoroo.andlib.service.RestClient;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class ABTestReporter { public class ABTestInvoker {
/** NOTE: these values are development values and will not work on production */ /** NOTE: these values are development values and will not work on production */
private static final String URL = "http://analytics.astrid.com/api/1/retention"; private static final String URL = "http://analytics.astrid.com/api/1/retention";
@ -29,7 +29,7 @@ public class ABTestReporter {
@Autowired private RestClient restClient; @Autowired private RestClient restClient;
public ABTestReporter() { public ABTestInvoker() {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
} }
Loading…
Cancel
Save