[1040] | 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.
|
---|
[1030] | 14 |
|
---|
| 15 | package de.ugoe.cs.autoquest.usability.evaluation.rule.evaluator;
|
---|
| 16 |
|
---|
| 17 | import java.util.Map;
|
---|
| 18 |
|
---|
| 19 | import com.google.common.base.Optional;
|
---|
| 20 | import com.google.common.collect.Maps;
|
---|
| 21 |
|
---|
| 22 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
|
---|
| 23 | import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefect;
|
---|
| 24 | import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectFactory;
|
---|
| 25 | import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectSeverityLevel;
|
---|
| 26 | import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectXmlDescriptionResolver;
|
---|
| 27 | import de.ugoe.cs.autoquest.usability.evaluation.rule.set.UsabilityRule;
|
---|
| 28 | import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
|
---|
| 29 | import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatisticCache;
|
---|
| 30 | import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeNodeFilter;
|
---|
| 31 |
|
---|
[1040] | 32 | /**
|
---|
| 33 | * <p>
|
---|
| 34 | * TODO comment
|
---|
| 35 | * </p>
|
---|
| 36 | *
|
---|
| 37 | * @author Alexander Deicke
|
---|
| 38 | */
|
---|
[1030] | 39 | public abstract class RuleEvaluator {
|
---|
| 40 |
|
---|
| 41 | protected final UsabilityRule evaluatedUsabilityRule;
|
---|
| 42 |
|
---|
| 43 | protected final FilterStatistic filteredNodes;
|
---|
| 44 |
|
---|
| 45 | protected Map<String, String> defectDescriptionMessageParameterValues = Maps.newHashMap();
|
---|
| 46 |
|
---|
| 47 | public RuleEvaluator(UsabilityRule evaluatedUsabilityRule, ITaskTree taskTree) {
|
---|
| 48 | this.evaluatedUsabilityRule = evaluatedUsabilityRule;
|
---|
| 49 | this.filteredNodes = nodesUnderEvaluation(taskTree);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | protected abstract FilterStatistic nodesUnderEvaluation(ITaskTree taskTree);
|
---|
| 53 |
|
---|
| 54 | @SuppressWarnings("rawtypes")
|
---|
| 55 | protected Optional<FilterStatistic> loadFromCache(TaskTreeNodeFilter nodeFilter) {
|
---|
| 56 | return FilterStatisticCache.instance().getFilterStatistic(nodeFilter);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | @SuppressWarnings("rawtypes")
|
---|
[1040] | 60 | protected FilterStatistic cacheAndReturnNodes(ITaskTree taskTree, TaskTreeNodeFilter nodeFilter)
|
---|
| 61 | {
|
---|
[1030] | 62 | FilterStatistic textInputEvents = extractNodesFromTaskTree(taskTree);
|
---|
| 63 | FilterStatisticCache.instance().addFilterStatistic(nodeFilter, textInputEvents);
|
---|
| 64 | return textInputEvents;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | protected abstract FilterStatistic extractNodesFromTaskTree(ITaskTree taskTree);
|
---|
| 68 |
|
---|
| 69 | public Optional<UsabilityDefect> evaluationResult() {
|
---|
| 70 | Optional<UsabilityDefect> ruleEvaluationResult = Optional.absent();
|
---|
| 71 | float evaluationMetric = calculateEvaluationMetric();
|
---|
| 72 | Optional<UsabilityDefectSeverityLevel> severityLevel =
|
---|
| 73 | determineSeverityLevel(evaluationMetric);
|
---|
| 74 | if (severityLevel.isPresent()) {
|
---|
[1040] | 75 | ruleEvaluationResult = Optional.of(createRuleEvaluationResult(severityLevel.get()));
|
---|
[1030] | 76 | }
|
---|
| 77 | return ruleEvaluationResult;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | protected abstract float calculateEvaluationMetric();
|
---|
[1040] | 81 |
|
---|
[1035] | 82 | protected void storeEvaluationMetricForDefectDescription(String key, String value) {
|
---|
| 83 | defectDescriptionMessageParameterValues.put(key, value);
|
---|
| 84 | }
|
---|
[1030] | 85 |
|
---|
| 86 | protected abstract Optional<UsabilityDefectSeverityLevel> determineSeverityLevel(float evaluationMetric);
|
---|
| 87 |
|
---|
[1040] | 88 | public UsabilityDefect createRuleEvaluationResult(UsabilityDefectSeverityLevel severityLevelOfDefect)
|
---|
| 89 | {
|
---|
[1030] | 90 | return new UsabilityDefectFactory(UsabilityDefectXmlDescriptionResolver.instance())
|
---|
[1040] | 91 | .createUsabilityGuidlineRecommendation(severityLevelOfDefect, evaluatedUsabilityRule,
|
---|
[1030] | 92 | defectDescriptionMessageParameterValues);
|
---|
| 93 | }
|
---|
| 94 | }
|
---|