ItEr39S05ValidacionEProbasFuncionaisItEr38S05: [Bug #179] Fixed using BigDecimal for chart calculations.
This commit is contained in:
parent
758881b987
commit
5dd0b1807d
3 changed files with 52 additions and 46 deletions
|
|
@ -65,9 +65,9 @@ import org.zkoss.zk.ui.Executions;
|
|||
public abstract class ChartFiller implements IChartFiller {
|
||||
|
||||
protected abstract class HoursByDayCalculator<T> {
|
||||
public SortedMap<LocalDate, Integer> calculate(
|
||||
public SortedMap<LocalDate, BigDecimal> calculate(
|
||||
Collection<? extends T> elements) {
|
||||
SortedMap<LocalDate, Integer> result = new TreeMap<LocalDate, Integer>();
|
||||
SortedMap<LocalDate, BigDecimal> result = new TreeMap<LocalDate, BigDecimal>();
|
||||
if (elements.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
|
@ -76,9 +76,9 @@ public abstract class ChartFiller implements IChartFiller {
|
|||
int hours = getHoursFor(element);
|
||||
LocalDate day = getDayFor(element);
|
||||
if (!result.containsKey(day)) {
|
||||
result.put(day, 0);
|
||||
result.put(day, BigDecimal.ZERO);
|
||||
}
|
||||
result.put(day, result.get(day) + hours);
|
||||
result.put(day, result.get(day).add(new BigDecimal(hours)));
|
||||
}
|
||||
}
|
||||
return convertAsNeededByZoom(result);
|
||||
|
|
@ -352,28 +352,30 @@ public abstract class ChartFiller implements IChartFiller {
|
|||
return maximumValueForChart;
|
||||
}
|
||||
|
||||
protected SortedMap<LocalDate, Integer> groupByWeek(
|
||||
SortedMap<LocalDate, Integer> map) {
|
||||
SortedMap<LocalDate, Integer> result = new TreeMap<LocalDate, Integer>();
|
||||
for (Entry<LocalDate, Integer> entry : map.entrySet()) {
|
||||
protected SortedMap<LocalDate, BigDecimal> groupByWeek(
|
||||
SortedMap<LocalDate, BigDecimal> map) {
|
||||
SortedMap<LocalDate, BigDecimal> result = new TreeMap<LocalDate, BigDecimal>();
|
||||
for (Entry<LocalDate, BigDecimal> entry : map.entrySet()) {
|
||||
LocalDate day = entry.getKey();
|
||||
LocalDate key = getThursdayOfThisWeek(day);
|
||||
Integer hours = entry.getValue() == null ? 0 : entry.getValue();
|
||||
BigDecimal hours = entry.getValue() == null ? BigDecimal.ZERO
|
||||
: entry.getValue();
|
||||
if (result.get(key) == null) {
|
||||
result.put(key, hours);
|
||||
} else {
|
||||
result.put(key, result.get(key) + hours);
|
||||
result.put(key, result.get(key).add(hours));
|
||||
}
|
||||
}
|
||||
for (Entry<LocalDate, Integer> entry : result.entrySet()) {
|
||||
for (Entry<LocalDate, BigDecimal> entry : result.entrySet()) {
|
||||
LocalDate day = entry.getKey();
|
||||
result.put(entry.getKey(), result.get(day) / 7);
|
||||
result.put(entry.getKey(), result.get(day).setScale(2).divide(
|
||||
new BigDecimal(7), RoundingMode.DOWN));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected SortedMap<LocalDate, Integer> convertAsNeededByZoom(
|
||||
SortedMap<LocalDate, Integer> map) {
|
||||
protected SortedMap<LocalDate, BigDecimal> convertAsNeededByZoom(
|
||||
SortedMap<LocalDate, BigDecimal> map) {
|
||||
if (isZoomByDay()) {
|
||||
return map;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -587,9 +587,9 @@ public abstract class CompanyPlanningModel implements ICompanyPlanningModel {
|
|||
.list(DayAssignment.class);
|
||||
|
||||
SortedMap<LocalDate, Map<Resource, Integer>> dayAssignmentGrouped = groupDayAssignmentsByDayAndResource(dayAssignments);
|
||||
SortedMap<LocalDate, Integer> mapDayAssignments = calculateHoursAdditionByDayWithoutOverload(dayAssignmentGrouped);
|
||||
SortedMap<LocalDate, BigDecimal> mapDayAssignments = calculateHoursAdditionByDayWithoutOverload(dayAssignmentGrouped);
|
||||
|
||||
return convertToBigDecimal(mapDayAssignments);
|
||||
return mapDayAssignments;
|
||||
}
|
||||
|
||||
private SortedMap<LocalDate, BigDecimal> getOverload(Date start,
|
||||
|
|
@ -598,23 +598,23 @@ public abstract class CompanyPlanningModel implements ICompanyPlanningModel {
|
|||
.list(DayAssignment.class);
|
||||
|
||||
SortedMap<LocalDate, Map<Resource, Integer>> dayAssignmentGrouped = groupDayAssignmentsByDayAndResource(dayAssignments);
|
||||
SortedMap<LocalDate, Integer> mapDayAssignments = calculateHoursAdditionByDayJustOverload(dayAssignmentGrouped);
|
||||
SortedMap<LocalDate, Integer> mapMaxAvailability = calculateHoursAdditionByDay(
|
||||
SortedMap<LocalDate, BigDecimal> mapDayAssignments = calculateHoursAdditionByDayJustOverload(dayAssignmentGrouped);
|
||||
SortedMap<LocalDate, BigDecimal> mapMaxAvailability = calculateHoursAdditionByDay(
|
||||
resourceDAO.list(Resource.class), start, finish);
|
||||
|
||||
for (LocalDate day : mapDayAssignments.keySet()) {
|
||||
if ((day.compareTo(new LocalDate(start)) >= 0)
|
||||
&& (day.compareTo(new LocalDate(finish)) <= 0)) {
|
||||
Integer overloadHours = mapDayAssignments.get(day);
|
||||
Integer maxHours = mapMaxAvailability.get(day);
|
||||
mapDayAssignments.put(day, overloadHours + maxHours);
|
||||
BigDecimal overloadHours = mapDayAssignments.get(day);
|
||||
BigDecimal maxHours = mapMaxAvailability.get(day);
|
||||
mapDayAssignments.put(day, overloadHours.add(maxHours));
|
||||
}
|
||||
}
|
||||
|
||||
return convertToBigDecimal(mapDayAssignments);
|
||||
return mapDayAssignments;
|
||||
}
|
||||
|
||||
private SortedMap<LocalDate, Integer> calculateHoursAdditionByDayWithoutOverload(
|
||||
private SortedMap<LocalDate, BigDecimal> calculateHoursAdditionByDayWithoutOverload(
|
||||
SortedMap<LocalDate, Map<Resource, Integer>> dayAssignmentGrouped) {
|
||||
SortedMap<LocalDate, Integer> map = new TreeMap<LocalDate, Integer>();
|
||||
|
||||
|
|
@ -643,10 +643,10 @@ public abstract class CompanyPlanningModel implements ICompanyPlanningModel {
|
|||
map.put(day, result);
|
||||
}
|
||||
|
||||
return convertAsNeededByZoom(map);
|
||||
return convertAsNeededByZoom(convertToBigDecimal(map));
|
||||
}
|
||||
|
||||
private SortedMap<LocalDate, Integer> calculateHoursAdditionByDayJustOverload(
|
||||
private SortedMap<LocalDate, BigDecimal> calculateHoursAdditionByDayJustOverload(
|
||||
SortedMap<LocalDate, Map<Resource, Integer>> dayAssignmentGrouped) {
|
||||
SortedMap<LocalDate, Integer> map = new TreeMap<LocalDate, Integer>();
|
||||
|
||||
|
|
@ -673,18 +673,18 @@ public abstract class CompanyPlanningModel implements ICompanyPlanningModel {
|
|||
map.put(day, result);
|
||||
}
|
||||
|
||||
return convertAsNeededByZoom(map);
|
||||
return convertAsNeededByZoom(convertToBigDecimal(map));
|
||||
}
|
||||
|
||||
private SortedMap<LocalDate, BigDecimal> getCalendarMaximumAvailability(
|
||||
Date start, Date finish) {
|
||||
SortedMap<LocalDate, Integer> mapDayAssignments = calculateHoursAdditionByDay(
|
||||
SortedMap<LocalDate, BigDecimal> mapDayAssignments = calculateHoursAdditionByDay(
|
||||
resourceDAO.list(Resource.class), start, finish);
|
||||
|
||||
return convertToBigDecimal(mapDayAssignments);
|
||||
return mapDayAssignments;
|
||||
}
|
||||
|
||||
private SortedMap<LocalDate, Integer> calculateHoursAdditionByDay(
|
||||
private SortedMap<LocalDate, BigDecimal> calculateHoursAdditionByDay(
|
||||
List<Resource> resources, Date start, Date finish) {
|
||||
return new HoursByDayCalculator<Entry<LocalDate, List<Resource>>>() {
|
||||
|
||||
|
|
|
|||
|
|
@ -679,11 +679,11 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
private final Order order;
|
||||
|
||||
private SortedMap<LocalDate, Integer> mapOrderLoad = new TreeMap<LocalDate, Integer>();
|
||||
private SortedMap<LocalDate, Integer> mapOrderOverload = new TreeMap<LocalDate, Integer>();
|
||||
private SortedMap<LocalDate, Integer> mapMaxCapacity = new TreeMap<LocalDate, Integer>();
|
||||
private SortedMap<LocalDate, Integer> mapOtherLoad = new TreeMap<LocalDate, Integer>();
|
||||
private SortedMap<LocalDate, Integer> mapOtherOverload = new TreeMap<LocalDate, Integer>();
|
||||
private SortedMap<LocalDate, BigDecimal> mapOrderLoad = new TreeMap<LocalDate, BigDecimal>();
|
||||
private SortedMap<LocalDate, BigDecimal> mapOrderOverload = new TreeMap<LocalDate, BigDecimal>();
|
||||
private SortedMap<LocalDate, BigDecimal> mapMaxCapacity = new TreeMap<LocalDate, BigDecimal>();
|
||||
private SortedMap<LocalDate, BigDecimal> mapOtherLoad = new TreeMap<LocalDate, BigDecimal>();
|
||||
private SortedMap<LocalDate, BigDecimal> mapOtherOverload = new TreeMap<LocalDate, BigDecimal>();
|
||||
|
||||
public OrderLoadChartFiller(Order orderReloaded) {
|
||||
this.order = orderReloaded;
|
||||
|
|
@ -712,15 +712,17 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
convertAsNeededByZoomMaps();
|
||||
|
||||
Plotinfo plotOrderLoad = createPlotinfo(
|
||||
convertToBigDecimal(mapOrderLoad), interval);
|
||||
mapOrderLoad, interval);
|
||||
Plotinfo plotOrderOverload = createPlotinfo(
|
||||
convertToBigDecimal(mapOrderOverload), interval);
|
||||
mapOrderOverload,
|
||||
interval);
|
||||
Plotinfo plotMaxCapacity = createPlotinfo(
|
||||
convertToBigDecimal(mapMaxCapacity), interval);
|
||||
mapMaxCapacity, interval);
|
||||
Plotinfo plotOtherLoad = createPlotinfo(
|
||||
convertToBigDecimal(mapOtherLoad), interval);
|
||||
mapOtherLoad, interval);
|
||||
Plotinfo plotOtherOverload = createPlotinfo(
|
||||
convertToBigDecimal(mapOtherOverload), interval);
|
||||
mapOtherOverload,
|
||||
interval);
|
||||
|
||||
plotOrderLoad.setFillColor(COLOR_ASSIGNED_LOAD_SPECIFIC);
|
||||
plotOrderLoad.setLineWidth(0);
|
||||
|
|
@ -767,8 +769,9 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
SortedMap<LocalDate, Map<Resource, Integer>> resourceDayAssignmentsGrouped) {
|
||||
|
||||
for (LocalDate day : orderDayAssignmentsGrouped.keySet()) {
|
||||
int maxCapacity = getMaxCapcity(orderDayAssignmentsGrouped, day);
|
||||
mapMaxCapacity.put(day, maxCapacity);
|
||||
Integer maxCapacity = getMaxCapcity(orderDayAssignmentsGrouped,
|
||||
day);
|
||||
mapMaxCapacity.put(day, new BigDecimal(maxCapacity));
|
||||
|
||||
Integer orderLoad = 0;
|
||||
Integer orderOverload = 0;
|
||||
|
|
@ -809,11 +812,12 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
}
|
||||
}
|
||||
|
||||
mapOrderLoad.put(day, orderLoad);
|
||||
mapOrderOverload.put(day, orderOverload + maxCapacity);
|
||||
mapOtherLoad.put(day, otherLoad + orderLoad);
|
||||
mapOtherOverload.put(day, otherOverload + orderOverload
|
||||
+ maxCapacity);
|
||||
mapOrderLoad.put(day, new BigDecimal(orderLoad));
|
||||
mapOrderOverload.put(day, new BigDecimal(orderOverload
|
||||
+ maxCapacity));
|
||||
mapOtherLoad.put(day, new BigDecimal(otherLoad + orderLoad));
|
||||
mapOtherOverload.put(day, new BigDecimal(otherOverload
|
||||
+ orderOverload + maxCapacity));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue