Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Functionality to Dynamically Calculate Threshold Value For Minimum Time Required For Term #1466

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,19 @@ public KruizeObject() {
public static void setDefaultTerms(Map<String, Terms> 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);
}
Expand Down Expand Up @@ -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));
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/autotune/utils/KruizeConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down