Skip to content

Commit

Permalink
Merge branch 'master' into app_excision
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef Norgan committed Apr 27, 2016
2 parents 63db47b + 3b3b9ae commit acf5315
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 115 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.hello.suripu</groupId>
<artifactId>suripu-parent</artifactId>
<packaging>pom</packaging>
<version>0.7.14-SNAPSHOT</version>
<version>0.7.16-SNAPSHOT</version>
<properties>
<dropwizard.version>0.6.2</dropwizard.version>
<protobuf.version>2.5.0</protobuf.version>
Expand Down
2 changes: 1 addition & 1 deletion suripu-algorithm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>suripu-parent</artifactId>
<groupId>com.hello.suripu</groupId>
<version>0.7.14-SNAPSHOT</version>
<version>0.7.16-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion suripu-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.hello.suripu</groupId>
<artifactId>suripu-parent</artifactId>
<version>0.7.14-SNAPSHOT</version>
<version>0.7.16-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
6 changes: 3 additions & 3 deletions suripu-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>suripu-parent</artifactId>
<groupId>com.hello.suripu</groupId>
<version>0.7.14-SNAPSHOT</version>
<version>0.7.16-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -19,7 +19,7 @@
<dependency>
<groupId>com.hello.suripu</groupId>
<artifactId>suripu-algorithm</artifactId>
<version>0.7.14-SNAPSHOT</version>
<version>0.7.16-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down Expand Up @@ -58,7 +58,7 @@
<dependency>
<groupId>com.hello.suripu</groupId>
<artifactId>suripu-api</artifactId>
<version>0.7.14-SNAPSHOT</version>
<version>0.7.16-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.xerial.snappy</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ public class FeatureFlipper {
public final static String SLEEP_SCORE_DURATION_WEIGHTING_V2 = "sleep_score_duration_weighting_V2";
public final static String SLEEP_SCORE_DURATION_V2 = "sleep_score_duration_v2";
public final static String SLEEP_SCORE_TIMES_AWAKE_PENALTY = "sleep_score_times_awake_penalty";

// Return enum to the app that Sleep Sounds cannot be played because Sense requires a firmware update
public final static String SLEEP_SOUNDS_DISPLAY_FW_UPDATE = "sleep_sounds_display_fw_update";

// Show the Sleep Sounds UI in the app
public final static String SLEEP_SOUNDS_ENABLED = "sleep_sounds_enabled";

public final static String SLEEP_SOUNDS_OVERRIDE_OTA = "sleep_sounds_override_ota";
public final static String SLEEP_SEGMENT_OFFSET_REMAPPING = "sleep_segment_offset_remapping";
public final static String SLEEP_STATS_MEDIUM_SLEEP = "sleep_stats_medium_sleep";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import com.google.common.collect.Sets;
import com.hello.suripu.core.db.AggregateSleepScoreDAODynamoDB;
import com.hello.suripu.core.db.CalibrationDAO;
import com.hello.suripu.core.db.DeviceDataDAO;
import com.hello.suripu.core.db.DeviceDataDAODynamoDB;
import com.hello.suripu.core.db.DeviceDataInsightQueryDAO;
import com.hello.suripu.core.db.DeviceReadDAO;
import com.hello.suripu.core.db.InsightsDAODynamoDB;
import com.hello.suripu.core.db.MarketingInsightsSeenDAODynamoDB;
import com.hello.suripu.core.db.SleepStatsDAODynamoDB;
import com.hello.suripu.core.db.TrackerMotionDAO;
import com.hello.suripu.core.db.TrendsInsightsDAO;
import com.hello.suripu.core.flipper.FeatureFlipper;
import com.hello.suripu.core.models.DeviceAccountPair;
Expand Down Expand Up @@ -86,11 +84,9 @@ public class InsightProcessor {

private static final Random RANDOM = new Random();

private final DeviceDataDAO deviceDataDAO;
private final DeviceDataDAODynamoDB deviceDataDAODynamoDB;
private final DeviceReadDAO deviceReadDAO;
private final TrendsInsightsDAO trendsInsightsDAO;
private final TrackerMotionDAO trackerMotionDAO;
private final AggregateSleepScoreDAODynamoDB scoreDAODynamoDB;
private final InsightsDAODynamoDB insightsDAODynamoDB;
private final SleepStatsDAODynamoDB sleepStatsDAODynamoDB;
Expand All @@ -110,11 +106,16 @@ public class InsightProcessor {
InsightCard.Category.SWIM,
InsightCard.Category.WORK));

public InsightProcessor(@NotNull final DeviceDataDAO deviceDataDAO,
@NotNull final DeviceDataDAODynamoDB deviceDataDAODynamoDB,
private static final ImmutableSet<InsightCard.Category> goalInsightPool = ImmutableSet.copyOf(Sets.newHashSet(
InsightCard.Category.GOAL_COFFEE,
InsightCard.Category.GOAL_GO_OUTSIDE,
InsightCard.Category.GOAL_SCHEDULE_THOUGHTS,
InsightCard.Category.GOAL_SCREENS,
InsightCard.Category.GOAL_WAKE_VARIANCE));

public InsightProcessor(@NotNull final DeviceDataDAODynamoDB deviceDataDAODynamoDB,
@NotNull final DeviceReadDAO deviceReadDAO,
@NotNull final TrendsInsightsDAO trendsInsightsDAO,
@NotNull final TrackerMotionDAO trackerMotionDAO,
@NotNull final AggregateSleepScoreDAODynamoDB scoreDAODynamoDB,
@NotNull final InsightsDAODynamoDB insightsDAODynamoDB,
@NotNull final SleepStatsDAODynamoDB sleepStatsDAODynamoDB,
Expand All @@ -125,11 +126,9 @@ public InsightProcessor(@NotNull final DeviceDataDAO deviceDataDAO,
@NotNull final CalibrationDAO calibrationDAO,
@NotNull final MarketingInsightsSeenDAODynamoDB marketingInsightsSeenDAODynamoDB
) {
this.deviceDataDAO = deviceDataDAO;
this.deviceDataDAODynamoDB = deviceDataDAODynamoDB;
this.deviceReadDAO = deviceReadDAO;
this.trendsInsightsDAO = trendsInsightsDAO;
this.trackerMotionDAO = trackerMotionDAO;
this.scoreDAODynamoDB = scoreDAODynamoDB;
this.insightsDAODynamoDB = insightsDAODynamoDB;
this.preferencesDAO = preferencesDAO;
Expand Down Expand Up @@ -157,20 +156,9 @@ public void generateInsights(final Long accountId, final DateTime accountCreated
return;
}

final Long internalDeviceId = deviceAccountPairOptional.get().internalDeviceId;

if (featureFlipper.userFeatureActive(FeatureFlipper.DYNAMODB_DEVICE_DATA_INSIGHTS, accountId, Collections.EMPTY_LIST)) {
LOGGER.info("Generating insights with DynamoDB for account {}", accountId);
try {
final String externalDeviceId = deviceAccountPairOptional.get().externalDeviceId;
this.generateGeneralInsights(accountId, DeviceId.create(externalDeviceId), deviceDataDAODynamoDB, featureFlipper);
return;
} catch (Exception ex) {
LOGGER.error("Caught exception generating insight for account using DynamoDB {}. {}", accountId, ex);
}
}

this.generateGeneralInsights(accountId, DeviceId.create(internalDeviceId), deviceDataDAO, featureFlipper);
final String externalDeviceId = deviceAccountPairOptional.get().externalDeviceId;
this.generateGeneralInsights(accountId, DeviceId.create(externalDeviceId), deviceDataDAODynamoDB, featureFlipper);
return;
}

/**
Expand Down Expand Up @@ -222,7 +210,7 @@ private Optional<InsightCard.Category> generateGeneralInsights(final Long accoun
public Optional<InsightCard.Category> generateGeneralInsights(final Long accountId, final DeviceId deviceId, final DeviceDataInsightQueryDAO deviceDataInsightQueryDAO,
final Set<InsightCard.Category> recentCategories, final DateTime currentTime, final RolloutClient featureFlipper) {

if (recentCategories.contains(InsightCard.Category.GOAL_GO_OUTSIDE) || recentCategories.contains(InsightCard.Category.GOAL_COFFEE)) {
if (!Collections.disjoint(recentCategories, goalInsightPool)) {
LOGGER.info("Goal insight generated recently for accountId {}, suppressing all other insights", accountId);
return Optional.absent();
}
Expand Down Expand Up @@ -448,7 +436,6 @@ public Optional<InsightCard.Category> generateInsightsByCategory(final Long acco
insightCardOptional = BedLightIntensity.getInsights(accountId, deviceId, deviceDataInsightQueryDAO, sleepStatsDAODynamoDB);
break;
case DRIVE:
marketingInsightsSeenDAODynamoDB.updateSeenCategories(accountId, category);
insightCardOptional = Drive.getMarketingInsights(accountId);
break;
case EAT:
Expand Down Expand Up @@ -497,7 +484,7 @@ public Optional<InsightCard.Category> generateInsightsByCategory(final Long acco
insightCardOptional = SleepScore.getMarketingInsights(accountId);
break;
case SOUND:
insightCardOptional = SoundDisturbance.getInsights(accountId, deviceId, deviceDataDAO, sleepStatsDAODynamoDB);
insightCardOptional = SoundDisturbance.getInsights(accountId, deviceId, deviceDataDAODynamoDB, sleepStatsDAODynamoDB);
break;
case SWIM:
insightCardOptional = Swim.getMarketingInsights(accountId);
Expand Down Expand Up @@ -594,11 +581,9 @@ private TemperatureUnit getTemperatureUnitString(final Long accountId) {
* Builder class, too many variables to initialize in the constructor
*/
public static class Builder {
private @Nullable DeviceDataDAO deviceDataDAO;
private @Nullable DeviceDataDAODynamoDB deviceDataDAODynamoDB;
private @Nullable DeviceReadDAO deviceReadDAO;
private @Nullable TrendsInsightsDAO trendsInsightsDAO;
private @Nullable TrackerMotionDAO trackerMotionDAO;
private @Nullable AggregateSleepScoreDAODynamoDB scoreDAODynamoDB;
private @Nullable InsightsDAODynamoDB insightsDAODynamoDB;
private @Nullable SleepStatsDAODynamoDB sleepStatsDAODynamoDB;
Expand All @@ -614,18 +599,12 @@ public Builder withMarketingInsightsSeenDAO(final MarketingInsightsSeenDAODynamo
return this;
}

public Builder withSenseDAOs(final DeviceDataDAO deviceDataDAO, final DeviceDataDAODynamoDB deviceDataDAODynamoDB, final DeviceReadDAO deviceReadDAO) {
public Builder withSenseDAOs(final DeviceDataDAODynamoDB deviceDataDAODynamoDB, final DeviceReadDAO deviceReadDAO) {
this.deviceReadDAO = deviceReadDAO;
this.deviceDataDAO = deviceDataDAO;
this.deviceDataDAODynamoDB = deviceDataDAODynamoDB;
return this;
}

public Builder withTrackerMotionDAO(final TrackerMotionDAO trackerMotionDAO) {
this.trackerMotionDAO = trackerMotionDAO;
return this;
}

public Builder withInsightsDAO(final TrendsInsightsDAO trendsInsightsDAO) {
this.trendsInsightsDAO = trendsInsightsDAO;
return this;
Expand Down Expand Up @@ -664,10 +643,8 @@ public Builder withCalibrationDAO(final CalibrationDAO calibrationDAO) {
}

public InsightProcessor build() {
checkNotNull(deviceDataDAO, "deviceDataDAO can not be null");
checkNotNull(deviceReadDAO, "deviceReadDAO can not be null");
checkNotNull(trendsInsightsDAO, "trendsInsightsDAO can not be null");
checkNotNull(trackerMotionDAO, "trackerMotionDAO can not be null");
checkNotNull(scoreDAODynamoDB, "scoreDAODynamoDB can not be null");
checkNotNull(insightsDAODynamoDB, "insightsDAODynamoDB can not be null");
checkNotNull(sleepStatsDAODynamoDB, "sleepStatsDAODynamoDB can not be null");
Expand All @@ -678,9 +655,8 @@ public InsightProcessor build() {
checkNotNull(calibrationDAO, "calibrationDAO cannot be null");
checkNotNull(marketingInsightsSeenDAODynamoDB, "marketInsightsSeenDAO cannot be null");

return new InsightProcessor(deviceDataDAO, deviceDataDAODynamoDB, deviceReadDAO,
return new InsightProcessor(deviceDataDAODynamoDB, deviceReadDAO,
trendsInsightsDAO,
trackerMotionDAO,
scoreDAODynamoDB, insightsDAODynamoDB,
sleepStatsDAODynamoDB,
preferencesDAO,
Expand Down
Loading

0 comments on commit acf5315

Please sign in to comment.