From 471d143567d6ddecc668beb2cde01171284fdac8 Mon Sep 17 00:00:00 2001 From: avelichk Date: Tue, 19 May 2020 00:55:13 +0100 Subject: [PATCH 1/2] Fix compare in trial info plot --- pkg/ui/v1alpha3/hp.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/ui/v1alpha3/hp.go b/pkg/ui/v1alpha3/hp.go index 56cb81227a7..f9f4e77ddb4 100644 --- a/pkg/ui/v1alpha3/hp.go +++ b/pkg/ui/v1alpha3/hp.go @@ -182,11 +182,29 @@ func (k *KatibUIHandler) FetchHPJobTrialInfo(w http.ResponseWriter, r *http.Requ prevMetricTimeValue[m.Metric.Name] = []string{"", ""} } + + newMetricValue, err := strconv.ParseFloat(m.Metric.Value, 64) + if err != nil { + log.Printf("ParseFloat for new metric value: %v failed: %v", m.Metric.Value, err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + var prevMetricValue float64 + if prevMetricTimeValue[m.Metric.Name][1] != "" { + prevMetricValue, err = strconv.ParseFloat(prevMetricTimeValue[m.Metric.Name][1], 64) + if err != nil { + log.Printf("ParseFloat for prev metric value: %v failed: %v", prevMetricTimeValue[m.Metric.Name][1], err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + if formatCurrentTime == prevMetricTimeValue[m.Metric.Name][0] && ((objectiveType == commonv1alpha3.ObjectiveTypeMinimize && - m.Metric.Value < prevMetricTimeValue[m.Metric.Name][1]) || + (newMetricValue < prevMetricValue)) || (objectiveType == commonv1alpha3.ObjectiveTypeMaximize && - m.Metric.Value > prevMetricTimeValue[m.Metric.Name][1])) { + (newMetricValue > prevMetricValue))) { prevMetricTimeValue[m.Metric.Name][1] = m.Metric.Value for i := len(resultArray) - 1; i >= 0; i-- { From f33b65ed1b3671746ca3146bc6bd98cfa047a13c Mon Sep 17 00:00:00 2001 From: avelichk Date: Tue, 19 May 2020 01:02:33 +0100 Subject: [PATCH 2/2] Remove parentheses --- pkg/ui/v1alpha3/hp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/ui/v1alpha3/hp.go b/pkg/ui/v1alpha3/hp.go index f9f4e77ddb4..4c5204f66bc 100644 --- a/pkg/ui/v1alpha3/hp.go +++ b/pkg/ui/v1alpha3/hp.go @@ -202,9 +202,9 @@ func (k *KatibUIHandler) FetchHPJobTrialInfo(w http.ResponseWriter, r *http.Requ if formatCurrentTime == prevMetricTimeValue[m.Metric.Name][0] && ((objectiveType == commonv1alpha3.ObjectiveTypeMinimize && - (newMetricValue < prevMetricValue)) || + newMetricValue < prevMetricValue) || (objectiveType == commonv1alpha3.ObjectiveTypeMaximize && - (newMetricValue > prevMetricValue))) { + newMetricValue > prevMetricValue)) { prevMetricTimeValue[m.Metric.Name][1] = m.Metric.Value for i := len(resultArray) - 1; i >= 0; i-- {