Skip to content

Commit

Permalink
Merge pull request #1203 from khansaad/values-round-off
Browse files Browse the repository at this point in the history
Format the durationInhours value
  • Loading branch information
dinogun authored Jun 13, 2024
2 parents a743f2e + 7878f19 commit 47ce130
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public static void setDurationBasedOnTerm(ContainerData containerDataKruizeObjec
mappedRecommendationForTerm, String recommendationTerm) {

double durationSummation = getDurationSummation(containerDataKruizeObject);
durationSummation = Double.parseDouble(String.format("%.1f", durationSummation));
// Get the maximum duration allowed for the term
double maxDurationInHours = getMaxDuration(recommendationTerm);
double maxDurationInMinutes = maxDurationInHours * KruizeConstants.TimeConv.NO_OF_MINUTES_PER_HOUR;
Expand All @@ -146,6 +145,7 @@ public static void setDurationBasedOnTerm(ContainerData containerDataKruizeObjec
durationSummation = maxDurationInMinutes;
}
double durationSummationInHours = durationSummation / KruizeConstants.TimeConv.NO_OF_MINUTES_PER_HOUR;
durationSummationInHours = Double.parseDouble(String.format("%.2f", durationSummationInHours));
mappedRecommendationForTerm.setDurationInHrs(durationSummationInHours);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/scripts/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ def validate_container(update_results_container, update_results_json, list_reco_
# assert cost_obj[term]["monitoring_end_time"] == interval_end_time, \
# f"monitoring end time {cost_obj[term]['monitoring_end_time']} did not match end timestamp {interval_end_time}"

# Validate the precision of the valid duration
duration = terms_obj[term]["duration_in_hours"]
assert validate_duration_in_hours_decimal_precision(duration), f"The value '{duration}' for " \
f"'{term}' has more than two decimal places"

monitoring_start_time = term_based_start_time(interval_end_time, term)
assert terms_obj[term]["monitoring_start_time"] == monitoring_start_time, \
f"actual = {terms_obj[term]['monitoring_start_time']} expected = {monitoring_start_time}"
Expand Down Expand Up @@ -857,3 +862,13 @@ def validate_recommendation_for_cpu_mem_optimised(recommendations: dict, current
assert recommendations["recommendation_engines"][profile]["config"]["limits"]["cpu"]["amount"] == current["limits"]["cpu"]["amount"]
assert recommendations["recommendation_engines"][profile]["config"]["requests"]["memory"]["amount"] == current["requests"]["memory"]["amount"]
assert recommendations["recommendation_engines"][profile]["config"]["limits"]["memory"]["amount"] == current["limits"]["memory"]["amount"]


# validate duration_in_hours decimal precision
def validate_duration_in_hours_decimal_precision(duration_in_hours):
"""
Validate that the given value has at most two decimal places.
:param duration_in_hours: The value to be validated.
:return: True if the value has at most two decimal places, False otherwise.
"""
return re.match(r'^\d+\.\d{3,}$', str(duration_in_hours)) is None

0 comments on commit 47ce130

Please sign in to comment.