Source:
public Boolean generateCurrentAggStats(final DeviceAccountPair deviceAccountPair) { final Long accountId = deviceAccountPair.accountId; final Optional<Integer> timeZoneOffsetOptional = sleepStatsDAODynamoDB.getTimeZoneOffset(accountId); if (!timeZoneOffsetOptional.isPresent()) { LOGGER.debug("method=current-aggstat action=skip-compute-agg-stats reason=timezoneoffset-absent account_id={}", accountId); return Boolean.FALSE; } final Integer timeZoneOffset = timeZoneOffsetOptional.get(); final DateTime utcNow = DateTime.now(); final DateTime localNow = utcNow.plusMillis(timeZoneOffset); final Boolean inAllowedComputeTime = checkAllowedComputeTime(localNow); if (!inAllowedComputeTime) { LOGGER.debug("action=skip-compute-agg-stats reason=not-in-compute-hours-range account_id={} local_hour={}", accountId, localNow.getHourOfDay()); return Boolean.FALSE; } final DateTime targetDateLocal = localNow.minusDays(1).withTimeAtStartOfDay(); final DeviceId deviceId = DeviceId.create(deviceAccountPair.externalDeviceId); final Optional<AggStats> presentAggStat = aggStatsDAODynamoDB.getSingleStat(accountId, deviceId, targetDateLocal); if (presentAggStat.isPresent()) { LOGGER.debug("action=skip-compute-agg-stats condition=agg-stats-already-present account_id={} target_date_local={}", accountId, targetDateLocal.toString()); return Boolean.FALSE; } final AggStats aggStats = computeAggStatsForDay(accountId, deviceId, targetDateLocal, timeZoneOffset); LOGGER.debug("action=computed-agg-stats account_id={} target_date_local={}", accountId, targetDateLocal.toString()); final Boolean successInsert = saveAggStat(aggStats); LOGGER.info("action=insert-agg-stats success={} account_id={} ", successInsert.toString(), aggStats.accountId); return successInsert; }

Target:
public Boolean generateCurrentAggStats(final DeviceAccountPair deviceAccountPair) { final Long accountId = deviceAccountPair.accountId; final Optional<Integer> timeZoneOffsetOptional = sleepStatsDAODynamoDB.getTimeZoneOffset(accountId); if (!timeZoneOffsetOptional.isPresent()) { LOGGER.debug("method=current-aggstat action=skip-compute-agg-stats reason=timezoneoffset-absent account_id={}", accountId); return Boolean.FALSE; } final Integer timeZoneOffset = timeZoneOffsetOptional.get(); final DateTime utcNow = DateTime.now(DateTimeZone.UTC); final DateTime localNow = utcNow.plusMillis(timeZoneOffset); final Boolean inAllowedComputeTime = checkAllowedComputeTime(localNow); if (!inAllowedComputeTime) { LOGGER.debug("action=skip-compute-agg-stats reason=not-in-compute-hours-range account_id={} local_hour={}", accountId, localNow.getHourOfDay()); return Boolean.FALSE; } final DateTime targetDateLocal = localNow.minusDays(1).withTimeAtStartOfDay(); final DeviceId deviceId = DeviceId.create(deviceAccountPair.externalDeviceId); final Optional<AggStats> presentAggStat = aggStatsDAODynamoDB.getSingleStat(accountId, deviceId, targetDateLocal); if (presentAggStat.isPresent()) { LOGGER.debug("action=skip-compute-agg-stats condition=agg-stats-already-present account_id={} target_date_local={}", accountId, targetDateLocal.toString()); return Boolean.FALSE; } final AggStats aggStats = computeAggStatsForDay(accountId, deviceId, targetDateLocal, timeZoneOffset); LOGGER.debug("action=computed-agg-stats account_id={} target_date_local={}", accountId, targetDateLocal.toString()); final Boolean successInsert = saveAggStat(aggStats); if (!successInsert) { LOGGER.warn("action=insert-agg-stats success={} account_id={} ", successInsert.toString(), aggStats.accountId); } return successInsert; }