org.conqat.lib.commons.assessment.AssessmentUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of teamscale-lib-commons Show documentation
Show all versions of teamscale-lib-commons Show documentation
Provides common utility functions
/*
* Copyright (c) CQSE GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.conqat.lib.commons.assessment;
/**
* Utility methods for dealing with ratings.
*/
public class AssessmentUtils {
/**
* Ordering of assessments as used in the user interface. Corresponds to a visual ordering of the
* assessment bars.
*/
public static final ETrafficLightColor[][] ASSESSMENT_SORT_ORDER = {
{ ETrafficLightColor.RED, ETrafficLightColor.ORANGE, ETrafficLightColor.YELLOW, ETrafficLightColor.BASELINE,
ETrafficLightColor.UNKNOWN } };
/**
* Compares two {@link Assessment}s returning which is "better" than another one.
*
* @return the value 0 if o1 is equal to o2; a value less than 0 if o1 is worse than o2; and a value
* greater than 0 if o1 is better than o2.
*/
public static int compareAssessments(Assessment o1, Assessment o2) {
double red1 = o1.getColorFrequency(ETrafficLightColor.RED) / (double) o1.getSize();
double red2 = o2.getColorFrequency(ETrafficLightColor.RED) / (double) o2.getSize();
double yellow1 = o1.getColorFrequency(ETrafficLightColor.YELLOW) / (double) o1.getSize();
double yellow2 = o2.getColorFrequency(ETrafficLightColor.YELLOW) / (double) o2.getSize();
// chosen by a close look at the sorting result.
double yFactor = 0.4;
return Double.compare(red1 + yFactor * yellow1, red2 + yFactor * yellow2);
}
}