diff --git a/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java b/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java index d11be2c3d..990fb57d7 100644 --- a/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java +++ b/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java @@ -136,15 +136,19 @@ public KruizeObject() { public static void setDefaultTerms(Map terms, KruizeObject kruizeObject) { // TODO: define term names like daily, weekly, fortnightly etc // TODO: add CRD for terms - terms.put(KruizeConstants.JSONKeys.SHORT_TERM, new Terms(KruizeConstants.JSONKeys.SHORT_TERM, KruizeConstants.RecommendationEngineConstants - .DurationBasedEngine.DurationAmount.SHORT_TERM_DURATION_DAYS, KruizeConstants.RecommendationEngineConstants - .DurationBasedEngine.DurationAmount.SHORT_TERM_DURATION_DAYS_THRESHOLD, 4, 0.25)); - terms.put(KruizeConstants.JSONKeys.MEDIUM_TERM, new Terms(KruizeConstants.JSONKeys.MEDIUM_TERM, KruizeConstants - .RecommendationEngineConstants.DurationBasedEngine.DurationAmount.MEDIUM_TERM_DURATION_DAYS, KruizeConstants - .RecommendationEngineConstants.DurationBasedEngine.DurationAmount.MEDIUM_TERM_DURATION_DAYS_THRESHOLD, 7, 1)); - terms.put(KruizeConstants.JSONKeys.LONG_TERM, new Terms(KruizeConstants.JSONKeys.LONG_TERM, KruizeConstants - .RecommendationEngineConstants.DurationBasedEngine.DurationAmount.LONG_TERM_DURATION_DAYS, KruizeConstants - .RecommendationEngineConstants.DurationBasedEngine.DurationAmount.LONG_TERM_DURATION_DAYS_THRESHOLD, 15, 1)); + + terms.put(KruizeConstants.JSONKeys.SHORT_TERM, new Terms(KruizeConstants.JSONKeys.SHORT_TERM, + KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.SHORT_TERM_DURATION_DAYS, + getTermThresholdInDays(KruizeConstants.JSONKeys.SHORT_TERM, kruizeObject.getTrial_settings().getMeasurement_durationMinutes_inDouble()), + 4, 0.25)); + terms.put(KruizeConstants.JSONKeys.MEDIUM_TERM, new Terms(KruizeConstants.JSONKeys.MEDIUM_TERM, + KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.MEDIUM_TERM_DURATION_DAYS, + getTermThresholdInDays(KruizeConstants.JSONKeys.MEDIUM_TERM, kruizeObject.getTrial_settings().getMeasurement_durationMinutes_inDouble()), + 7, 1)); + terms.put(KruizeConstants.JSONKeys.LONG_TERM, new Terms(KruizeConstants.JSONKeys.LONG_TERM, + KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.LONG_TERM_DURATION_DAYS, + getTermThresholdInDays(KruizeConstants.JSONKeys.LONG_TERM, kruizeObject.getTrial_settings().getMeasurement_durationMinutes_inDouble()), + 15, 1)); kruizeObject.setTerms(terms); } @@ -359,4 +363,23 @@ public boolean isNamespaceExperiment() { public boolean isContainerExperiment() { return ExperimentTypeUtil.isContainerExperiment(experimentType); } + + private static double getTermThresholdInDays(String term, Double measurement_duration) { + double minDataPoints = 2; + + switch (term) { + case KruizeConstants.JSONKeys.SHORT_TERM: + minDataPoints = KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.SHORT_TERM_MIN_DATAPOINTS; + break; + case KruizeConstants.JSONKeys.MEDIUM_TERM: + minDataPoints = KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.MEDIUM_TERM_MIN_DATAPOINTS; + break; + case KruizeConstants.JSONKeys.LONG_TERM: + minDataPoints = KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.LONG_TERM_MIN_DATAPOINTS; + break; + } + + return ((double) measurement_duration * minDataPoints + / (KruizeConstants.TimeConv.NO_OF_HOURS_PER_DAY * KruizeConstants.TimeConv.NO_OF_MINUTES_PER_HOUR)); + } } diff --git a/src/main/java/com/autotune/utils/KruizeConstants.java b/src/main/java/com/autotune/utils/KruizeConstants.java index ff0b52592..5484526b8 100644 --- a/src/main/java/com/autotune/utils/KruizeConstants.java +++ b/src/main/java/com/autotune/utils/KruizeConstants.java @@ -730,6 +730,14 @@ public static final class DurationAmount { public static final int MEDIUM_TERM_DURATION_DAYS_THRESHOLD = 2; public static final int LONG_TERM_DURATION_DAYS = 15; public static final int LONG_TERM_DURATION_DAYS_THRESHOLD = 8; + // Represents the minimum number of data points required for different term thresholds. + // Minimum data points are calculated based on the above threshold in days and a 15-minute measurement duration. + // If the short-term threshold is 30 minutes and the measurement duration is 15 minutes + // then the minimum data points = 30 / 15 = 2 + public static final int SHORT_TERM_MIN_DATAPOINTS = 2; + public static final int MEDIUM_TERM_MIN_DATAPOINTS = 192; + public static final int LONG_TERM_MIN_DATAPOINTS = 768; + private DurationAmount() {