source: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/TaskMetric.java @ 1428

Last change on this file since 1428 was 1423, checked in by pharms, 10 years ago
  • added possibility to calculate metrics for tasks and added the first metrics
File size: 3.8 KB
Line 
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
15package de.ugoe.cs.autoquest.tasktrees.treeifc;
16
17import 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 */
27public 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 " +
36                         "covered by all tasks in their instances in per mille", 0.1, "%");
37   
38    /**
39     * <p>
40     * the name of the metric
41     * </p>
42     */
43    private String name;
44   
45    /**
46     * <p>
47     * a human readable description of the metric
48     * </p>
49     */
50    private String description;
51
52    /**
53     * <p>
54     * a scale applied for the metric when formatting the value
55     * </p>
56     */
57    private double formatScale;
58   
59    /**
60     * <p>
61     * the unit of the metric used when formatting the value
62     * </p>
63     */
64    private String formatUnit;
65   
66    /**
67     * <p>
68     * initializes the metric with a name and a description
69     * </p>
70     */
71    private TaskMetric(String name, String description) {
72        this.name = name;
73        this.description = description;
74        this.formatScale = 1.0;
75        this.formatUnit = null;
76    }
77
78    /**
79     * <p>
80     * initializes the metric with a name and a description, as well as with a scale and a unit for
81     * formatting it.
82     * </p>
83     */
84    private TaskMetric(String name, String description, double formatScale, String formatUnit) {
85        this.name = name;
86        this.description = description;
87        this.formatScale = formatScale;
88        this.formatUnit = formatUnit;
89    }
90
91    /**
92     * <p>
93     * returns the name of the metric
94     * </p>
95     *
96     * @return the name of the metric
97     */
98    public String getName() {
99        return name;
100    }
101
102    /**
103     * <p>
104     * returns the human readable description of the metric
105     * </p>
106     *
107     * @return the human readable description of the metric
108     */
109    public String getDescription() {
110        return description;
111    }
112   
113    /**
114     * <p>
115     * formats the provided value of a measure of the metric using the internal format scale and
116     * unit.
117     * </p>
118     *
119     * @return the formatted value depending on the scale and unit of the metric
120     */
121    public String formatValue(int value) {
122        String formattedValue;
123       
124        if (formatScale != 1.0) {
125            double effectiveValue = formatScale * value;
126            formattedValue = new DecimalFormat( "#,##0.0;(#)").format(effectiveValue);
127        }
128        else {
129            formattedValue = Integer.toString(value);
130        }
131       
132        if (formatUnit != null) {
133            formattedValue += formatUnit;
134        }
135       
136        return formattedValue;
137    }
138}
Note: See TracBrowser for help on using the repository browser.