From 190b5dcf743e6356ba15740c2c773d7dea74b17a Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Tue, 10 Jul 2012 20:14:57 -0700 Subject: [PATCH] Report ab test event info when assigning a task --- .../astrid/actfm/sync/ActFmSyncService.java | 17 +++++++++++++++++ .../abtesting/ABTestEventReportingService.java | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index 83a380fd1..b7644cd7a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -69,6 +69,7 @@ import com.todoroo.astrid.service.StatisticsConstants; import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TaskService; +import com.todoroo.astrid.service.abtesting.ABTestEventReportingService; import com.todoroo.astrid.sync.SyncV2Provider.SyncExceptionHandler; import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.utility.Flags; @@ -95,6 +96,7 @@ public final class ActFmSyncService { @Autowired TagDataDao tagDataDao; @Autowired UpdateDao updateDao; @Autowired MetadataDao metadataDao; + @Autowired ABTestEventReportingService abTestEventReportingService; public static final long TIME_BETWEEN_TRIES = 5 * DateUtilities.ONE_MINUTE; @@ -382,6 +384,8 @@ public final class ActFmSyncService { params.add("repeat"); params.add(recurrence); } + + boolean sharing = false; if(values.containsKey(Task.USER_ID.name) && task.getTransitory(TaskService.TRANS_ASSIGNED) != null) { if(task.getValue(Task.USER_ID) == Task.USER_ID_EMAIL) { try { @@ -403,6 +407,7 @@ public final class ActFmSyncService { else params.add(task.getValue(Task.USER_ID)); } + sharing = true; } if (values.containsKey(Task.SHARED_WITH.name)) { @@ -422,6 +427,18 @@ public final class ActFmSyncService { } catch (JSONException e) { Log.e("Error parsing shared_with", task.getValue(Task.SHARED_WITH), e); } + sharing = true; + } + + if (sharing) { + JSONArray abTestInfo = abTestEventReportingService.getTestsWithVariantsArray(); + try { + for (int i = 0; i < abTestInfo.length(); i++) { + params.add("ab_variants[]"); params.add(abTestInfo.getString(i)); + } + } catch (JSONException e) { + Log.e("Error parsing AB test info", abTestInfo.toString(), e); + } } if(Flags.checkAndClear(Flags.TAGS_CHANGED) || newlyCreated) { diff --git a/astrid/src/com/todoroo/astrid/service/abtesting/ABTestEventReportingService.java b/astrid/src/com/todoroo/astrid/service/abtesting/ABTestEventReportingService.java index f578c5898..cc8e8d1df 100644 --- a/astrid/src/com/todoroo/astrid/service/abtesting/ABTestEventReportingService.java +++ b/astrid/src/com/todoroo/astrid/service/abtesting/ABTestEventReportingService.java @@ -1,6 +1,7 @@ package com.todoroo.astrid.service.abtesting; import java.io.IOException; +import java.util.Set; import org.json.JSONArray; import org.json.JSONException; @@ -41,6 +42,9 @@ public final class ABTestEventReportingService { @Autowired private ABTestInvoker abTestInvoker; + @Autowired + private ABTests abTests; + public ABTestEventReportingService() { DependencyInjectionService.getInstance().inject(this); } @@ -88,6 +92,16 @@ public final class ABTestEventReportingService { } } + public JSONArray getTestsWithVariantsArray() { + JSONArray array = new JSONArray(); + Set tests = abTests.getAllTestKeys(); + + for (String key : tests) { + array.put(key + ":" + abTests.getDescriptionForTestOption(key, ABChooser.readChoiceForTest(key))); + } + return array; + } + private void handleException(Exception e) { Log.e("analytics", "analytics-error", e); }