[1423] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
| 2 | // |
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 4 | // you may not use this file except in compliance with the License. |
---|
| 5 | // You may obtain a copy of the License at |
---|
| 6 | // |
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 8 | // |
---|
| 9 | // Unless required by applicable law or agreed to in writing, software |
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 12 | // See the License for the specific language governing permissions and |
---|
| 13 | // limitations under the License. |
---|
| 14 | |
---|
| 15 | package de.ugoe.cs.autoquest.tasktrees.treeifc; |
---|
| 16 | |
---|
| 17 | import java.text.DecimalFormat; |
---|
| 18 | |
---|
| 19 | /** |
---|
| 20 | * <p> |
---|
| 21 | * represents different metrics available or calculatable for tasks. Measure for the metrics |
---|
| 22 | * are calculated by a task model and added to the task infos of a specific task. |
---|
| 23 | * </p> |
---|
| 24 | * |
---|
| 25 | * @author Patrick Harms |
---|
| 26 | */ |
---|
| 27 | public enum TaskMetric { |
---|
| 28 | |
---|
| 29 | COUNT("count", "number of all occurrences of the task in the model"), |
---|
| 30 | DEPTH("depth", |
---|
| 31 | "the maximum depth of the task, i.e., the number of children levels including the " + |
---|
| 32 | "level of the task itself"), |
---|
| 33 | EVENT_COVERAGE("covered events", "number of all event task instances covered by the task"), |
---|
| 34 | EVENT_COVERAGE_RATIO("event coverage ratio", |
---|
| 35 | "the ratio of events covered by this task in relation to all events " + |
---|
[1494] | 36 | "covered by all tasks in their instances in per mille", 0.1, "%"), |
---|
| 37 | EVENT_COVERAGE_QUANTILE("event coverage ratio quantile", |
---|
| 38 | "the quantile of with respect to all event coverages begining with " + |
---|
| 39 | "the lowest", 0.1, "%"); |
---|
[1423] | 40 | |
---|
| 41 | /** |
---|
| 42 | * <p> |
---|
| 43 | * the name of the metric |
---|
| 44 | * </p> |
---|
| 45 | */ |
---|
| 46 | private String name; |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * <p> |
---|
| 50 | * a human readable description of the metric |
---|
| 51 | * </p> |
---|
| 52 | */ |
---|
| 53 | private String description; |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | * <p> |
---|
| 57 | * a scale applied for the metric when formatting the value |
---|
| 58 | * </p> |
---|
| 59 | */ |
---|
| 60 | private double formatScale; |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | * <p> |
---|
| 64 | * the unit of the metric used when formatting the value |
---|
| 65 | * </p> |
---|
| 66 | */ |
---|
| 67 | private String formatUnit; |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * <p> |
---|
| 71 | * initializes the metric with a name and a description |
---|
| 72 | * </p> |
---|
| 73 | */ |
---|
| 74 | private TaskMetric(String name, String description) { |
---|
| 75 | this.name = name; |
---|
| 76 | this.description = description; |
---|
| 77 | this.formatScale = 1.0; |
---|
| 78 | this.formatUnit = null; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | /** |
---|
| 82 | * <p> |
---|
| 83 | * initializes the metric with a name and a description, as well as with a scale and a unit for |
---|
| 84 | * formatting it. |
---|
| 85 | * </p> |
---|
| 86 | */ |
---|
| 87 | private TaskMetric(String name, String description, double formatScale, String formatUnit) { |
---|
| 88 | this.name = name; |
---|
| 89 | this.description = description; |
---|
| 90 | this.formatScale = formatScale; |
---|
| 91 | this.formatUnit = formatUnit; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | * <p> |
---|
| 96 | * returns the name of the metric |
---|
| 97 | * </p> |
---|
| 98 | * |
---|
| 99 | * @return the name of the metric |
---|
| 100 | */ |
---|
| 101 | public String getName() { |
---|
| 102 | return name; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | * <p> |
---|
| 107 | * returns the human readable description of the metric |
---|
| 108 | * </p> |
---|
| 109 | * |
---|
| 110 | * @return the human readable description of the metric |
---|
| 111 | */ |
---|
| 112 | public String getDescription() { |
---|
| 113 | return description; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | /** |
---|
| 117 | * <p> |
---|
| 118 | * formats the provided value of a measure of the metric using the internal format scale and |
---|
| 119 | * unit. |
---|
| 120 | * </p> |
---|
| 121 | * |
---|
| 122 | * @return the formatted value depending on the scale and unit of the metric |
---|
| 123 | */ |
---|
| 124 | public String formatValue(int value) { |
---|
| 125 | String formattedValue; |
---|
| 126 | |
---|
| 127 | if (formatScale != 1.0) { |
---|
| 128 | double effectiveValue = formatScale * value; |
---|
| 129 | formattedValue = new DecimalFormat( "#,##0.0;(#)").format(effectiveValue); |
---|
| 130 | } |
---|
| 131 | else { |
---|
| 132 | formattedValue = Integer.toString(value); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | if (formatUnit != null) { |
---|
| 136 | formattedValue += formatUnit; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | return formattedValue; |
---|
| 140 | } |
---|
| 141 | } |
---|