All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.conqat.lib.commons.assessment.AssessmentUtils Maven / Gradle / Ivy

There is a newer version: 2024.7.2
Show newest version
/*
 * 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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy