1 |
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.detecting.detectors;
|
2 |
2 |
|
3 |
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.DatabaseConnection;
|
4 |
|
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
|
5 |
|
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
|
6 |
|
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResultItem;
|
7 |
|
import cz.zcu.fav.kiv.antipatterndetectionapp.model.ResultDetail;
|
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.*;
|
8 |
5 |
import org.slf4j.Logger;
|
9 |
6 |
import org.slf4j.LoggerFactory;
|
10 |
7 |
|
11 |
|
import java.util.ArrayList;
|
12 |
|
import java.util.List;
|
13 |
|
import java.util.Map;
|
|
8 |
import java.util.*;
|
14 |
9 |
|
15 |
10 |
public class NinetyNinetyRuleDetectorImpl implements AntiPatternDetector {
|
16 |
11 |
|
... | ... | |
19 |
14 |
private final AntiPattern antiPattern = new AntiPattern(7L,
|
20 |
15 |
"Ninety Ninety Rule",
|
21 |
16 |
"NinetyNinetyRule",
|
22 |
|
"TODO");
|
|
17 |
"The first 90 percent of the code represents the first 90 percent of development time. The " +
|
|
18 |
"remaining 10 percent of the code represents another 90 percent of development time. " +
|
|
19 |
"Then decide on a long delay of the project compared to the original estimate. " +
|
|
20 |
"The functionality is almost done, some number is already closed and is only waiting " +
|
|
21 |
"for one activity to close, but it has been open for a long time.",
|
|
22 |
new HashMap<>() {{
|
|
23 |
put("maxDivisionRange", new Configuration<Double>("maxDivisionRange",
|
|
24 |
"Maximum ration value",
|
|
25 |
"Maximum ratio value of spent and estimated time", 1.2));
|
|
26 |
put("maxBadDivisionLimit", new Configuration<Integer>("maxBadDivisionLimit",
|
|
27 |
"Maximum iterations thresholds",
|
|
28 |
"Maximum number of consecutive iterations where the thresholds were exceeded", 2));
|
|
29 |
}});
|
23 |
30 |
|
24 |
31 |
private final String sqlFileName = "ninety_ninety_rule.sql";
|
25 |
32 |
// sql queries loaded from sql file
|
26 |
33 |
private List<String> sqlQueries;
|
27 |
34 |
|
28 |
|
/**
|
29 |
|
* SETTINGS
|
30 |
|
*/
|
31 |
|
private static final double MAX_DIVISION_RANGE = 1.2;
|
32 |
|
private static final double MIN_DIVISION_RANGE = 0.8;
|
33 |
|
private static final int MAX_BAD_ITERATION_LIMIT = 3;
|
|
35 |
private double getMaxDivisionRange() {
|
|
36 |
return (Double) antiPattern.getConfigurations().get("maxDivisionRange").getValue();
|
|
37 |
}
|
|
38 |
|
|
39 |
private int getMaxBadDivisionLimit() {
|
|
40 |
return (int) antiPattern.getConfigurations().get("maxBadDivisionLimit").getValue();
|
|
41 |
}
|
34 |
42 |
|
35 |
43 |
@Override
|
36 |
44 |
public AntiPattern getAntiPatternModel() {
|
... | ... | |
51 |
59 |
* Postup detekce:
|
52 |
60 |
* 1) pro každou iteraci udělat součet stráveného a odhadovaného času přes všechny aktivity
|
53 |
61 |
* 2) udělat podíl strávený čas / odhadovaný čas
|
54 |
|
* 3) pokud všechny výsledky podílů budou v rozsahu 0.8 - 1.2 => vše ok
|
|
62 |
* 3) pokud všechny výsledky podílů budou menší než 1.2 => vše ok
|
55 |
63 |
* 4) pokud předchozí bod nezabere, tak iterovat přes všechny podíly
|
56 |
|
* 5) pokud budou nalezeny tři iterace po sobě, které se stále zhoršují stejným směrem => detekce
|
|
64 |
* 5) pokud budou nalezeny tři iterace po sobě, kde se stále zhoršují odhady => detekováno
|
57 |
65 |
*
|
58 |
66 |
* @param project analyzovaný project
|
59 |
67 |
* @param databaseConnection databázové připojení
|
... | ... | |
76 |
84 |
}
|
77 |
85 |
divisionsResults.add(resultDivision);
|
78 |
86 |
// if is one division is out of range set boolean to false
|
79 |
|
if (resultDivision > MAX_DIVISION_RANGE || resultDivision < MIN_DIVISION_RANGE) {
|
|
87 |
if (resultDivision > getMaxDivisionRange()) {
|
80 |
88 |
isAllInRange = false;
|
81 |
89 |
}
|
82 |
90 |
}
|
... | ... | |
89 |
97 |
}
|
90 |
98 |
|
91 |
99 |
int counterOverEstimated = 0;
|
92 |
|
int counterUnderEstimated = 0;
|
93 |
100 |
for (Double divisionResult : divisionsResults) {
|
94 |
|
if (divisionResult > MAX_DIVISION_RANGE) {
|
|
101 |
if (divisionResult > getMaxDivisionRange()) {
|
95 |
102 |
counterOverEstimated++;
|
96 |
|
counterUnderEstimated = 0;
|
97 |
|
}
|
98 |
|
|
99 |
|
if (divisionResult < MIN_DIVISION_RANGE) {
|
100 |
|
counterUnderEstimated++;
|
|
103 |
} else {
|
101 |
104 |
counterOverEstimated = 0;
|
102 |
105 |
}
|
103 |
106 |
|
104 |
|
if (counterOverEstimated >= MAX_BAD_ITERATION_LIMIT) {
|
|
107 |
if (counterOverEstimated > getMaxBadDivisionLimit()) {
|
105 |
108 |
resultDetails.add(new ResultDetail("Conclusion",
|
106 |
|
"Found bad significant trend in estimated time - over estimated."));
|
107 |
|
return new QueryResultItem(this.antiPattern, false, resultDetails);
|
|
109 |
getMaxBadDivisionLimit() + " or more consecutive iterations has a bad trend in estimates"));
|
|
110 |
return new QueryResultItem(this.antiPattern, true, resultDetails);
|
108 |
111 |
}
|
109 |
112 |
|
110 |
|
if (counterUnderEstimated >= MAX_BAD_ITERATION_LIMIT) {
|
111 |
|
resultDetails.add(new ResultDetail("Conclusion",
|
112 |
|
"Found bad significant trend in estimated time - under estimated."));
|
113 |
|
return new QueryResultItem(this.antiPattern, false, resultDetails);
|
114 |
|
}
|
115 |
113 |
}
|
116 |
114 |
|
117 |
115 |
resultDetails.add(new ResultDetail("Conclusion",
|
Ninety-ninety rule finished