[1030] | 1 |
|
---|
| 2 | package de.ugoe.cs.autoquest.usability.evaluation.rule.evaluator;
|
---|
| 3 |
|
---|
| 4 | import java.util.Map;
|
---|
| 5 |
|
---|
| 6 | import com.google.common.base.Optional;
|
---|
| 7 | import com.google.common.collect.Maps;
|
---|
| 8 |
|
---|
| 9 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
|
---|
| 10 | import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefect;
|
---|
| 11 | import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectFactory;
|
---|
| 12 | import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectSeverityLevel;
|
---|
| 13 | import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectXmlDescriptionResolver;
|
---|
| 14 | import de.ugoe.cs.autoquest.usability.evaluation.rule.set.UsabilityRule;
|
---|
| 15 | import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
|
---|
| 16 | import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatisticCache;
|
---|
| 17 | import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeNodeFilter;
|
---|
| 18 |
|
---|
| 19 | public abstract class RuleEvaluator {
|
---|
| 20 |
|
---|
| 21 | protected final UsabilityRule evaluatedUsabilityRule;
|
---|
| 22 |
|
---|
| 23 | protected final FilterStatistic filteredNodes;
|
---|
| 24 |
|
---|
| 25 | protected Map<String, String> defectDescriptionMessageParameterValues = Maps.newHashMap();
|
---|
| 26 |
|
---|
| 27 | public RuleEvaluator(UsabilityRule evaluatedUsabilityRule, ITaskTree taskTree) {
|
---|
| 28 | this.evaluatedUsabilityRule = evaluatedUsabilityRule;
|
---|
| 29 | this.filteredNodes = nodesUnderEvaluation(taskTree);
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | protected abstract FilterStatistic nodesUnderEvaluation(ITaskTree taskTree);
|
---|
| 33 |
|
---|
| 34 | @SuppressWarnings("rawtypes")
|
---|
| 35 | protected Optional<FilterStatistic> loadFromCache(TaskTreeNodeFilter nodeFilter) {
|
---|
| 36 | return FilterStatisticCache.instance().getFilterStatistic(nodeFilter);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | @SuppressWarnings("rawtypes")
|
---|
| 40 | protected FilterStatistic cacheAndReturnNodes(ITaskTree taskTree, TaskTreeNodeFilter nodeFilter) {
|
---|
| 41 | FilterStatistic textInputEvents = extractNodesFromTaskTree(taskTree);
|
---|
| 42 | FilterStatisticCache.instance().addFilterStatistic(nodeFilter, textInputEvents);
|
---|
| 43 | return textInputEvents;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | protected abstract FilterStatistic extractNodesFromTaskTree(ITaskTree taskTree);
|
---|
| 47 |
|
---|
| 48 | public Optional<UsabilityDefect> evaluationResult() {
|
---|
| 49 | Optional<UsabilityDefect> ruleEvaluationResult = Optional.absent();
|
---|
| 50 | float evaluationMetric = calculateEvaluationMetric();
|
---|
| 51 | Optional<UsabilityDefectSeverityLevel> severityLevel =
|
---|
| 52 | determineSeverityLevel(evaluationMetric);
|
---|
| 53 | if (severityLevel.isPresent()) {
|
---|
| 54 | ruleEvaluationResult =
|
---|
| 55 | Optional.of(createRuleEvaluationResult(severityLevel.get()));
|
---|
| 56 | }
|
---|
| 57 | return ruleEvaluationResult;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected abstract float calculateEvaluationMetric();
|
---|
[1035] | 61 |
|
---|
| 62 | protected void storeEvaluationMetricForDefectDescription(String key, String value) {
|
---|
| 63 | defectDescriptionMessageParameterValues.put(key, value);
|
---|
| 64 | }
|
---|
[1030] | 65 |
|
---|
| 66 | protected abstract Optional<UsabilityDefectSeverityLevel> determineSeverityLevel(float evaluationMetric);
|
---|
| 67 |
|
---|
| 68 | public UsabilityDefect createRuleEvaluationResult(UsabilityDefectSeverityLevel severityLevelOfDefect) {
|
---|
| 69 | return new UsabilityDefectFactory(UsabilityDefectXmlDescriptionResolver.instance())
|
---|
| 70 | .createUsabilityGuidlineRecommendation(severityLevelOfDefect,
|
---|
| 71 | evaluatedUsabilityRule,
|
---|
| 72 | defectDescriptionMessageParameterValues);
|
---|
| 73 | }
|
---|
| 74 | }
|
---|