diff --git a/astrid/src/com/todoroo/astrid/dao/ABTestEventDao.java b/astrid/src/com/todoroo/astrid/dao/ABTestEventDao.java index 7fdd9a63b..9cf8e9781 100644 --- a/astrid/src/com/todoroo/astrid/dao/ABTestEventDao.java +++ b/astrid/src/com/todoroo/astrid/dao/ABTestEventDao.java @@ -67,4 +67,34 @@ public class ABTestEventDao extends DatabaseDao { return true; } + public void createRelativeDateEvents() { + TodorooCursor allEvents = query(Query.select(ABTestEvent.TEST_NAME, ABTestEvent.DATE_RECORDED) + .where(ABTestEvent.TIME_INTERVAL.eq(ABTestEvent.TIME_INTERVAL_0))); + + try { + long now = DateUtilities.now(); + for (allEvents.moveToFirst(); !allEvents.isAfterLast(); allEvents.moveToNext()) { + ABTestEvent event = new ABTestEvent(allEvents); + long baseTime = event.getValue(ABTestEvent.DATE_RECORDED); + long timeSinceBase = now - baseTime; + + String testName = event.getValue(ABTestEvent.TEST_NAME); + int timeInterval = -1; + if (timeSinceBase > 3 * DateUtilities.ONE_WEEK) + timeInterval = ABTestEvent.TIME_INTERVAL_21; + else if (timeSinceBase > 2 * DateUtilities.ONE_WEEK) + timeInterval = ABTestEvent.TIME_INTERVAL_14; + else if (timeSinceBase > DateUtilities.ONE_WEEK) + timeInterval = ABTestEvent.TIME_INTERVAL_7; + else if (timeSinceBase > 3 * DateUtilities.ONE_DAY) + timeInterval = ABTestEvent.TIME_INTERVAL_3; + + if (timeInterval > 0) + createTestEventWithTimeInterval(testName, timeInterval); + } + } finally { + allEvents.close(); + } + } + } diff --git a/astrid/src/com/todoroo/astrid/service/StartupService.java b/astrid/src/com/todoroo/astrid/service/StartupService.java index ca3d00888..0887193b8 100644 --- a/astrid/src/com/todoroo/astrid/service/StartupService.java +++ b/astrid/src/com/todoroo/astrid/service/StartupService.java @@ -35,6 +35,7 @@ import com.todoroo.astrid.actfm.sync.ActFmSyncService; import com.todoroo.astrid.backup.BackupConstants; import com.todoroo.astrid.backup.BackupService; import com.todoroo.astrid.backup.TasksXmlImporter; +import com.todoroo.astrid.dao.ABTestEventDao; import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.gtasks.sync.GtasksSyncService; @@ -91,6 +92,8 @@ public class StartupService { @Autowired ABTestEventReportingService abTestEventReportingService; + @Autowired ABTestEventDao abTestEventDao; + /** * bit to prevent multiple initializations */ @@ -218,8 +221,6 @@ public class StartupService { initializeABTesting(latestSetVersion == 0); AstridPreferences.setPreferenceDefaults(); - trackABTestingData(); - // check for task killers if(!Constants.OEM) showTaskKillerHelp(context); @@ -231,28 +232,7 @@ public class StartupService { abTestEventReportingService.initialize(); abTestEventReportingService.pushAllUnreportedABTestEvents(); abChooser.makeChoicesForAllTests(newUser, taskService.getUserActivationStatus()); - } - - private void trackABTestingData() { - long firstLaunchTime = Preferences.getLong(AstridPreferences.P_FIRST_LAUNCH, 0); - long now = DateUtilities.now(); - long timeSinceFirst = now - firstLaunchTime; - - if (firstLaunchTime == 0) { - // Event days +0 - } - if (timeSinceFirst > DateUtilities.ONE_DAY * 3 /*&& !some condition*/) { - // Event days +3 - } - if (timeSinceFirst > DateUtilities.ONE_WEEK /*&& !some condition*/) { - // Event days +7 - } - if (timeSinceFirst > 2 * DateUtilities.ONE_WEEK /*&& !some condition*/) { - // Event days +14 - } - if (timeSinceFirst > 3 * DateUtilities.ONE_WEEK /*&& !some condition*/) { - // Event days +21 - } + abTestEventDao.createRelativeDateEvents(); } /**