From 02fcc8a93ce5dd60a1ccc8bca9f9809b14d20e2e Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Wed, 11 Jul 2012 20:29:49 +0200 Subject: [PATCH] Bug #1503: Fix intervals in task completion chart Reused the same function for both histograms: task completion and estimation accuracy. FEA: ItEr76S04BugFixing --- .../web/dashboard/DashboardController.java | 9 +- .../web/dashboard/DashboardModel.java | 151 +++++------------- .../web/dashboard/IDashboardModel.java | 3 +- 3 files changed, 41 insertions(+), 122 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/DashboardController.java b/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/DashboardController.java index 7b6998c86..2d7257c0d 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/DashboardController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/DashboardController.java @@ -35,7 +35,6 @@ import org.libreplan.business.orders.entities.Order; import org.libreplan.business.planner.entities.TaskElement; import org.libreplan.business.planner.entities.TaskStatusEnum; import org.libreplan.web.dashboard.DashboardModel.IntegerInterval; -import org.libreplan.web.dashboard.DashboardModel.Interval; import org.libreplan.web.planner.order.PlanningStateCreator.PlanningState; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.ApplicationContext; @@ -345,7 +344,7 @@ public class DashboardController extends GenericForwardComposer { private final IDashboardModel dashboardModel; - private Map taskCompletationData; + private Map taskCompletationData; private TaskCompletationData(IDashboardModel dashboardModel) { this.dashboardModel = dashboardModel; @@ -355,7 +354,7 @@ public class DashboardController extends GenericForwardComposer { return new TaskCompletationData(dashboardModel); } - private Map getData() { + private Map getData() { if (taskCompletationData == null) { taskCompletationData = dashboardModel .calculateTaskCompletion(); @@ -364,10 +363,10 @@ public class DashboardController extends GenericForwardComposer { } public String[] getTicks() { - Set intervals = getData().keySet(); + Set intervals = getData().keySet(); String[] result = new String[intervals.size()]; int i = 0; - for (Interval each : intervals) { + for (IntegerInterval each : intervals) { result[i++] = each.toString(); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/DashboardModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/DashboardModel.java index f121bc266..2ae3fc3c6 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/DashboardModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/DashboardModel.java @@ -262,54 +262,19 @@ public class DashboardModel implements IDashboardModel { } /** - * Calculates the task completation deviations for the current order + * Calculates the task completion deviations for the current order * - * All the deviations are groups in Interval.MAX_INTERVALS intervals of - * equal size. If the order contains just one single task then, the upper - * limit will be the deviation of the task + 3, and the lower limit will be - * deviation of the task - 2 + * All the deviations are groups in 6 intervals of equal size. If the order + * contains just one single task then, the upper limit will be the deviation + * of the task +3, and the lower limit will be deviation of the task -3 * * Each {@link Interval} contains the number of tasks that fit in that * interval - * - * @return */ @Override - public Map calculateTaskCompletion() { - Map result = new LinkedHashMap(); - Double max, min; - - // Get deviations of finished tasks, calculate max, min and delta + public Map calculateTaskCompletion() { List deviations = getTaskLagDeviations(); - if (deviations.isEmpty()) { - max = Double.valueOf(3); - min = Double.valueOf(-2); - } else if (deviations.size() == 1) { - max = deviations.get(0).doubleValue() + 3; - min = deviations.get(0).doubleValue() - 2; - } else { - max = Collections.max(deviations); - min = Collections.min(deviations); - } - double delta = (max - min) / Interval.MAX_INTERVALS; - - // Create MAX_INTERVALS - double from = min; - for (int i = 0; i < Interval.MAX_INTERVALS; i++) { - result.put(Interval.create(from, from + delta), Integer.valueOf(0)); - from = from + delta; - } - - // Construct map with number of tasks for each interval - final Set intervals = result.keySet(); - for (Double each : deviations) { - Interval interval = Interval.containingValue(intervals, each); - if (interval != null) { - Integer value = result.get(interval); - result.put(interval, value + 1); - } - } - return result; + return calculateHistogramIntervals(deviations, 6, 1); } private List getTaskLagDeviations() { @@ -349,36 +314,45 @@ public class DashboardModel implements IDashboardModel { */ @Override public Map calculateEstimationAccuracy() { - Map result = new LinkedHashMap(); - double maxDouble, minDouble; - - // Get deviations of finished tasks, calculate max, min and delta List deviations = getEstimationAccuracyDeviations(); - if (deviations.isEmpty()) { - minDouble = -30; - maxDouble = 30; - } else if (deviations.size() == 1) { - minDouble = deviations.get(0) - 30; - maxDouble = deviations.get(0) + 30; + return calculateHistogramIntervals(deviations, 6, 10); + } + + private Map calculateHistogramIntervals( + List values, int intervalsNumber, int intervalMinimumSize) { + Map result = new LinkedHashMap(); + + int totalMinimumSize = intervalsNumber * intervalMinimumSize; + int halfSize = totalMinimumSize / 2; + + double maxDouble, minDouble; + if (values.isEmpty()) { + minDouble = -halfSize; + maxDouble = halfSize; + } else if (values.size() == 1) { + minDouble = values.get(0) - halfSize; + maxDouble = values.get(0) + halfSize; } else { - minDouble = Collections.min(deviations); - maxDouble = Collections.max(deviations); + minDouble = Collections.min(values); + maxDouble = Collections.max(values); } - // If min and max are between -30 and +30, set -30 as min and +30 as max - if (minDouble >= -30 && maxDouble <= 30) { - minDouble = -30; - maxDouble = 30; + // If min and max are between -halfSize and +halfSize, set -halfSize as + // min and +halfSize as max + if (minDouble >= -halfSize && maxDouble <= halfSize) { + minDouble = -halfSize; + maxDouble = halfSize; } - // If the difference between min and max is less than 60, decrease min + // If the difference between min and max is less than totalMinimumSize, + // decrease min // and increase max till get that difference boolean changeMin = true; - while (maxDouble - minDouble < 60) { + while (maxDouble - minDouble < totalMinimumSize) { if (changeMin) { - minDouble -= 10; + minDouble -= intervalMinimumSize; } else { - maxDouble += 10; + maxDouble += intervalMinimumSize; } } @@ -405,7 +379,6 @@ public class DashboardModel implements IDashboardModel { } // Calculate intervals size - int intervalsNumber = 6; double delta = (double) (max - min) / intervalsNumber; double deltaDecimalPart = delta - (int) delta; @@ -424,7 +397,7 @@ public class DashboardModel implements IDashboardModel { // Construct map with number of tasks for each interval final Set intervals = result.keySet(); - for (Double each : deviations) { + for (Double each : values) { IntegerInterval interval = IntegerInterval.containingValue( intervals, each); if (interval != null) { @@ -475,58 +448,6 @@ public class DashboardModel implements IDashboardModel { } - /** - * - * @author Diego Pino GarcĂ­a - * - */ - static class Interval { - - public static final double MAX_INTERVALS = 6; - - private double min; - - private double max; - - private Interval() { - - } - - public static Interval create(double min, double max) { - return new Interval(min, max); - } - - private Interval(double min, double max) { - this.min = min; - this.max = max; - } - - public static Interval copy(Interval interval) { - return new Interval(interval.min, interval.max); - } - - public static Interval containingValue(Collection intervals, - Double value) { - for (Interval each : intervals) { - if (each.includes(value)) { - return each; - } - } - return null; - } - - private boolean includes(double value) { - return (value >= min) && (value <= max); - } - - @Override - public String toString() { - return String.format("[%d, %d]", (int) Math.ceil(min), - (int) Math.ceil(max)); - } - - } - @Override public Map calculateTaskStatus() { AccumulateTasksStatusVisitor visitor = new AccumulateTasksStatusVisitor(); diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/IDashboardModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/IDashboardModel.java index 5461ab116..127b4f880 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/IDashboardModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/dashboard/IDashboardModel.java @@ -26,7 +26,6 @@ import java.util.Map; import org.libreplan.business.planner.entities.TaskElement; import org.libreplan.business.planner.entities.TaskStatusEnum; import org.libreplan.web.dashboard.DashboardModel.IntegerInterval; -import org.libreplan.web.dashboard.DashboardModel.Interval; import org.libreplan.web.planner.order.PlanningStateCreator.PlanningState; interface IDashboardModel { @@ -77,7 +76,7 @@ interface IDashboardModel { Map calculateEstimationAccuracy(); /* Time KPI: "Lead/Lag in task completion" */ - Map calculateTaskCompletion(); + Map calculateTaskCompletion(); /* Resources KPI: "Overtime Ratio" */