source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/result/UsabilityProblemDescription.java @ 1319

Last change on this file since 1319 was 1319, checked in by khartmann, 11 years ago
  • Reworked Filters to use the first instance of a task to provide type and target
  • Added a function to extract all tasks matching a given filter
  • Added simple console feedback for matched usability problems
  • Property svn:mime-type set to text/plain
File size: 4.9 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.usability.result;
16
17import java.util.Collections;
18import java.util.EnumMap;
19import java.util.Map;
20
21import com.google.common.base.Optional;
22import com.google.common.base.Predicate;
23import com.google.common.collect.BiMap;
24import com.google.common.collect.HashBiMap;
25import com.google.common.collect.Maps;
26
27/**
28 * <p>
29 * Description for a usability problem.
30 * </p>
31 *
32 * @author Alexander Deicke
33 */
34public class UsabilityProblemDescription {
35    /**
36     * <p>
37     * The severity of the defect.
38     * </p>
39     */
40
41    private UsabilityProblemSeverityLevel severityLevel = UsabilityProblemSeverityLevel.NONE;
42
43    /**
44     * <p>
45     * A detailed description of the defect.
46     * </p>
47     */
48    private String description;
49
50    /**
51     * <p>
52     * Assignment of all possible severity values to a certain threshold. This is used, to determine
53     * the severity level during the usability evaluation.
54     * </p>
55     */
56    private final EnumMap<UsabilityProblemSeverityLevel, Double> severity;
57
58    /**
59     * <p>
60     * Constructor. Creates a new UsabilityDefectDescription for given description and all possible
61     * severity level.
62     * </p>
63     *
64     * @param description
65     *            description of the defect
66     * @param severity
67     *            all possible severity level and their threshold
68     */
69    public UsabilityProblemDescription(String description,
70                                      EnumMap<UsabilityProblemSeverityLevel, Double> severity)
71    {
72        this.description = description;
73        this.severity = severity;
74    }
75
76    /**
77     * <p>
78     * Gets the severity level of this defect.
79     * </p>
80     *
81     * @return severity level of this defect
82     */
83    public UsabilityProblemSeverityLevel getSeverityLevel() {
84        return this.severityLevel;
85    }
86
87    @Override
88    public String toString() {
89        return this.description;
90    }
91   
92    /**
93     * <p>
94     * Checks, if a defect is present. Therefore it uses a value, which is used to determine the
95     * severity level.
96     * </p>
97     *
98     * @param evaluationMetric
99     *            value, which determines the severity level of a defect
100     * @return iff defect is present, a {@linkplain UsabilityProblemDescription} of the defect
101     */
102    public Optional<UsabilityProblemDescription> isPresent(float evaluationMetric) {
103        Optional<UsabilityProblemDescription> defect = Optional.absent();
104        Map<UsabilityProblemSeverityLevel, Double> matchingSeverityLevels =
105            Maps.filterValues(this.severity, severityForMetric(evaluationMetric));
106        if (matchingSeverityLevels.isEmpty()) {
107            return defect;
108        }
109        setDefectAttributes(matchingSeverityLevels, evaluationMetric);
110        return Optional.of(this);
111    }
112
113    /**
114     * <p>
115     * Initializes the properties of a {@linkplain UsabilityProblemDescription}.
116     * </p>
117     *
118     * @param matchingSeverityLevels
119     *            all severity level, where {@linkplain evaluationMetric} exceeds the threshold
120     * @param evaluationMetric
121     *            measure for the defect
122     */
123    private void setDefectAttributes(Map<UsabilityProblemSeverityLevel, Double> matchingSeverityLevels,
124                                     float evaluationMetric)
125    {
126        BiMap<Double, UsabilityProblemSeverityLevel> inverse =
127            HashBiMap.create(matchingSeverityLevels).inverse();
128        this.severityLevel = inverse.get(Collections.max(inverse.keySet()));
129        this.description = String.format(this.description, evaluationMetric);
130    }
131
132    /**
133     * <p>
134     * Gets severity level depending on a measurement for the defect.
135     * </p>
136     *
137     * @param evaluationMetric
138     *            measure for the defect
139     *
140     * @return severity level, if measurement is equal or bigger as the threshold of the severity
141     *         level
142     */
143    private Predicate<Double> severityForMetric(final float evaluationMetric) {
144        return new Predicate<Double>() {
145
146            public boolean apply(Double severityThreshold) {
147                return evaluationMetric == severityThreshold ||
148                    evaluationMetric > severityThreshold;
149            }
150
151        };
152    }
153
154}
Note: See TracBrowser for help on using the repository browser.